-
Notifications
You must be signed in to change notification settings - Fork 26
Multi k8s kubernetes cluster commands #3319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ func New(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command { | |
| cmd.AddCommand(c.newCatalogCommand()) | ||
| cmd.AddCommand(c.newDetachedSavepointCommand()) | ||
| cmd.AddCommand(c.newEnvironmentCommand()) | ||
| cmd.AddCommand(c.newKubernetesClusterCommand()) | ||
| cmd.AddCommand(c.newSavepointCommand()) | ||
|
Comment on lines
41
to
44
|
||
|
|
||
| // On-Prem and Cloud Commands | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| cmfsdk "github.com/confluentinc/cmf-sdk-go/v1" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| ) | ||
|
|
||
| type kubernetesClusterOutput struct { | ||
| Name string `human:"Name" serialized:"name"` | ||
| CreatedTime string `human:"Created Time" serialized:"created_time"` | ||
| UpdatedTime string `human:"Updated Time" serialized:"updated_time"` | ||
| LifecycleState string `human:"Lifecycle State,omitempty" serialized:"lifecycle_state,omitempty"` | ||
| ConnectionState string `human:"Connection State,omitempty" serialized:"connection_state,omitempty"` | ||
| KubernetesVersion string `human:"Kubernetes Version,omitempty" serialized:"kubernetes_version,omitempty"` | ||
| } | ||
|
|
||
| func (c *command) newKubernetesClusterCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "kubernetes-cluster", | ||
| Short: "Manage Kubernetes clusters registered with CMF.", | ||
| Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout}, | ||
| } | ||
|
|
||
| cmd.AddCommand(c.newKubernetesClusterListCommand()) | ||
| cmd.AddCommand(c.newKubernetesClusterDescribeCommand()) | ||
| cmd.AddCommand(c.newKubernetesClusterUpdateCommand()) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func convertSdkKubernetesClusterToLocal(cluster cmfsdk.KubernetesCluster) LocalKubernetesCluster { | ||
| local := LocalKubernetesCluster{ | ||
| ApiVersion: cluster.ApiVersion, | ||
| Kind: cluster.Kind, | ||
| Metadata: LocalKubernetesClusterMetadata{ | ||
| Name: cluster.Metadata.Name, | ||
| CreationTimestamp: cluster.Metadata.CreationTimestamp, | ||
| UpdateTimestamp: cluster.Metadata.UpdateTimestamp, | ||
| Uid: cluster.Metadata.Uid, | ||
| Labels: cluster.Metadata.Labels, | ||
| Annotations: cluster.Metadata.Annotations, | ||
| }, | ||
| Spec: LocalKubernetesClusterSpec{ | ||
| LifecycleState: cluster.Spec.LifecycleState, | ||
| }, | ||
| } | ||
|
|
||
| if cluster.Status != nil { | ||
| local.Status = &LocalKubernetesClusterStatus{ | ||
| State: cluster.Status.State, | ||
| Message: cluster.Status.Message, | ||
| LastHeartbeatTimestamp: cluster.Status.LastHeartbeatTimestamp, | ||
| KubernetesVersion: cluster.Status.KubernetesVersion, | ||
| } | ||
| } | ||
|
|
||
| return local | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *command) newKubernetesClusterDescribeCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "describe <name>", | ||
| Short: "Describe a Kubernetes cluster registered with CMF.", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: c.kubernetesClusterDescribe, | ||
| } | ||
|
|
||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) kubernetesClusterDescribe(cmd *cobra.Command, args []string) error { | ||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| clusterName := args[0] | ||
| cluster, err := client.DescribeKubernetesCluster(c.createContext(), clusterName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if output.GetFormat(cmd) == output.Human { | ||
| table := output.NewTable(cmd) | ||
| o := &kubernetesClusterOutput{ | ||
| Name: cluster.Metadata.Name, | ||
| } | ||
| if cluster.Metadata.CreationTimestamp != nil { | ||
| o.CreatedTime = *cluster.Metadata.CreationTimestamp | ||
| } | ||
| if cluster.Metadata.UpdateTimestamp != nil { | ||
| o.UpdatedTime = *cluster.Metadata.UpdateTimestamp | ||
| } | ||
| if cluster.Spec.LifecycleState != nil { | ||
| o.LifecycleState = *cluster.Spec.LifecycleState | ||
| } | ||
| if cluster.Status != nil { | ||
| if cluster.Status.State != nil { | ||
| o.ConnectionState = *cluster.Status.State | ||
| } | ||
| if cluster.Status.KubernetesVersion != nil { | ||
| o.KubernetesVersion = *cluster.Status.KubernetesVersion | ||
| } | ||
| } | ||
| table.Add(o) | ||
| return table.Print() | ||
| } | ||
|
|
||
| localCluster := convertSdkKubernetesClusterToLocal(cluster) | ||
| return output.SerializedOutput(cmd, localCluster) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *command) newKubernetesClusterListCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List Kubernetes clusters registered with CMF.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.kubernetesClusterList, | ||
| } | ||
|
|
||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) kubernetesClusterList(cmd *cobra.Command, _ []string) error { | ||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| clusters, err := client.ListKubernetesClusters(c.createContext()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if output.GetFormat(cmd) == output.Human { | ||
| list := output.NewList(cmd) | ||
| list.Filter([]string{"Name", "CreatedTime", "UpdatedTime", "LifecycleState", "ConnectionState"}) | ||
| for _, cluster := range clusters { | ||
| o := &kubernetesClusterOutput{ | ||
| Name: cluster.Metadata.Name, | ||
| } | ||
| if cluster.Metadata.CreationTimestamp != nil { | ||
| o.CreatedTime = *cluster.Metadata.CreationTimestamp | ||
| } | ||
| if cluster.Metadata.UpdateTimestamp != nil { | ||
| o.UpdatedTime = *cluster.Metadata.UpdateTimestamp | ||
| } | ||
| if cluster.Spec.LifecycleState != nil { | ||
| o.LifecycleState = *cluster.Spec.LifecycleState | ||
| } | ||
| if cluster.Status != nil && cluster.Status.State != nil { | ||
| o.ConnectionState = *cluster.Status.State | ||
| } | ||
| list.Add(o) | ||
| } | ||
| return list.Print() | ||
| } | ||
|
|
||
| localClusters := make([]LocalKubernetesCluster, 0, len(clusters)) | ||
| for _, cluster := range clusters { | ||
| localClusters = append(localClusters, convertSdkKubernetesClusterToLocal(cluster)) | ||
| } | ||
| return output.SerializedOutput(cmd, localClusters) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repo already depends on go.uber.org/mock (and many tests import go.uber.org/mock/gomock), but this PR adds github.com/golang/mock and regenerates several mocks against that package. Mixing these two gomock packages will break compilation because the Controller/Call types are not interchangeable. Please standardize on one gomock implementation (either switch all tests + remaining mocks to github.com/golang/mock/gomock, or revert these regenerated mocks and the new dependency back to go.uber.org/mock/gomock) and regenerate consistently.