Skip to content

Commit be55b09

Browse files
committed
kwokctl: Support modify etcd prefix when create cluster
1 parent 1e5918c commit be55b09

20 files changed

+67
-29
lines changed

pkg/apis/config/v1alpha1/kwokctl_configuration_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ type KwokctlConfigurationOptions struct {
287287
//+k8s:conversion-gen=false
288288
EtcdBinaryTar string `json:"etcdBinaryTar,omitempty"`
289289

290+
// EtcdPrefix is the prefix of etcd.
291+
// +default="/registry"
292+
EtcdPrefix string `json:"etcdPrefix,omitempty"`
293+
290294
// KwokBinaryPrefix is the prefix of the kwok binary.
291295
// is the default value for env KWOK_BINARY_PREFIX
292296
//+k8s:conversion-gen=false

pkg/apis/config/v1alpha1/zz_generated.defaults.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/internalversion/kwokctl_configuration_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ type KwokctlConfigurationOptions struct {
188188
// Deprecated: Use EtcdBinary instead
189189
EtcdBinaryTar string
190190

191+
// EtcdPrefix is the prefix of etcd.
192+
EtcdPrefix string
193+
191194
// KwokControllerBinary is the binary of kwok.
192195
KwokControllerBinary string
193196

pkg/apis/internalversion/zz_generated.conversion.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kwokctl/cmd/create/cluster/cluster.go

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func NewCommand(ctx context.Context) *cobra.Command {
116116
cmd.Flags().StringVar(&flags.Options.EtcdBinaryTar, "etcd-binary-tar", flags.Options.EtcdBinaryTar, `Tar of etcd, if --etcd-binary is set, this is ignored, only for binary runtime
117117
`)
118118
_ = cmd.Flags().MarkDeprecated("etcd-binary-tar", "--etcd-binary-tar will be removed in a future release, please use --etcd-binary instead")
119+
cmd.Flags().StringVar(&flags.Options.EtcdPrefix, "etcd-prefix", flags.Options.EtcdPrefix, `prefix of the key`)
119120
cmd.Flags().StringVar(&flags.Options.MetricsServerBinary, "metrics-server-binary", flags.Options.MetricsServerBinary, `Binary of metrics-server, only for binary runtime`)
120121
cmd.Flags().StringVar(&flags.Options.PrometheusBinary, "prometheus-binary", flags.Options.PrometheusBinary, `Binary of Prometheus, only for binary runtime`)
121122
cmd.Flags().StringVar(&flags.Options.PrometheusBinaryTar, "prometheus-binary-tar", flags.Options.PrometheusBinaryTar, `Tar of Prometheus, if --prometheus-binary is set, this is ignored, only for binary runtime

pkg/kwokctl/cmd/hack/del/del.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
type flagpole struct {
3838
Name string
3939
Namespace string
40-
Prefix string
4140
Output string
4241
}
4342

@@ -59,7 +58,6 @@ func NewCommand(ctx context.Context) *cobra.Command {
5958
},
6059
}
6160

62-
cmd.Flags().StringVar(&flags.Prefix, "prefix", "/registry", "prefix of the key")
6361
cmd.Flags().StringVarP(&flags.Output, "output", "o", "key", "output format. One of: (key, none).")
6462
cmd.Flags().StringVarP(&flags.Namespace, "namespace", "n", "", "namespace of resource")
6563
return cmd
@@ -78,6 +76,11 @@ func runE(ctx context.Context, flags *flagpole, args []string) error {
7876
return err
7977
}
8078

79+
conf, err := rt.Config(ctx)
80+
if err != nil {
81+
return err
82+
}
83+
8184
if rt.IsDryRun() {
8285
switch len(args) {
8386
case 1:
@@ -172,7 +175,7 @@ func runE(ctx context.Context, flags *flagpole, args []string) error {
172175
)
173176
}
174177

175-
err = etcdclient.Delete(ctx, flags.Prefix,
178+
err = etcdclient.Delete(ctx, conf.Options.EtcdPrefix,
176179
opOpts...,
177180
)
178181
if err != nil {

pkg/kwokctl/cmd/hack/get/get.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
type flagpole struct {
3838
Name string
3939
Namespace string
40-
Prefix string
4140
Output string
4241
ChunkSize int64
4342
Watch bool
@@ -62,7 +61,6 @@ func NewCommand(ctx context.Context) *cobra.Command {
6261
},
6362
}
6463

65-
cmd.Flags().StringVar(&flags.Prefix, "prefix", "/registry", "prefix of the key")
6664
cmd.Flags().StringVarP(&flags.Output, "output", "o", "yaml", "output format. One of: (json, yaml, raw, key).")
6765
cmd.Flags().StringVarP(&flags.Namespace, "namespace", "n", "", "namespace of resource")
6866
cmd.Flags().BoolVarP(&flags.Watch, "watch", "w", false, "after listing/getting the requested object, watch for changes")
@@ -84,6 +82,11 @@ func runE(ctx context.Context, flags *flagpole, args []string) error {
8482
return err
8583
}
8684

85+
conf, err := rt.Config(ctx)
86+
if err != nil {
87+
return err
88+
}
89+
8790
if rt.IsDryRun() {
8891
switch len(args) {
8992
case 1:
@@ -233,7 +236,7 @@ func runE(ctx context.Context, flags *flagpole, args []string) error {
233236
if flags.Watch {
234237
var rev int64
235238
if !flags.WatchOnly {
236-
rev, err = etcdclient.Get(ctx, flags.Prefix,
239+
rev, err = etcdclient.Get(ctx, conf.Options.EtcdPrefix,
237240
opOpts...,
238241
)
239242
if err != nil {
@@ -243,14 +246,14 @@ func runE(ctx context.Context, flags *flagpole, args []string) error {
243246

244247
opOpts = append(opOpts, etcd.WithRevision(rev))
245248

246-
err = etcdclient.Watch(ctx, flags.Prefix,
249+
err = etcdclient.Watch(ctx, conf.Options.EtcdPrefix,
247250
opOpts...,
248251
)
249252
if err != nil {
250253
return err
251254
}
252255
} else {
253-
_, err = etcdclient.Get(ctx, flags.Prefix,
256+
_, err = etcdclient.Get(ctx, conf.Options.EtcdPrefix,
254257
opOpts...,
255258
)
256259
if err != nil {

pkg/kwokctl/cmd/hack/put/put.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
type flagpole struct {
4343
Name string
4444
Namespace string
45-
Prefix string
4645
Output string
4746
Path string
4847
}
@@ -65,7 +64,6 @@ func NewCommand(ctx context.Context) *cobra.Command {
6564
},
6665
}
6766

68-
cmd.Flags().StringVar(&flags.Prefix, "prefix", "/registry", "prefix of the key")
6967
cmd.Flags().StringVarP(&flags.Output, "output", "o", "key", "output format. One of: (key, none).")
7068
cmd.Flags().StringVarP(&flags.Namespace, "namespace", "n", "", "namespace of resource")
7169
cmd.Flags().StringVar(&flags.Path, "path", "", "path of the file")
@@ -85,6 +83,11 @@ func runE(ctx context.Context, flags *flagpole, args []string) error {
8583
return err
8684
}
8785

86+
conf, err := rt.Config(ctx)
87+
if err != nil {
88+
return err
89+
}
90+
8891
if rt.IsDryRun() {
8992
switch len(args) {
9093
case 1:
@@ -264,7 +267,7 @@ func runE(ctx context.Context, flags *flagpole, args []string) error {
264267
)
265268
}
266269

267-
err = etcdclient.Put(ctx, flags.Prefix, data,
270+
err = etcdclient.Put(ctx, conf.Options.EtcdPrefix, data,
268271
opOpts...,
269272
)
270273
if err != nil {

pkg/kwokctl/cmd/snapshot/record/record.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
type flagpole struct {
4141
Name string
4242
Path string
43-
Prefix string
4443
Snapshot bool
4544
}
4645

@@ -58,7 +57,6 @@ func NewCommand(ctx context.Context) *cobra.Command {
5857
},
5958
}
6059

61-
cmd.Flags().StringVar(&flags.Prefix, "prefix", "/registry", "prefix of the key")
6260
cmd.Flags().StringVar(&flags.Path, "path", "", "Path to the recording")
6361
cmd.Flags().BoolVar(&flags.Snapshot, "snapshot", false, "Only save the snapshot")
6462
return cmd
@@ -86,6 +84,11 @@ func runE(ctx context.Context, flags *flagpole) error {
8684
return err
8785
}
8886

87+
conf, err := rt.Config(ctx)
88+
if err != nil {
89+
return err
90+
}
91+
8992
etcdclient, err := rt.GetEtcdClient(ctx)
9093
if err != nil {
9194
return err
@@ -99,7 +102,7 @@ func runE(ctx context.Context, flags *flagpole) error {
99102
saver, err := etcd.NewSaver(etcd.SaveConfig{
100103
Clientset: clientset,
101104
Client: etcdclient,
102-
Prefix: flags.Prefix,
105+
Prefix: conf.Options.EtcdPrefix,
103106
})
104107
if err != nil {
105108
return err

pkg/kwokctl/cmd/snapshot/replay/replay.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import (
4343
type flagpole struct {
4444
Name string
4545
Path string
46-
Prefix string
4746
Snapshot bool
4847
}
4948

@@ -61,7 +60,6 @@ func NewCommand(ctx context.Context) *cobra.Command {
6160
},
6261
}
6362

64-
cmd.Flags().StringVar(&flags.Prefix, "prefix", "/registry", "prefix of the key")
6563
cmd.Flags().StringVar(&flags.Path, "path", "", "Path to the recording")
6664
cmd.Flags().BoolVar(&flags.Snapshot, "snapshot", false, "Only restore the snapshot")
6765
return cmd
@@ -89,6 +87,11 @@ func runE(ctx context.Context, flags *flagpole) error {
8987
return err
9088
}
9189

90+
conf, err := rt.Config(ctx)
91+
if err != nil {
92+
return err
93+
}
94+
9295
components, err := rt.ListComponents(ctx)
9396
if err != nil {
9497
return err
@@ -131,7 +134,7 @@ func runE(ctx context.Context, flags *flagpole) error {
131134
loader, err := etcd.NewLoader(etcd.LoadConfig{
132135
Clientset: clientset,
133136
Client: etcdclient,
134-
Prefix: flags.Prefix,
137+
Prefix: conf.Options.EtcdPrefix,
135138
})
136139
if err != nil {
137140
return err

pkg/kwokctl/components/kube_apiserver.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type BuildKubeApiserverComponentConfig struct {
5353
Verbosity log.Level
5454
DisableQPSLimits bool
5555
TracingConfigPath string
56+
EtcdPrefix string
5657
}
5758

5859
// BuildKubeApiserverComponent builds a kube-apiserver component.
@@ -62,7 +63,7 @@ func BuildKubeApiserverComponent(conf BuildKubeApiserverComponentConfig) (compon
6263
}
6364

6465
kubeApiserverArgs := []string{
65-
"--etcd-prefix=/registry",
66+
"--etcd-prefix=" + conf.EtcdPrefix,
6667
"--allow-privileged=true",
6768
}
6869

pkg/kwokctl/runtime/binary/cluster.go

+1
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ func (c *Cluster) addKubeApiserver(ctx context.Context, env *env) (err error) {
466466
Verbosity: env.verbosity,
467467
DisableQPSLimits: conf.DisableQPSLimits,
468468
TracingConfigPath: kubeApiserverTracingConfigPath,
469+
EtcdPrefix: conf.EtcdPrefix,
469470
})
470471
if err != nil {
471472
return err

pkg/kwokctl/runtime/compose/cluster.go

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ func (c *Cluster) addKubeApiserver(ctx context.Context, env *env) (err error) {
489489
Verbosity: env.verbosity,
490490
DisableQPSLimits: conf.DisableQPSLimits,
491491
TracingConfigPath: kubeApiserverTracingConfigPath,
492+
EtcdPrefix: conf.EtcdPrefix,
492493
})
493494
if err != nil {
494495
return err

site/content/en/docs/generated/apis.md

+11
Original file line numberDiff line numberDiff line change
@@ -3223,6 +3223,17 @@ Deprecated: Use EtcdBinary or EtcdctlBinary instead</p>
32233223
</tr>
32243224
<tr>
32253225
<td>
3226+
<code>etcdPrefix</code>
3227+
<em>
3228+
string
3229+
</em>
3230+
</td>
3231+
<td>
3232+
<p>EtcdPrefix is the prefix of etcd.</p>
3233+
</td>
3234+
</tr>
3235+
<tr>
3236+
<td>
32263237
<code>kwokBinaryPrefix</code>
32273238
<em>
32283239
string

site/content/en/docs/generated/kwokctl_create_cluster.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ kwokctl create cluster [flags]
2424
'${KWOK_KUBE_IMAGE_PREFIX}/etcd:${KWOK_ETCD_VERSION}'
2525
(default "registry.k8s.io/etcd:3.5.11-0")
2626
--etcd-port uint32 Port of etcd given to the host. The behavior is unstable for kind/kind-podman runtime and may be modified in the future
27+
--etcd-prefix string prefix of the key (default "/registry")
2728
-h, --help help for cluster
2829
--jaeger-binary string Binary of Jaeger, only for binary runtime (default "https://github.com/jaegertracing/jaeger/releases/download/v1.53.0/jaeger-1.53.0-linux-amd64.tar.gz#jaeger-all-in-one")
2930
--jaeger-image string Image of Jaeger, only for docker/podman/nerdctl/kind/kind-podman runtime

site/content/en/docs/generated/kwokctl_hack_delete.md

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ kwokctl hack delete [resource] [name] [flags]
1212
-h, --help help for delete
1313
-n, --namespace string namespace of resource
1414
-o, --output string output format. One of: (key, none). (default "key")
15-
--prefix string prefix of the key (default "/registry")
1615
```
1716

1817
### Options inherited from parent commands

site/content/en/docs/generated/kwokctl_hack_get.md

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ kwokctl hack get [resource] [name] [flags]
1313
-h, --help help for get
1414
-n, --namespace string namespace of resource
1515
-o, --output string output format. One of: (json, yaml, raw, key). (default "yaml")
16-
--prefix string prefix of the key (default "/registry")
1716
-w, --watch after listing/getting the requested object, watch for changes
1817
--watch-only watch for changes to the requested object(s), without listing/getting first
1918
```

site/content/en/docs/generated/kwokctl_hack_put.md

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ kwokctl hack put [resource] [name] [flags]
1313
-n, --namespace string namespace of resource
1414
-o, --output string output format. One of: (key, none). (default "key")
1515
--path string path of the file
16-
--prefix string prefix of the key (default "/registry")
1716
```
1817

1918
### Options inherited from parent commands

site/content/en/docs/generated/kwokctl_snapshot_record.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ kwokctl snapshot record [flags]
99
### Options
1010

1111
```
12-
-h, --help help for record
13-
--path string Path to the recording
14-
--prefix string prefix of the key (default "/registry")
15-
--snapshot Only save the snapshot
12+
-h, --help help for record
13+
--path string Path to the recording
14+
--snapshot Only save the snapshot
1615
```
1716

1817
### Options inherited from parent commands

site/content/en/docs/generated/kwokctl_snapshot_replay.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ kwokctl snapshot replay [flags]
99
### Options
1010

1111
```
12-
-h, --help help for replay
13-
--path string Path to the recording
14-
--prefix string prefix of the key (default "/registry")
15-
--snapshot Only restore the snapshot
12+
-h, --help help for replay
13+
--path string Path to the recording
14+
--snapshot Only restore the snapshot
1615
```
1716

1817
### Options inherited from parent commands

0 commit comments

Comments
 (0)