Skip to content

Commit

Permalink
support display images list
Browse files Browse the repository at this point in the history
  • Loading branch information
liangzai006 committed Apr 2, 2024
1 parent 3c85fd5 commit 3bd69dd
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/kk/cmd/artifact/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func NewCmdArtifactImages() *cobra.Command {

o.CommonOptions.AddCommonFlag(cmd)
cmd.AddCommand(NewCmdArtifactImagesPush())
cmd.AddCommand(NewCmdArtifactImagesList())

return cmd
}
113 changes: 113 additions & 0 deletions cmd/kk/cmd/artifact/images/list.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 3bd69dd

Please sign in to comment.