-
Notifications
You must be signed in to change notification settings - Fork 64
✨ Support serviceaccount pull secrets #2005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -61,8 +61,10 @@ import ( | |||||||||||||||
"github.com/operator-framework/operator-controller/internal/catalogd/serverutil" | ||||||||||||||||
"github.com/operator-framework/operator-controller/internal/catalogd/storage" | ||||||||||||||||
"github.com/operator-framework/operator-controller/internal/catalogd/webhook" | ||||||||||||||||
sharedcontrollers "github.com/operator-framework/operator-controller/internal/shared/controllers" | ||||||||||||||||
fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs" | ||||||||||||||||
imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image" | ||||||||||||||||
sautil "github.com/operator-framework/operator-controller/internal/shared/util/sa" | ||||||||||||||||
"github.com/operator-framework/operator-controller/internal/shared/version" | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
|
@@ -246,18 +248,40 @@ func run(ctx context.Context) error { | |||||||||||||||
cacheOptions := crcache.Options{ | ||||||||||||||||
ByObject: map[client.Object]crcache.ByObject{}, | ||||||||||||||||
} | ||||||||||||||||
if cfg.globalPullSecretKey != nil { | ||||||||||||||||
cacheOptions.ByObject[&corev1.Secret{}] = crcache.ByObject{ | ||||||||||||||||
Namespaces: map[string]crcache.Config{ | ||||||||||||||||
cfg.globalPullSecretKey.Namespace: { | ||||||||||||||||
LabelSelector: k8slabels.Everything(), | ||||||||||||||||
FieldSelector: fields.SelectorFromSet(map[string]string{ | ||||||||||||||||
"metadata.name": cfg.globalPullSecretKey.Name, | ||||||||||||||||
}), | ||||||||||||||||
}, | ||||||||||||||||
|
||||||||||||||||
saKey, err := sautil.GetServiceAccount() | ||||||||||||||||
if err != nil { | ||||||||||||||||
setupLog.Error(err, "Unable to get pod namesapce and serviceaccount") | ||||||||||||||||
return err | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
setupLog.Info("Read token", "serviceaccount", saKey) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
cacheOptions.ByObject[&corev1.ServiceAccount{}] = crcache.ByObject{ | ||||||||||||||||
Namespaces: map[string]crcache.Config{ | ||||||||||||||||
saKey.Namespace: { | ||||||||||||||||
LabelSelector: k8slabels.Everything(), | ||||||||||||||||
FieldSelector: fields.SelectorFromSet(map[string]string{ | ||||||||||||||||
"metadata.name": saKey.Name, | ||||||||||||||||
}), | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
secretCache := crcache.ByObject{} | ||||||||||||||||
secretCache.Namespaces = make(map[string]crcache.Config, 2) | ||||||||||||||||
secretCache.Namespaces[saKey.Namespace] = crcache.Config{ | ||||||||||||||||
LabelSelector: k8slabels.Everything(), | ||||||||||||||||
FieldSelector: fields.Everything(), | ||||||||||||||||
} | ||||||||||||||||
if cfg.globalPullSecretKey != nil { | ||||||||||||||||
secretCache.Namespaces[cfg.globalPullSecretKey.Namespace] = crcache.Config{ | ||||||||||||||||
LabelSelector: k8slabels.Everything(), | ||||||||||||||||
FieldSelector: fields.SelectorFromSet(map[string]string{ | ||||||||||||||||
"metadata.name": cfg.globalPullSecretKey.Name, | ||||||||||||||||
}), | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
cacheOptions.ByObject[&corev1.Secret{}] = secretCache | ||||||||||||||||
|
||||||||||||||||
// Create manager | ||||||||||||||||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||||||||||||||||
|
@@ -312,7 +336,7 @@ func run(ctx context.Context) error { | |||||||||||||||
DockerCertPath: cfg.pullCasDir, | ||||||||||||||||
OCICertPath: cfg.pullCasDir, | ||||||||||||||||
} | ||||||||||||||||
if _, err := os.Stat(authFilePath); err == nil && cfg.globalPullSecretKey != nil { | ||||||||||||||||
if _, err := os.Stat(authFilePath); err == nil { | ||||||||||||||||
logger.Info("using available authentication information for pulling image") | ||||||||||||||||
srcContext.AuthFilePath = authFilePath | ||||||||||||||||
} else if os.IsNotExist(err) { | ||||||||||||||||
|
@@ -370,17 +394,16 @@ func run(ctx context.Context) error { | |||||||||||||||
return err | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if cfg.globalPullSecretKey != nil { | ||||||||||||||||
setupLog.Info("creating SecretSyncer controller for watching secret", "Secret", cfg.globalPullSecret) | ||||||||||||||||
err := (&corecontrollers.PullSecretReconciler{ | ||||||||||||||||
Client: mgr.GetClient(), | ||||||||||||||||
AuthFilePath: authFilePath, | ||||||||||||||||
SecretKey: *cfg.globalPullSecretKey, | ||||||||||||||||
}).SetupWithManager(mgr) | ||||||||||||||||
if err != nil { | ||||||||||||||||
setupLog.Error(err, "unable to create controller", "controller", "SecretSyncer") | ||||||||||||||||
return err | ||||||||||||||||
} | ||||||||||||||||
setupLog.Info("creating SecretSyncer controller for watching secret", "Secret", cfg.globalPullSecret) | ||||||||||||||||
err = (&sharedcontrollers.PullSecretReconciler{ | ||||||||||||||||
Client: mgr.GetClient(), | ||||||||||||||||
AuthFilePath: authFilePath, | ||||||||||||||||
SecretKey: cfg.globalPullSecretKey, | ||||||||||||||||
ServiceAccountKey: saKey, | ||||||||||||||||
}).SetupWithManager(mgr) | ||||||||||||||||
if err != nil { | ||||||||||||||||
setupLog.Error(err, "unable to create controller", "controller", "SecretSyncer") | ||||||||||||||||
return err | ||||||||||||||||
} | ||||||||||||||||
//+kubebuilder:scaffold:builder | ||||||||||||||||
|
||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,9 +71,11 @@ import ( | |
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/certproviders" | ||
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1" | ||
"github.com/operator-framework/operator-controller/internal/operator-controller/scheme" | ||
sharedcontrollers "github.com/operator-framework/operator-controller/internal/shared/controllers" | ||
fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs" | ||
httputil "github.com/operator-framework/operator-controller/internal/shared/util/http" | ||
imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image" | ||
sautil "github.com/operator-framework/operator-controller/internal/shared/util/sa" | ||
"github.com/operator-framework/operator-controller/internal/shared/version" | ||
) | ||
|
||
|
@@ -217,18 +219,40 @@ func run() error { | |
}, | ||
DefaultLabelSelector: k8slabels.Nothing(), | ||
} | ||
if globalPullSecretKey != nil { | ||
cacheOptions.ByObject[&corev1.Secret{}] = crcache.ByObject{ | ||
Namespaces: map[string]crcache.Config{ | ||
globalPullSecretKey.Namespace: { | ||
LabelSelector: k8slabels.Everything(), | ||
FieldSelector: fields.SelectorFromSet(map[string]string{ | ||
"metadata.name": globalPullSecretKey.Name, | ||
}), | ||
}, | ||
|
||
saKey, err := sautil.GetServiceAccount() | ||
if err != nil { | ||
setupLog.Error(err, "Unable to get pod namesapce and serviceaccount") | ||
return err | ||
} | ||
|
||
setupLog.Info("Read token", "serviceaccount", saKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The block below appears identical in both cmd/catalogd/main.go and cmd/operator-controller/main.go. |
||
cacheOptions.ByObject[&corev1.ServiceAccount{}] = crcache.ByObject{ | ||
Namespaces: map[string]crcache.Config{ | ||
saKey.Namespace: { | ||
LabelSelector: k8slabels.Everything(), | ||
FieldSelector: fields.SelectorFromSet(map[string]string{ | ||
"metadata.name": saKey.Name, | ||
}), | ||
}, | ||
}, | ||
} | ||
|
||
secretCache := crcache.ByObject{} | ||
secretCache.Namespaces = make(map[string]crcache.Config, 2) | ||
secretCache.Namespaces[saKey.Namespace] = crcache.Config{ | ||
LabelSelector: k8slabels.Everything(), | ||
FieldSelector: fields.Everything(), | ||
} | ||
if globalPullSecretKey != nil { | ||
secretCache.Namespaces[globalPullSecretKey.Namespace] = crcache.Config{ | ||
LabelSelector: k8slabels.Everything(), | ||
FieldSelector: fields.SelectorFromSet(map[string]string{ | ||
"metadata.name": globalPullSecretKey.Name, | ||
}), | ||
} | ||
} | ||
cacheOptions.ByObject[&corev1.Secret{}] = secretCache | ||
|
||
metricsServerOptions := server.Options{} | ||
if len(cfg.certFile) > 0 && len(cfg.keyFile) > 0 { | ||
|
@@ -360,7 +384,7 @@ func run() error { | |
OCICertPath: cfg.pullCasDir, | ||
} | ||
logger := log.FromContext(ctx) | ||
if _, err := os.Stat(authFilePath); err == nil && globalPullSecretKey != nil { | ||
if _, err := os.Stat(authFilePath); err == nil { | ||
logger.Info("using available authentication information for pulling image") | ||
srcContext.AuthFilePath = authFilePath | ||
} else if os.IsNotExist(err) { | ||
|
@@ -482,17 +506,16 @@ func run() error { | |
return err | ||
} | ||
|
||
if globalPullSecretKey != nil { | ||
setupLog.Info("creating SecretSyncer controller for watching secret", "Secret", cfg.globalPullSecret) | ||
err := (&controllers.PullSecretReconciler{ | ||
Client: mgr.GetClient(), | ||
AuthFilePath: authFilePath, | ||
SecretKey: *globalPullSecretKey, | ||
}).SetupWithManager(mgr) | ||
if err != nil { | ||
setupLog.Error(err, "unable to create controller", "controller", "SecretSyncer") | ||
return err | ||
} | ||
setupLog.Info("creating SecretSyncer controller for watching secret", "Secret", cfg.globalPullSecret) | ||
err = (&sharedcontrollers.PullSecretReconciler{ | ||
Client: mgr.GetClient(), | ||
AuthFilePath: authFilePath, | ||
SecretKey: globalPullSecretKey, | ||
ServiceAccountKey: saKey, | ||
}).SetupWithManager(mgr) | ||
if err != nil { | ||
setupLog.Error(err, "unable to create controller", "controller", "SecretSyncer") | ||
return err | ||
} | ||
|
||
//+kubebuilder:scaffold:builder | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,11 @@ rules: | |
- patch | ||
- update | ||
- watch | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- serviceaccounts | ||
verbs: | ||
- get | ||
- list | ||
- watch |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.