mirror of
https://github.com/ysoftdevs/imagepullsecret-injector.git
synced 2026-03-26 11:01:55 +01:00
Allow ignoring secret creating errors to preserve _some_ k8s functionality in case of issues
This commit is contained in:
@@ -55,6 +55,7 @@ func main() {
|
|||||||
flag.StringVar(¶meters.sourceImagePullSecretName, "sourceImagePullSecretName", LookupStringEnv("CONFIG_SOURCE_IMAGE_PULL_SECRET_NAME", parameters.sourceImagePullSecretName), "Name of the imagePullSecret secret we use as source.")
|
flag.StringVar(¶meters.sourceImagePullSecretName, "sourceImagePullSecretName", LookupStringEnv("CONFIG_SOURCE_IMAGE_PULL_SECRET_NAME", parameters.sourceImagePullSecretName), "Name of the imagePullSecret secret we use as source.")
|
||||||
flag.StringVar(¶meters.sourceImagePullSecretNamespace, "sourceImagePullSecretNamespace", LookupStringEnv("CONFIG_SOURCE_IMAGE_PULL_SECRET_NAMESPACE", parameters.sourceImagePullSecretNamespace), "Namespace of the imagePullSecret secret we use as source.")
|
flag.StringVar(¶meters.sourceImagePullSecretNamespace, "sourceImagePullSecretNamespace", LookupStringEnv("CONFIG_SOURCE_IMAGE_PULL_SECRET_NAMESPACE", parameters.sourceImagePullSecretNamespace), "Namespace of the imagePullSecret secret we use as source.")
|
||||||
flag.BoolVar(¶meters.allServiceAccounts, "allServiceAccounts", LookupBoolEnv("CONFIG_ALL_SERVICE_ACCOUNTS", parameters.allServiceAccounts), "Switch for watching all service accounts. If true, serviceAccounts parameter is ignored")
|
flag.BoolVar(¶meters.allServiceAccounts, "allServiceAccounts", LookupBoolEnv("CONFIG_ALL_SERVICE_ACCOUNTS", parameters.allServiceAccounts), "Switch for watching all service accounts. If true, serviceAccounts parameter is ignored")
|
||||||
|
flag.BoolVar(¶meters.ignoreSecretCreationError, "ignoreSecretCreationError", LookupBoolEnv("CONFIG_IGNORE_SECRET_CREATION_ERROR", parameters.ignoreSecretCreationError), "If true, failed creation/update of secrets in the target namespace will not cause the webhook to fail")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
glog.Infof("Running with config: %+v", parameters)
|
glog.Infof("Running with config: %+v", parameters)
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ type WhSvrParameters struct {
|
|||||||
targetImagePullSecretName string
|
targetImagePullSecretName string
|
||||||
sourceImagePullSecretName string
|
sourceImagePullSecretName string
|
||||||
sourceImagePullSecretNamespace string
|
sourceImagePullSecretNamespace string
|
||||||
|
ignoreSecretCreationError bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -67,6 +68,7 @@ func DefaultParametersObject() WhSvrParameters {
|
|||||||
targetImagePullSecretName: "my-cool-secret",
|
targetImagePullSecretName: "my-cool-secret",
|
||||||
sourceImagePullSecretName: "my-cool-secret-source",
|
sourceImagePullSecretName: "my-cool-secret-source",
|
||||||
sourceImagePullSecretNamespace: "default",
|
sourceImagePullSecretNamespace: "default",
|
||||||
|
ignoreSecretCreationError: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,12 +254,16 @@ func (whsvr *WebhookServer) mutateServiceAccount(ar *v1beta1.AdmissionReview) *v
|
|||||||
|
|
||||||
if err := whsvr.ensureSecrets(ar); err != nil {
|
if err := whsvr.ensureSecrets(ar); err != nil {
|
||||||
glog.Errorf("Could not ensure existence of the imagePullSecret")
|
glog.Errorf("Could not ensure existence of the imagePullSecret")
|
||||||
|
if !whsvr.config.ignoreSecretCreationError {
|
||||||
|
glog.Errorf("Failing the mutation process")
|
||||||
return &v1beta1.AdmissionResponse{
|
return &v1beta1.AdmissionResponse{
|
||||||
Result: &metav1.Status{
|
Result: &metav1.Status{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glog.Infof("ignoreSecretCreationError is true, ignoring")
|
||||||
|
}
|
||||||
|
|
||||||
return &v1beta1.AdmissionResponse{
|
return &v1beta1.AdmissionResponse{
|
||||||
Allowed: true,
|
Allowed: true,
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ spec:
|
|||||||
value: {{ .Values.imagepullsecretInjector.dockerconfigjsonRef.secretName | quote }}
|
value: {{ .Values.imagepullsecretInjector.dockerconfigjsonRef.secretName | quote }}
|
||||||
- name: CONFIG_SOURCE_IMAGE_PULL_SECRET_NAMESPACE
|
- name: CONFIG_SOURCE_IMAGE_PULL_SECRET_NAMESPACE
|
||||||
value: {{ .Values.imagepullsecretInjector.dockerconfigjsonRef.secretNamespace | default .Release.Namespace | quote }}
|
value: {{ .Values.imagepullsecretInjector.dockerconfigjsonRef.secretNamespace | default .Release.Namespace | quote }}
|
||||||
|
- name: CONFIG_IGNORE_SECRET_CREATION_ERROR
|
||||||
|
value: {{ .Values.imagepullsecretInjector.ignoreSecretCreationError | quote }}
|
||||||
- name: CONFIG_ALL_SERVICE_ACCOUNTS
|
- name: CONFIG_ALL_SERVICE_ACCOUNTS
|
||||||
value: {{ .Values.imagepullsecretInjector.allSaNames | quote }}
|
value: {{ .Values.imagepullsecretInjector.allSaNames | quote }}
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ imagepullsecretInjector:
|
|||||||
secretNamespace: ""
|
secretNamespace: ""
|
||||||
|
|
||||||
targetSecretName: my-cool-secret
|
targetSecretName: my-cool-secret
|
||||||
|
ignoreSecretCreationError: false
|
||||||
allSaNames: false
|
allSaNames: false
|
||||||
saNames:
|
saNames:
|
||||||
- default
|
- default
|
||||||
|
|||||||
Reference in New Issue
Block a user