This is an automated email from the ASF dual-hosted git repository.

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new d8ae19da [operator] Supplementary code comments (#645)
d8ae19da is described below

commit d8ae19da873e84f6dec7051eb204ffbff68c6280
Author: Jian Zhong <[email protected]>
AuthorDate: Tue Mar 18 12:58:31 2025 +0800

    [operator] Supplementary code comments (#645)
---
 operator/cmd/cluster/install.go            | 24 ++++++++++-----
 operator/cmd/cluster/manifest.go           | 28 ++++++++++++++++-
 operator/cmd/cluster/root.go               |  1 +
 operator/cmd/cluster/shared.go             |  7 ++---
 operator/cmd/cluster/uninstall.go          | 19 ++++++++----
 operator/cmd/cluster/upgrade.go            |  1 +
 operator/pkg/apis/proto/values_types.proto | 48 +++++++++++++++++++++++++++++-
 operator/pkg/apis/register.go              |  3 ++
 operator/pkg/apis/types.go                 | 37 +++++++++++++++++------
 9 files changed, 139 insertions(+), 29 deletions(-)

diff --git a/operator/cmd/cluster/install.go b/operator/cmd/cluster/install.go
index 5766349b..91d7ec26 100644
--- a/operator/cmd/cluster/install.go
+++ b/operator/cmd/cluster/install.go
@@ -38,9 +38,15 @@ import (
 var InstallerScope = log.RegisterScope("installer")
 
 type installArgs struct {
-       filenames        []string
-       sets             []string
-       waitTimeout      time.Duration
+       // filenames is an array of paths to input DubboOperator CR files.
+       filenames []string
+       // sets is a string with the format "path=value".
+       sets []string
+       // waitTimeout is the maximum time to wait for all Dubbo resources to 
be ready.
+       // This setting takes effect only when the "wait" parameter is set to 
true.
+       waitTimeout time.Duration
+       // skipConfirmation determines whether the user is prompted for 
confirmation.
+       // If set to true, the user is not prompted, and a "Yes" response is 
assumed in all cases.
        skipConfirmation bool
 }
 
@@ -59,10 +65,7 @@ func addInstallFlags(cmd *cobra.Command, args *installArgs) {
        cmd.PersistentFlags().DurationVar(&args.waitTimeout, "wait-timeout", 
300*time.Second, "Maximum time to wait for Dubbo resources in each component to 
be ready.")
 }
 
-func InstallCmd(ctx cli.Context) *cobra.Command {
-       return InstallCmdWithArgs(ctx, &RootArgs{}, &installArgs{})
-}
-
+// InstallCmdWithArgs generates an Dubbo install manifest and applies it to a 
cluster.
 func InstallCmdWithArgs(ctx cli.Context, rootArgs *RootArgs, iArgs 
*installArgs) *cobra.Command {
        ic := &cobra.Command{
                Use:   "install",
@@ -95,6 +98,11 @@ func InstallCmdWithArgs(ctx cli.Context, rootArgs *RootArgs, 
iArgs *installArgs)
        return ic
 }
 
+// InstallCmd generates an Dubbo install manifest and applies it to a cluster.
+func InstallCmd(ctx cli.Context) *cobra.Command {
+       return InstallCmdWithArgs(ctx, &RootArgs{}, &installArgs{})
+}
+
 func Install(kubeClient kube.CLIClient, rootArgs *RootArgs, iArgs 
*installArgs, cl clog.Logger, stdOut io.Writer, p Printer) error {
        setFlags := applyFlagAliases(iArgs.sets)
        manifests, vals, err := render.GenerateManifest(iArgs.filenames, 
setFlags, cl, kubeClient)
@@ -124,6 +132,8 @@ func Install(kubeClient kube.CLIClient, rootArgs *RootArgs, 
iArgs *installArgs,
        return nil
 }
 
+// --bar is an alias for --set bar=
+// --foo is an alias for --set foo=
 func applyFlagAliases(flags []string) []string {
        return flags
 }
diff --git a/operator/cmd/cluster/manifest.go b/operator/cmd/cluster/manifest.go
index 972a7e54..073c29ec 100644
--- a/operator/cmd/cluster/manifest.go
+++ b/operator/cmd/cluster/manifest.go
@@ -32,8 +32,10 @@ import (
 )
 
 type manifestGenerateArgs struct {
+       // filenames is an array of paths to input DubboOperator CR files.
        filenames []string
-       sets      []string
+       // sets is a string with the format "path=value".
+       sets []string
 }
 
 func (a *manifestGenerateArgs) String() string {
@@ -137,8 +139,32 @@ func objectKindOrder(m manifest.Manifest) int {
        o := m.Unstructured
        gk := o.GroupVersionKind().Group + "/" + o.GroupVersionKind().Kind
        switch {
+       // Create CRDs asap - both because they are slow and because we will 
likely create instances of them soon
        case gk == "apiextensions.k8s.io/CustomResourceDefinition":
                return -1000
+
+               // We need to create ServiceAccounts, Roles before we bind them 
with a RoleBinding
+       case gk == "/ServiceAccount" || gk == 
"rbac.authorization.k8s.io/ClusterRole":
+               return 1
+       case gk == "rbac.authorization.k8s.io/ClusterRoleBinding":
+               return 2
+
+               // Pods might need configmap or secrets - avoid backoff by 
creating them first
+       case gk == "/ConfigMap" || gk == "/Secrets":
+               return 100
+
+               // Create the pods after we've created other things they might 
be waiting for
+       case gk == "extensions/Deployment" || gk == "apps/Deployment":
+               return 1000
+
+               // Autoscalers typically act on a deployment
+       case gk == "autoscaling/HorizontalPodAutoscaler":
+               return 1001
+
+               // Create services late - after pods have been started
+       case gk == "/Service":
+               return 10000
+
        default:
                return 1000
        }
diff --git a/operator/cmd/cluster/root.go b/operator/cmd/cluster/root.go
index 14ac200c..adf5418a 100644
--- a/operator/cmd/cluster/root.go
+++ b/operator/cmd/cluster/root.go
@@ -22,6 +22,7 @@ import "github.com/spf13/cobra"
 type RootFlags struct{}
 
 type RootArgs struct {
+       // DryRun executes all steps without actually applying the manifests or 
creating output directories/files.
        DryRun bool
        RootFlags
 }
diff --git a/operator/cmd/cluster/shared.go b/operator/cmd/cluster/shared.go
index c527bd1e..531f398d 100644
--- a/operator/cmd/cluster/shared.go
+++ b/operator/cmd/cluster/shared.go
@@ -32,7 +32,7 @@ type Printer interface {
        Println(string)
 }
 
-func NewPtrForWtr(w io.Writer) Printer {
+func NewPrinterForWriter(w io.Writer) Printer {
        return &writerPrinter{writer: w}
 }
 
@@ -44,6 +44,7 @@ func (w writerPrinter) Println(s string) {
        _, _ = fmt.Fprintln(w.writer, s)
 }
 
+// OptionDeterminate waits for a user to confirm with the supplied message.
 func OptionDeterminate(msg string, writer io.Writer) bool {
        for {
                _, _ = fmt.Fprintf(writer, "%s ", msg)
@@ -60,7 +61,3 @@ func OptionDeterminate(msg string, writer io.Writer) bool {
                }
        }
 }
-
-func NewPrinterForWriter(w io.Writer) Printer {
-       return &writerPrinter{writer: w}
-}
diff --git a/operator/cmd/cluster/uninstall.go 
b/operator/cmd/cluster/uninstall.go
index f7d5ba33..91987a6f 100644
--- a/operator/cmd/cluster/uninstall.go
+++ b/operator/cmd/cluster/uninstall.go
@@ -29,13 +29,17 @@ import (
        "os"
 )
 
-const ()
-
 type uninstallArgs struct {
-       filenames        string
-       sets             []string
-       manifestPath     string
-       remove           bool
+       // filenames is an array of paths to input DubboOperator CR files.
+       filenames string
+       // sets is a string with the format "path=value".
+       sets []string
+       // manifestPath is a path to a charts and profiles directory in the 
local filesystem with a release tgz.
+       manifestPath string
+       // remove results in deletion of all Dubbo resources.
+       remove bool
+       // skipConfirmation determines whether the user is prompted for 
confirmation.
+       // If set to true, the user is not prompted, and a "Yes" response is 
assumed in all cases.
        skipConfirmation bool
 }
 
@@ -46,6 +50,7 @@ func addUninstallFlags(cmd *cobra.Command, args 
*uninstallArgs) {
        cmd.PersistentFlags().BoolVarP(&args.skipConfirmation, 
"skip-confirmation", "y", false, `The skipConfirmation determines whether the 
user is prompted for confirmation.`)
 }
 
+// UninstallCmd command uninstalls Dubbo from a cluster
 func UninstallCmd(ctx cli.Context) *cobra.Command {
        rootArgs := &RootArgs{}
        uiArgs := &uninstallArgs{}
@@ -76,6 +81,7 @@ func UninstallCmd(ctx cli.Context) *cobra.Command {
        return uicmd
 }
 
+// Uninstall uninstalls by deleting specified manifests.
 func Uninstall(cmd *cobra.Command, ctx cli.Context, rootArgs *RootArgs, uiArgs 
*uninstallArgs) error {
        cl := clog.NewConsoleLogger(cmd.OutOrStdout(), cmd.ErrOrStderr(), 
InstallerScope)
        var kubeClient kube.CLIClient
@@ -123,6 +129,7 @@ func Uninstall(cmd *cobra.Command, ctx cli.Context, 
rootArgs *RootArgs, uiArgs *
        return nil
 }
 
+// preCheck checks for potential major changes.
 func preCheck(cmd *cobra.Command, uiArgs *uninstallArgs, _ 
*clog.ConsoleLogger, dryRun bool) {
        needConfirmation, message := false, ""
        if uiArgs.remove {
diff --git a/operator/cmd/cluster/upgrade.go b/operator/cmd/cluster/upgrade.go
index 19824154..b9ff26b4 100644
--- a/operator/cmd/cluster/upgrade.go
+++ b/operator/cmd/cluster/upgrade.go
@@ -29,6 +29,7 @@ type upgradeArgs struct {
        *installArgs
 }
 
+// UpgradeCmd performs an in-place upgrade with eligibility checks.
 func UpgradeCmd(ctx cli.Context) *cobra.Command {
        rootArgs := &RootArgs{}
        upArgs := &upgradeArgs{
diff --git a/operator/pkg/apis/proto/values_types.proto 
b/operator/pkg/apis/proto/values_types.proto
index 33e00c7b..022603b8 100644
--- a/operator/pkg/apis/proto/values_types.proto
+++ b/operator/pkg/apis/proto/values_types.proto
@@ -21,6 +21,7 @@ package dubbo.operator.v1alpha1;
 
 import "google/protobuf/wrappers.proto";
 
+// Package-wide variables from generator "generated".
 option go_package = "dubbo.io/dubbo/operator/pkg/apis";
 
 // Global Configuration for Dubbo components.
@@ -35,110 +36,155 @@ message BaseConfig {
 }
 
 message ZookeeperConfig {
+  // Controls whether Zookeeper is installed.
   google.protobuf.BoolValue enabled = 1;
 
+  // Dedicated data log directory.
   google.protobuf.StringValue dataLogDir = 2;
 
+  // Basic time unit (in milliseconds) used by ZooKeeper for heartbeats.
   google.protobuf.Int64Value  tickTime = 3;
 
+  // ZooKeeper uses to limit the length of time the ZooKeeper servers in 
quorum have to connect to a leader.
   google.protobuf.Int64Value  initLimit = 4;
 
+  // How far out of date a server can be from a leader.
   google.protobuf.Int64Value  syncLimit = 5;
 
+  // Block size for transaction log file.
   google.protobuf.Int64Value  preAllocSize = 6;
 
+  // The number of transactions recorded in the transaction log before a 
snapshot can be taken (and the transaction log rolled).
   google.protobuf.Int64Value  snapCount = 7;
 
+  // A list of comma separated Four Letter Words commands that can be executed.
   google.protobuf.StringValue fourlwCommandsWhitelist = 8;
 
+  // Allow ZooKeeper to listen for connections from its peers on all available 
IP addresses.
   google.protobuf.BoolValue listenOnAllIPs = 9;
 
+  // Configuration for Zookeeper autopurge.
   ZookeeperAutopurge autopurge = 10;
 
+  // Limits the number of concurrent connections that a single client may make 
to a single member of the ZooKeeper ensemble.
   google.protobuf.Int64Value maxClientCnxns = 11;
 
+  // Maximum session timeout (in milliseconds) that the server will allow the 
client to negotiate.
   google.protobuf.Int64Value maxSessionTimeout = 12;
 
+  // Size (in MB) for the Java Heap options (Xmx and Xms).
   google.protobuf.Int64Value heapSize = 13;
 
+  // Log level for the ZooKeeper server. ERROR by default.
   google.protobuf.StringValue logLevel = 14;
 
+  // Configuration for Zookeeper auth.
   ZookeeperAuth auth = 15;
 }
 
 message ZookeeperAutopurge {
+  // The most recent snapshots amount (and corresponding transaction logs) to 
retain.
   google.protobuf.Int64Value snapRetainCount = 1;
 
+  // The time interval (in hours) for which the purge task has to be triggered.
   google.protobuf.Int64Value purgeInterval = 2;
 }
 
 message ZookeeperAuth {
+  // Configuration for Zookeeper client.
   ZookeeperAuthClientConfig client = 1;
 
+  // Configuration for Zookeeper quorum.
   ZookeeperAuthQuorumConfig quorum = 2;
 }
 
 message ZookeeperAuthClientConfig {
+  // Enable ZooKeeper client-server authentication. It uses SASL/Digest-MD5.
   google.protobuf.BoolValue enabled = 1;
 
+  // User that will use ZooKeeper clients to auth.
   google.protobuf.StringValue clientUser = 2;
 
+  // Password that will use ZooKeeper clients to auth.
   google.protobuf.StringValue clientPassword = 3;
 
+  // Comma, semicolon or whitespace separated list of user to be created.
   google.protobuf.StringValue serverUsers = 4;
 
+  // Comma, semicolon or whitespace separated list of passwords to assign to 
users when created.
   google.protobuf.StringValue serverPasswords = 5;
 
+  // Use existing secret (ignores previous passwords).
   google.protobuf.StringValue existingSecret = 6;
 }
 
 message ZookeeperAuthQuorumConfig {
+  // Enable ZooKeeper server-server authentication. It uses SASL/Digest-MD5.
   google.protobuf.BoolValue enabled = 1;
 
+  // User that the ZooKeeper quorumLearner will use to authenticate to 
quorumServers.
   google.protobuf.StringValue learnerUser = 2;
 
-  google.protobuf.StringValue learnerPassword =3;
+  // Password that the ZooKeeper quorumLearner will use to authenticate to 
quorumServers.
+  google.protobuf.StringValue learnerPassword = 3;
 
+  // Comma, semicolon or whitespace separated list of users for the 
quorumServers.
   google.protobuf.StringValue serverUsers = 4;
 
+  // Comma, semicolon or whitespace separated list of passwords to assign to 
users when created.
   google.protobuf.StringValue serverPasswords = 5;
 
+  // Use existing secret (ignores previous passwords).
   google.protobuf.StringValue existingSecret = 6;
 }
 
 message NacosConfig {
+  // Controls whether Nacos is installed.
   google.protobuf.BoolValue enabled = 1;
 
+  // Run Mode standalone or cluster.
   google.protobuf.StringValue mode = 2;
 
+  // Configuration for Nacos storage.
   NacosStorage storage = 3;
 
+  // Configuration for Nacos plugin.
   NacosPlugin plugin = 4;
 
+  // Enable Nacos cluster node domain name support.
   string preferhostmode = 5;
 }
 
 message NacosStorage {
+  // Nacos data storage method `mysql` or `embedded`. The `embedded` supports 
either standalone or cluster mode.
   string type = 1;
 
+  // Configuration for Nacos db.
   NacosDB db = 2;
 }
 
 message NacosDB {
+  // Specify the database host for Nacos storing configuration data.
   string host = 1;
 
+  // Specify the database name for Nacos storing configuration data.
   string name = 2;
 
+  // Specify the database port for Nacos storing configuration data.
   int64 port = 3;
 
+  // Specify the database username for Nacos storing configuration data.
   string username = 4;
 
+  // Specify the database password for Nacos storing configuration data.
   string password = 5;
 
+  // Specify the database url parameter for Nacos storing configuration data.
   string param = 6;
 }
 
 message NacosPlugin {
+  // Plugin Status for Nacos.
   google.protobuf.BoolValue enabled = 1;
 }
 
diff --git a/operator/pkg/apis/register.go b/operator/pkg/apis/register.go
index 4b6169de..3b10b8b1 100644
--- a/operator/pkg/apis/register.go
+++ b/operator/pkg/apis/register.go
@@ -21,8 +21,11 @@ import (
        "k8s.io/apimachinery/pkg/runtime/schema"
 )
 
+// Package v1alpha1 contains API Schema definitions for the dubbo v1alpha1 API 
group
 // +k8s:deepcopy-gen=package,register
 // +groupName=install.dubbo.io
+
+// DubboOperatorGVK is the GVK for DubboOperator.
 var DubboOperatorGVK = schema.GroupVersionKind{
        Version: "v1alpha1",
        Group:   "install.dubbo.io",
diff --git a/operator/pkg/apis/types.go b/operator/pkg/apis/types.go
index a5f677b6..73245c1f 100644
--- a/operator/pkg/apis/types.go
+++ b/operator/pkg/apis/types.go
@@ -22,6 +22,7 @@ import (
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 )
 
+// DubboOperator defines the custom API.
 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
 // +kubetype-gen
 // +kubetype-gen:groupVersion=install.dubbo.io/v1alpha1
@@ -30,20 +31,31 @@ type DubboOperator struct {
        metav1.TypeMeta `json:",inline"`
        // +optional
        metav1.ObjectMeta `json:"metadata,omitempty"`
+       // Spec defines the implementation of this definition.
        // +optional
        Spec DubboOperatorSpec `json:"spec,omitempty"`
 }
 
+// DubboOperatorSpec defines the desired installed state of Dubbo components.
+// This specification is used to customize the default profile values provided 
with each Dubbo release.
+// Since this specification is a customization API, specifying an empty 
DubboOperatorSpec results in the default Dubbo component values.
 type DubboOperatorSpec struct {
-       Profile    string              `json:"profile,omitempty"`
-       Dashboard  *DubboDashboardSpec `json:"dashboard,omitempty"`
+       // Path or name for the profile.
+       // default profile is used if this field is unset.
+       Profile string `json:"profile,omitempty"`
+       // For admin dashboard.
+       Dashboard *DubboDashboardSpec `json:"dashboard,omitempty"`
+       // enablement and component-specific settings that are not internal to 
the component.
        Components *DubboComponentSpec `json:"components,omitempty"`
-       Values     json.RawMessage     `json:"values,omitempty"`
+       // Overrides for default `values.yaml`. This is a validated 
pass-through to Helm templates.
+       Values json.RawMessage `json:"values,omitempty"`
 }
 
 type DubboComponentSpec struct {
-       Base     *BaseComponentSpec `json:"base,omitempty"`
-       Register *RegisterSpec      `json:"register,omitempty"`
+       // Used for Dubbo resources.
+       Base *BaseComponentSpec `json:"base,omitempty"`
+       // Using Zookeeper and Nacos as the registration plane.
+       Register *RegisterSpec `json:"register,omitempty"`
 }
 
 type DubboDashboardSpec struct {
@@ -51,22 +63,29 @@ type DubboDashboardSpec struct {
 }
 
 type RegisterSpec struct {
-       Nacos     *RegisterComponentSpec `json:"nacos,omitempty"`
+       // Nacos component.
+       Nacos *RegisterComponentSpec `json:"nacos,omitempty"`
+       // Zookeeper component.
        Zookeeper *RegisterComponentSpec `json:"zookeeper,omitempty"`
 }
 
 type BaseComponentSpec struct {
+       // Selects whether this component is installed.
        Enabled *BoolValue `json:"enabled,omitempty"`
 }
 
 type DashboardComponentSpec struct {
+       // Selects whether this component is installed.
        Enabled *BoolValue `json:"enabled,omitempty"`
 }
 
 type RegisterComponentSpec struct {
-       Enabled   *BoolValue     `json:"enabled,omitempty"`
-       Namespace string         `json:"namespace,omitempty"`
-       Raw       map[string]any `json:"-"`
+       // Selects whether this component is installed.
+       Enabled *BoolValue `json:"enabled,omitempty"`
+       // Namespace for the component.
+       Namespace string `json:"namespace,omitempty"`
+       // Raw is the raw inputs. This allows distinguishing unset vs 
zero-values for KubernetesResources
+       Raw map[string]any `json:"-"`
 }
 
 type MetadataCompSpec struct {

Reply via email to