Skip to content

Commit 193b434

Browse files
authored
Merge pull request #198 from kndpio/191-registry-creation-context
added --context parameter for registry creation
2 parents f39ea53 + b3ba9b4 commit 193b434

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cmd/kndp/registry/create.go

+2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ type createCmd struct {
2121
Email string `help:"is your Email."`
2222
Default bool `help:"Set registry as default."`
2323
Local bool `help:"Create local registry."`
24+
Context string `short:"c" help:"Kubernetes context where registry will be created."`
2425
}
2526

2627
func (c *createCmd) Run(ctx context.Context, client *kubernetes.Clientset, config *rest.Config, logger *zap.SugaredLogger) error {
2728
reg := registry.New(c.RegistryServer, c.Username, c.Password, c.Email)
2829
reg.SetDefault(c.Default)
2930
reg.SetLocal(c.Local)
31+
reg.WithContext(c.Context)
3032
err := reg.Validate(ctx, client, logger)
3133
if err != nil {
3234
return err

internal/registry/registry.go

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"k8s.io/client-go/kubernetes"
1919
kv1 "k8s.io/client-go/kubernetes/typed/core/v1"
2020
"k8s.io/client-go/rest"
21+
cfg "sigs.k8s.io/controller-runtime/pkg/client/config"
2122
)
2223

2324
const (
@@ -44,6 +45,7 @@ type Registry struct {
4445
Config RegistryConfig
4546
Default bool
4647
Local bool
48+
Context string
4749
corev1.Secret
4850
}
4951

@@ -138,6 +140,13 @@ func (r *Registry) SecretSpec() corev1.Secret {
138140

139141
// Creates registry in requested context and assign it to engine
140142
func (r *Registry) Create(ctx context.Context, config *rest.Config, logger *zap.SugaredLogger) error {
143+
var err error
144+
if r.Context != "" {
145+
config, err = cfg.GetConfigWithContext(r.Context)
146+
if err != nil {
147+
return err
148+
}
149+
}
141150

142151
client, err := kube.Client(config)
143152
if err != nil {
@@ -350,6 +359,11 @@ func (r *Registry) SetLocal(l bool) {
350359
r.Local = l
351360
}
352361

362+
// Kubernetes context where registry will be created
363+
func (r *Registry) WithContext(c string) {
364+
r.Context = c
365+
}
366+
353367
// Domain of primary registry
354368
func (r *Registry) Domain() string {
355369
if r.Local {

0 commit comments

Comments
 (0)