Skip to content

Commit 86cc939

Browse files
committed
Add missing fetch of configuration ConfigMap in newArgoCD
1 parent 3c1d8e6 commit 86cc939

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

internal/controller/argo.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strings"
2727

2828
v1 "k8s.io/api/core/v1"
29+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2930
"k8s.io/apimachinery/pkg/api/resource"
3031
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -56,7 +57,18 @@ const (
5657
ConsoleLinkResource = "consolelinks"
5758
)
5859

59-
func newArgoCD(name, namespace string) *argooperator.ArgoCD {
60+
func newArgoCD(r kubernetes.Interface, name, namespace string) (*argooperator.ArgoCD, error) {
61+
// Check if the config map exists and read the config map values
62+
cm, err := r.CoreV1().ConfigMaps(DetectOperatorNamespace()).Get(context.Background(), OperatorConfigMap, metav1.GetOptions{})
63+
// If we hit an error that is not related to the configmap not existing bubble it up
64+
if err != nil && !apierrors.IsNotFound(err) {
65+
return nil, err
66+
}
67+
68+
if cm != nil {
69+
PatternsOperatorConfig = cm.Data
70+
}
71+
6072
argoPolicy := `g, system:cluster-admins, role:admin
6173
g, cluster-admins, role:admin
6274
g, admin, role:admin`
@@ -425,7 +437,7 @@ return health_status`,
425437
},
426438
},
427439
}
428-
return &s
440+
return &s, nil
429441
}
430442

431443
func haveArgo(client dynamic.Interface, name, namespace string) bool {
@@ -435,7 +447,10 @@ func haveArgo(client dynamic.Interface, name, namespace string) bool {
435447
}
436448

437449
func createOrUpdateArgoCD(client dynamic.Interface, fullClient kubernetes.Interface, name, namespace string) error {
438-
argo := newArgoCD(name, namespace)
450+
argo, errArgo := newArgoCD(fullClient, name, namespace)
451+
if errArgo != nil {
452+
return fmt.Errorf("failed to get ArgoCD object: %v", errArgo)
453+
}
439454
gvr := schema.GroupVersionResource{Group: ArgoCDGroup, Version: ArgoCDVersion, Resource: ArgoCDResource}
440455

441456
var err error

0 commit comments

Comments
 (0)