From 3dee626e20c15d13654e8e9c2caf9da269c9834f Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Mon, 17 Jul 2023 12:54:49 -0400 Subject: [PATCH] chore: Print in-cluster svr addr disabled warning during ArgoDB initialization (#14539) * chore: Print in-cluster svr addr disabled warning during ArgoDB initialization Signed-off-by: Yuan Tang * fix: undo a change Signed-off-by: Yuan Tang * chore: move to a function Signed-off-by: Yuan Tang * chore: rename Signed-off-by: Yuan Tang --------- Signed-off-by: Yuan Tang --- util/db/cluster.go | 2 -- util/db/db.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/util/db/cluster.go b/util/db/cluster.go index 22c92dbde32aa..d821b59ff6a0e 100644 --- a/util/db/cluster.go +++ b/util/db/cluster.go @@ -77,8 +77,6 @@ func (db *db) ListClusters(ctx context.Context) (*appv1.ClusterList, error) { if inClusterEnabled { hasInClusterCredentials = true clusterList.Items = append(clusterList.Items, *cluster) - } else { - log.Warnf("failed to add cluster %q to cluster list: in-cluster server address is disabled in Argo CD settings", cluster.Name) } } else { clusterList.Items = append(clusterList.Items, *cluster) diff --git a/util/db/db.go b/util/db/db.go index 05ae38e75bb84..f66cf65dc9c47 100644 --- a/util/db/db.go +++ b/util/db/db.go @@ -4,9 +4,11 @@ import ( "context" "strings" + log "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes" + "github.com/argoproj/argo-cd/v2/common" appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v2/util/settings" ) @@ -93,11 +95,36 @@ type db struct { // NewDB returns a new instance of the argo database func NewDB(namespace string, settingsMgr *settings.SettingsManager, kubeclientset kubernetes.Interface) ArgoDB { - return &db{ + dbInstance := db{ settingsMgr: settingsMgr, ns: namespace, kubeclientset: kubeclientset, } + dbInstance.logInClusterWarning() + return &dbInstance +} + +func (db *db) logInClusterWarning() { + clusterSecrets, err := db.listSecretsByType(common.LabelValueSecretTypeCluster) + if err != nil { + log.WithError(err).Errorln("could not list secrets by type") + } + dbSettings, err := db.settingsMgr.GetSettings() + if err != nil { + log.WithError(err).Errorln("could not get DB settings") + } + for _, clusterSecret := range clusterSecrets { + cluster, err := secretToCluster(clusterSecret) + if err != nil { + log.Errorf("could not unmarshal cluster secret %s", clusterSecret.Name) + continue + } + if cluster.Server == appv1.KubernetesInternalAPIServerAddr { + if !dbSettings.InClusterEnabled { + log.Warnf("cluster %q uses in-cluster server address but it's disabled in Argo CD settings", cluster.Name) + } + } + } } func (db *db) getSecret(name string, cache map[string]*v1.Secret) (*v1.Secret, error) {