Skip to content

Commit

Permalink
allow through openshift.io/ annotations on service accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl committed Feb 5, 2025
1 parent 5cf9da0 commit cacc4ec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/util/clienthelper/clienthelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
hivev1 "github.com/openshift/hive/apis/hive/v1"
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
extensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -186,6 +187,11 @@ func merge(old, new client.Object) (client.Object, bool, string, error) {

case *corev1.ServiceAccount:
old, new := old.(*corev1.ServiceAccount), new.(*corev1.ServiceAccount)
for _, name := range maps.Keys(old.ObjectMeta.Annotations) {
if strings.HasPrefix(name, "openshift.io/") {
copyAnnotation(&new.ObjectMeta, &old.ObjectMeta, name)
}
}
new.Secrets = old.Secrets
new.ImagePullSecrets = old.ImagePullSecrets

Expand Down
10 changes: 10 additions & 0 deletions pkg/util/clienthelper/clienthelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ func TestMerge(t *testing.T) {
{
name: "ServiceAccount no changes",
old: &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"openshift.io/internal-registry-pull-secret-ref": "example",
},
},
Secrets: []corev1.ObjectReference{
{
Name: "secret1",
Expand All @@ -274,6 +279,11 @@ func TestMerge(t *testing.T) {
},
new: &corev1.ServiceAccount{},
want: &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"openshift.io/internal-registry-pull-secret-ref": "example",
},
},
Secrets: []corev1.ObjectReference{
{
Name: "secret1",
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/dynamichelper/dynamichelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
hivev1 "github.com/openshift/hive/apis/hive/v1"
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
extensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -222,6 +223,11 @@ func merge(old, new kruntime.Object) (kruntime.Object, bool, string, error) {

case *corev1.ServiceAccount:
old, new := old.(*corev1.ServiceAccount), new.(*corev1.ServiceAccount)
for _, name := range maps.Keys(old.ObjectMeta.Annotations) {
if strings.HasPrefix(name, "openshift.io/") {
copyAnnotation(&new.ObjectMeta, &old.ObjectMeta, name)
}
}
new.Secrets = old.Secrets
new.ImagePullSecrets = old.ImagePullSecrets

Expand Down
10 changes: 10 additions & 0 deletions pkg/util/dynamichelper/dynamichelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ func TestMerge(t *testing.T) {
{
name: "ServiceAccount no changes",
old: &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"openshift.io/internal-registry-pull-secret-ref": "example",
},
},
Secrets: []corev1.ObjectReference{
{
Name: "secret1",
Expand All @@ -282,6 +287,11 @@ func TestMerge(t *testing.T) {
},
new: &corev1.ServiceAccount{},
want: &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"openshift.io/internal-registry-pull-secret-ref": "example",
},
},
Secrets: []corev1.ObjectReference{
{
Name: "secret1",
Expand Down

0 comments on commit cacc4ec

Please sign in to comment.