From 3bd69dd2859f135813ece201d4b191c35952aa99 Mon Sep 17 00:00:00 2001 From: Xiao Liu <46879761+liangzai006@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:59:16 +0800 Subject: [PATCH] support display images list --- cmd/kk/cmd/artifact/images/images.go | 1 + cmd/kk/cmd/artifact/images/list.go | 113 +++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 cmd/kk/cmd/artifact/images/list.go diff --git a/cmd/kk/cmd/artifact/images/images.go b/cmd/kk/cmd/artifact/images/images.go index 0d3ae5ebe..180070d47 100644 --- a/cmd/kk/cmd/artifact/images/images.go +++ b/cmd/kk/cmd/artifact/images/images.go @@ -43,6 +43,7 @@ func NewCmdArtifactImages() *cobra.Command { o.CommonOptions.AddCommonFlag(cmd) cmd.AddCommand(NewCmdArtifactImagesPush()) + cmd.AddCommand(NewCmdArtifactImagesList()) return cmd } diff --git a/cmd/kk/cmd/artifact/images/list.go b/cmd/kk/cmd/artifact/images/list.go new file mode 100644 index 000000000..714e72d0e --- /dev/null +++ b/cmd/kk/cmd/artifact/images/list.go @@ -0,0 +1,113 @@ +/* + Copyright 2022 The KubeSphere Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package images + +import ( + "fmt" + kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/v3/cmd/kk/apis/kubekey/v1alpha2" + "github.com/kubesphere/kubekey/v3/cmd/kk/cmd/options" + "github.com/kubesphere/kubekey/v3/cmd/kk/cmd/util" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/common" + "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/images" + "github.com/spf13/cobra" +) + +type ArtifactImagesListOptions struct { + CommonOptions *options.CommonOptions + + KubernetesVersion string +} + +func NewArtifactImagesListOptions() *ArtifactImagesListOptions { + return &ArtifactImagesListOptions{ + CommonOptions: options.NewCommonOptions(), + } +} + +// NewCmdArtifactImagesList creates a new `kubekey artifacts images push` command +func NewCmdArtifactImagesList() *cobra.Command { + o := NewArtifactImagesListOptions() + cmd := &cobra.Command{ + Use: "list", + Short: "list images to a registry from an artifact", + Run: func(cmd *cobra.Command, args []string) { + util.CheckErr(o.Run()) + }, + } + + o.CommonOptions.AddCommonFlag(cmd) + o.AddFlags(cmd) + return cmd +} + +func (o *ArtifactImagesListOptions) Run() error { + runtime, err := common.NewKubeRuntime(common.AllInOne, common.Argument{}) + if err != nil { + return err + } + + imageName := []string{ + "pause", + "etcd", + "kube-apiserver", + "kube-controller-manager", + "kube-scheduler", + "kube-proxy", + + // network + "coredns", + "k8s-dns-node-cache", + "calico-kube-controllers", + "calico-cni", + "calico-node", + "calico-flexvol", + "calico-typha", + "flannel", + "flannel-cni-plugin", + "cilium", + "cilium-operator-generic", + "hybridnet", + "kubeovn", + "multus", + // storage + "provisioner-localpv", + "linux-utils", + // load balancer + "haproxy", + "kubevip", + // kata-deploy + "kata-deploy", + // node-feature-discovery + "node-feature-discovery", + } + + for _, name := range imageName { + repo := images.GetImage(runtime, &common.KubeConf{ + Cluster: &kubekeyapiv1alpha2.ClusterSpec{ + Kubernetes: kubekeyapiv1alpha2.Kubernetes{Version: o.KubernetesVersion}, + Registry: kubekeyapiv1alpha2.RegistryConfig{PrivateRegistry: "docker.io"}, + }, + }, name).ImageName() + fmt.Println(repo) + } + + return nil +} + +func (o *ArtifactImagesListOptions) AddFlags(cmd *cobra.Command) { + cmd.Flags().StringVarP(&o.KubernetesVersion, "k8s-version", "", "v1.23.15", "Path to a KubeKey artifact images directory") +}