1
// Code generated by go run tools/import_commands.go --talos-version v1.7.1 image
4
// This Source Code Form is subject to the terms of the Mozilla Public
5
// License, v. 2.0. If a copy of the MPL was not distributed with this
6
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
17
"github.com/dustin/go-humanize"
18
"github.com/spf13/cobra"
20
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
21
"github.com/siderolabs/talos/pkg/images"
22
"github.com/siderolabs/talos/pkg/machinery/api/common"
23
"github.com/siderolabs/talos/pkg/machinery/api/machine"
24
"github.com/siderolabs/talos/pkg/machinery/client"
25
"github.com/siderolabs/talos/pkg/machinery/config/container"
26
"github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1"
29
type imageCmdFlagsType struct {
34
var imageCmdFlags imageCmdFlagsType
36
func (flags imageCmdFlagsType) apiNamespace() (common.ContainerdNamespace, error) {
37
switch flags.namespace {
39
return common.ContainerdNamespace_NS_CRI, nil
41
return common.ContainerdNamespace_NS_SYSTEM, nil
43
return 0, fmt.Errorf("unsupported namespace %q", flags.namespace)
47
// imagesCmd represents the image command.
48
var imageCmd = &cobra.Command{
50
Aliases: []string{"images"},
51
Short: "Manage CRI containter images",
56
// imageListCmd represents the image list command.
57
var imageListCmd = &cobra.Command{
59
Aliases: []string{"l", "ls"},
60
Short: "List CRI images",
63
RunE: func(cmd *cobra.Command, args []string) error {
64
return WithClient(func(ctx context.Context, c *client.Client) error {
65
ns, err := imageCmdFlags.apiNamespace()
70
rcv, err := c.ImageList(ctx, ns)
72
return fmt.Errorf("error listing images: %w", err)
75
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
76
fmt.Fprintln(w, "NODE\tIMAGE\tDIGEST\tSIZE\tCREATED")
78
if err = helpers.ReadGRPCStream(rcv, func(msg *machine.ImageListResponse, node string, multipleNodes bool) error {
79
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
83
humanize.Bytes(uint64(msg.Size)),
84
msg.CreatedAt.AsTime().Format(time.RFC3339),
97
// imagePullCmd represents the image pull command.
98
var imagePullCmd = &cobra.Command{
100
Aliases: []string{"p"},
101
Short: "Pull an image into CRI",
103
Args: cobra.ExactArgs(1),
104
RunE: func(cmd *cobra.Command, args []string) error {
105
return WithClient(func(ctx context.Context, c *client.Client) error {
106
ns, err := imageCmdFlags.apiNamespace()
111
err = c.ImagePull(ctx, ns, args[0])
113
return fmt.Errorf("error pulling image: %w", err)
121
// imageDefaultCmd represents the image default command.
122
var imageDefaultCmd = &cobra.Command{
124
Short: "List the default images used by Talos",
126
RunE: func(cmd *cobra.Command, args []string) error {
127
images := images.List(container.NewV1Alpha1(&v1alpha1.Config{
128
MachineConfig: &v1alpha1.MachineConfig{
129
MachineKubelet: &v1alpha1.KubeletConfig{},
131
ClusterConfig: &v1alpha1.ClusterConfig{
132
EtcdConfig: &v1alpha1.EtcdConfig{},
133
APIServerConfig: &v1alpha1.APIServerConfig{},
134
ControllerManagerConfig: &v1alpha1.ControllerManagerConfig{},
135
SchedulerConfig: &v1alpha1.SchedulerConfig{},
136
CoreDNSConfig: &v1alpha1.CoreDNS{},
137
ProxyConfig: &v1alpha1.ProxyConfig{},
141
fmt.Printf("%s\n", images.Flannel)
142
fmt.Printf("%s\n", images.FlannelCNI)
143
fmt.Printf("%s\n", images.CoreDNS)
144
fmt.Printf("%s\n", images.Etcd)
145
fmt.Printf("%s\n", images.KubeAPIServer)
146
fmt.Printf("%s\n", images.KubeControllerManager)
147
fmt.Printf("%s\n", images.KubeScheduler)
148
fmt.Printf("%s\n", images.KubeProxy)
149
fmt.Printf("%s\n", images.Kubelet)
150
fmt.Printf("%s\n", images.Installer)
151
fmt.Printf("%s\n", images.Pause)
158
imageCmd.Flags().StringSliceVarP(&imageCmdFlags.configFiles, "file",
159
"f", nil, "specify config files or patches in a YAML file (can specify multiple)",
161
imageCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
162
nodesFromArgs := len(GlobalArgs.Nodes) >
164
endpointsFromArgs := len(GlobalArgs.
166
for _, configFile := range imageCmdFlags.configFiles {
167
if err := processModelineAndUpdateGlobals(configFile, nodesFromArgs,
168
endpointsFromArgs, false); err != nil {
175
Flags().StringSliceVarP(&etcdCmdFlags.configFiles,
176
"file", "f", nil, "specify config files or patches in a YAML file (can specify multiple)",
178
imageDefaultCmd.PreRunE = etcdCmd.PreRunE
180
imageListCmd.Flags().StringSliceVarP(&etcdCmdFlags.
181
configFiles, "file", "f", nil,
182
"specify config files or patches in a YAML file (can specify multiple)",
185
PreRunE = etcdCmd.PreRunE
187
Flags().StringSliceVarP(&etcdCmdFlags.configFiles,
189
"f", nil, "specify config files or patches in a YAML file (can specify multiple)",
191
imagePullCmd.PreRunE = etcdCmd.PreRunE
193
imageCmd.PersistentFlags().StringVar(&imageCmdFlags.namespace, "namespace", "cri", "namespace to use: `system` (etcd and kubelet images) or `cri` for all Kubernetes workloads")
196
imageCmd.AddCommand(imageDefaultCmd)
197
imageCmd.AddCommand(imageListCmd)
198
imageCmd.AddCommand(imagePullCmd)