talm

Форк
0
/
imported_image.go 
199 строк · 5.7 Кб
1
// Code generated by go run tools/import_commands.go --talos-version v1.7.1 image
2
// DO NOT EDIT.
3

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/.
7

8
package commands
9

10
import (
11
	"context"
12
	"fmt"
13
	"os"
14
	"text/tabwriter"
15
	"time"
16

17
	"github.com/dustin/go-humanize"
18
	"github.com/spf13/cobra"
19

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"
27
)
28

29
type imageCmdFlagsType struct {
30
	namespace   string
31
	configFiles []string
32
}
33

34
var imageCmdFlags imageCmdFlagsType
35

36
func (flags imageCmdFlagsType) apiNamespace() (common.ContainerdNamespace, error) {
37
	switch flags.namespace {
38
	case "cri":
39
		return common.ContainerdNamespace_NS_CRI, nil
40
	case "system":
41
		return common.ContainerdNamespace_NS_SYSTEM, nil
42
	default:
43
		return 0, fmt.Errorf("unsupported namespace %q", flags.namespace)
44
	}
45
}
46

47
// imagesCmd represents the image command.
48
var imageCmd = &cobra.Command{
49
	Use:     "image",
50
	Aliases: []string{"images"},
51
	Short:   "Manage CRI containter images",
52
	Long:    ``,
53
	Args:    cobra.NoArgs,
54
}
55

56
// imageListCmd represents the image list command.
57
var imageListCmd = &cobra.Command{
58
	Use:     "list",
59
	Aliases: []string{"l", "ls"},
60
	Short:   "List CRI images",
61
	Long:    ``,
62
	Args:    cobra.NoArgs,
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()
66
			if err != nil {
67
				return err
68
			}
69

70
			rcv, err := c.ImageList(ctx, ns)
71
			if err != nil {
72
				return fmt.Errorf("error listing images: %w", err)
73
			}
74

75
			w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
76
			fmt.Fprintln(w, "NODE\tIMAGE\tDIGEST\tSIZE\tCREATED")
77

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",
80
					node,
81
					msg.Name,
82
					msg.Digest,
83
					humanize.Bytes(uint64(msg.Size)),
84
					msg.CreatedAt.AsTime().Format(time.RFC3339),
85
				)
86

87
				return nil
88
			}); err != nil {
89
				return err
90
			}
91

92
			return w.Flush()
93
		})
94
	},
95
}
96

97
// imagePullCmd represents the image pull command.
98
var imagePullCmd = &cobra.Command{
99
	Use:     "pull",
100
	Aliases: []string{"p"},
101
	Short:   "Pull an image into CRI",
102
	Long:    ``,
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()
107
			if err != nil {
108
				return err
109
			}
110

111
			err = c.ImagePull(ctx, ns, args[0])
112
			if err != nil {
113
				return fmt.Errorf("error pulling image: %w", err)
114
			}
115

116
			return nil
117
		})
118
	},
119
}
120

121
// imageDefaultCmd represents the image default command.
122
var imageDefaultCmd = &cobra.Command{
123
	Use:   "default",
124
	Short: "List the default images used by Talos",
125
	Long:  ``,
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{},
130
			},
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{},
138
			},
139
		}))
140

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)
152

153
		return nil
154
	},
155
}
156

157
func init() {
158
	imageCmd.Flags().StringSliceVarP(&imageCmdFlags.configFiles, "file",
159
		"f", nil, "specify config files or patches in a YAML file (can specify multiple)",
160
	)
161
	imageCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
162
		nodesFromArgs := len(GlobalArgs.Nodes) >
163
			0
164
		endpointsFromArgs := len(GlobalArgs.
165
			Endpoints) > 0
166
		for _, configFile := range imageCmdFlags.configFiles {
167
			if err := processModelineAndUpdateGlobals(configFile, nodesFromArgs,
168
				endpointsFromArgs, false); err != nil {
169
				return err
170
			}
171
		}
172
		return nil
173
	}
174
	imageDefaultCmd.
175
		Flags().StringSliceVarP(&etcdCmdFlags.configFiles,
176
		"file", "f", nil, "specify config files or patches in a YAML file (can specify multiple)",
177
	)
178
	imageDefaultCmd.PreRunE = etcdCmd.PreRunE
179

180
	imageListCmd.Flags().StringSliceVarP(&etcdCmdFlags.
181
		configFiles, "file", "f", nil,
182
		"specify config files or patches in a YAML file (can specify multiple)",
183
	)
184
	imageListCmd.
185
		PreRunE = etcdCmd.PreRunE
186
	imagePullCmd.
187
		Flags().StringSliceVarP(&etcdCmdFlags.configFiles,
188
		"file",
189
		"f", nil, "specify config files or patches in a YAML file (can specify multiple)",
190
	)
191
	imagePullCmd.PreRunE = etcdCmd.PreRunE
192

193
	imageCmd.PersistentFlags().StringVar(&imageCmdFlags.namespace, "namespace", "cri", "namespace to use: `system` (etcd and kubelet images) or `cri` for all Kubernetes workloads")
194
	addCommand(imageCmd)
195

196
	imageCmd.AddCommand(imageDefaultCmd)
197
	imageCmd.AddCommand(imageListCmd)
198
	imageCmd.AddCommand(imagePullCmd)
199
}
200

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.