Skip to content

Commit

Permalink
chore: Print in-cluster svr addr disabled warning during ArgoDB initi…
Browse files Browse the repository at this point in the history
…alization (#14539)

* chore: Print in-cluster svr addr disabled warning during ArgoDB initialization

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* fix: undo a change

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* chore: move to a function

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

* chore: rename

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>

---------

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>
  • Loading branch information
terrytangyuan authored Jul 17, 2023
1 parent ff92e60 commit 9c0c6bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 0 additions & 2 deletions util/db/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 28 additions & 1 deletion util/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9c0c6bc

Please sign in to comment.