Avoid image pull secret and mount duplicate entries in service accounts
@@ -104,23 +104,21 @@ func (a *installAction) Execute(ctx context.Context, syndesis *v1alpha1.Syndesis
if err != nil {
return err
}
- builder.ImagePullSecrets = append(builder.ImagePullSecrets, corev1.LocalObjectReference{
- Name: SyndesisPullSecret,
- })
- builder.Secrets = append(builder.Secrets, corev1.ObjectReference{Namespace: syndesis.Namespace, Name: SyndesisPullSecret})
+ linked := linkImagePullSecret(builder, SyndesisPullSecret)
+ linked = linked || linkSecret(builder, SyndesisPullSecret)
+ if linked {
err = a.client.Update(ctx, builder)
if err != nil {
return err
}
}
+ }
// Link the syndesis service accounts to the image pull secret if it exists
if secret != nil {
for _, res := range list {
if sa, ok := isServiceAccount(res); ok {
- sa.ImagePullSecrets = append(sa.ImagePullSecrets, corev1.LocalObjectReference{
- Name: SyndesisPullSecret,
- })
+ linkImagePullSecret(sa, SyndesisPullSecret)
}
}
}
@@ -282,6 +280,42 @@ func isServiceAccount(resource runtime.Object) (*corev1.ServiceAccount, bool) {
return nil, false
}
+func linkImagePullSecret(sa *corev1.ServiceAccount, secret string) bool {
+ exist := false
+ for _, s := range sa.ImagePullSecrets {
+ if s.Name == secret {
+ exist = true
+ break
+ }
+ }
+
+ if !exist {
+ sa.ImagePullSecrets = append(sa.ImagePullSecrets, corev1.LocalObjectReference{
+ Name: SyndesisPullSecret,
+ })
+ return true
+ }
+
+ return false
+}
+
+func linkSecret(sa *corev1.ServiceAccount, secret string) bool {
+ exist := false
+ for _, s := range sa.Secrets {
+ if s.Name == secret {
+ exist = true
+ break
+ }
+ }
+
+ if !exist {
+ sa.Secrets = append(sa.Secrets, corev1.ObjectReference{Namespace: sa.Namespace, Name: SyndesisPullSecret})
+ return true
+ }
+
+ return false
+}
+
func removeAutoGeneratedAnnotation(ctx context.Context, cl client.Client, route *v1.Route) error {
return updateOnLatestRevision(ctx, cl, route, func(obj runtime.Object) {
if r, ok := obj.(*v1.Route); ok {
