Skip to content

Commit

Permalink
Merge pull request #682 from jgwest/gitopsrvce-778-skip-operation-cre…
Browse files Browse the repository at this point in the history
…ation-on-local-managed-envs-oct-2023

GITOPSRVCE-778: only create operations for missing external cluster secrets
  • Loading branch information
openshift-ci[bot] authored Oct 17, 2023
2 parents eb5a1c0 + b5b959d commit 136ee66
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 49 deletions.
4 changes: 2 additions & 2 deletions backend-shared/db/clusteraccess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = Describe("ClusterAccess Tests", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -137,7 +137,7 @@ var _ = Describe("ClusterAccess Tests", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}
err = dbq.CreateClusterCredentials(ctx, &clusterCredentials)
Expand Down
4 changes: 4 additions & 0 deletions backend-shared/db/clustercredentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"fmt"
)

const (
DefaultServiceaccount_bearer_token = "serviceaccount_bearer_token"
)

func (dbq *PostgreSQLDatabaseQueries) UnsafeListAllClusterCredentials(ctx context.Context, clusterCredentials *[]ClusterCredentials) error {
if dbq.dbConnection == nil {
return fmt.Errorf("database connection is nil")
Expand Down
4 changes: 2 additions & 2 deletions backend-shared/db/gitopsenginecluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Describe("Gitopsenginecluster Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -92,7 +92,7 @@ var _ = Describe("Gitopsenginecluster Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}
err = dbq.CreateClusterCredentials(ctx, &clusterCredentials)
Expand Down
2 changes: 1 addition & 1 deletion backend-shared/db/gitopsengineinstance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("Gitopsengineinstance Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down
16 changes: 8 additions & 8 deletions backend-shared/db/guardrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ var _ = Describe("Test to verify update/delete operations are not globally scope
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -256,7 +256,7 @@ var _ = Describe("Test to verify update/delete operations are not globally scope
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -436,7 +436,7 @@ var _ = Describe("Test to verify update/delete operations are not globally scope
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand All @@ -456,7 +456,7 @@ var _ = Describe("Test to verify update/delete operations are not globally scope
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -488,7 +488,7 @@ var _ = Describe("Test to verify update/delete operations are not globally scope
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -517,7 +517,7 @@ var _ = Describe("Test to verify update/delete operations are not globally scope
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -596,7 +596,7 @@ var _ = Describe("Test to verify update/delete operations are not globally scope
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand All @@ -617,7 +617,7 @@ var _ = Describe("Test to verify update/delete operations are not globally scope
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down
6 changes: 3 additions & 3 deletions backend-shared/db/injection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var _ = Describe("Injection Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -124,7 +124,7 @@ var _ = Describe("Injection Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -178,7 +178,7 @@ var _ = Describe("Injection Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down
4 changes: 2 additions & 2 deletions backend-shared/db/managedenvironment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("Managedenvironment Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down Expand Up @@ -138,7 +138,7 @@ var _ = Describe("Managedenvironment Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}
err = dbq.CreateClusterCredentials(ctx, &clusterCredentials)
Expand Down
2 changes: 1 addition & 1 deletion backend-shared/db/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func generateSampleData() (ClusterCredentials, ManagedEnvironment, GitopsEngineC
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down
2 changes: 1 addition & 1 deletion backend-shared/db/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ var _ = Describe("Types Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down
4 changes: 2 additions & 2 deletions backend-shared/db/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func GetOrCreateManagedEnvironmentByNamespaceUID(ctx context.Context, namespace
Host: "host",
Kube_config: "kube_config",
Kube_config_context: "kube_config_context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "serviceaccount_ns",
}

Expand Down Expand Up @@ -395,7 +395,7 @@ func GetOrCreateGitopsEngineClusterByKubeSystemNamespaceUID(ctx context.Context,
Host: "host",
Kube_config: "kube_config",
Kube_config_context: "kube_config_context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "serviceaccount_ns",
}
if err := dbq.CreateClusterCredentials(ctx, &clusterCreds); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions backend-shared/db/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ var _ = Describe("Test utility functions.", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}
err = dbQueries.CreateClusterCredentials(ctx, &clusterCredentials)
Expand Down Expand Up @@ -921,7 +921,7 @@ var _ = Describe("Test utility functions.", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ var _ = Describe("ApplicationEventLoop Test", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down
4 changes: 2 additions & 2 deletions backend/eventloop/db_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ var _ = Describe("DB Clean-up Function Tests", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}
err = dbq.CreateClusterCredentials(ctx, &clusterCredentialsDb)
Expand Down Expand Up @@ -1638,7 +1638,7 @@ var _ = Describe("DB Clean-up Function Tests", func() {
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}
err = dbq.CreateClusterCredentials(ctx, &clusterCredentialsDb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ var _ = Describe("SharedResourceEventLoop ManagedEnvironment-related Test", func
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}
err = dbQueries.CreateClusterCredentials(ctx, &clusterCredentialsDb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ func generateSampleData() (db.ClusterCredentials, db.ManagedEnvironment, db.Gito
Host: "host",
Kube_config: "kube-config",
Kube_config_context: "kube-config-context",
Serviceaccount_bearer_token: "serviceaccount_bearer_token",
Serviceaccount_bearer_token: db.DefaultServiceaccount_bearer_token,
Serviceaccount_ns: "Serviceaccount_ns",
}

Expand Down
14 changes: 14 additions & 0 deletions cluster-agent/controllers/argoproj.io/namespace_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,20 @@ func recreateClusterSecrets(ctx context.Context, dbQueries db.DatabaseQueries, k
continue
}

clusterCreds := db.ClusterCredentials{
Clustercredentials_cred_id: managedEnvironment.Clustercredentials_id,
}
if err := dbQueries.GetClusterCredentialsById(ctx, &clusterCreds); err != nil {
log.Error(err, "Error occurred in recreateClusterSecrets while retrieving ClusterCredentials:"+managedEnvironment.Clustercredentials_id)
continue
}

// Skip if the cluster credentials do not have a token
// - this usually indicates that the ManagedEnvironment is on the local cluster, and thus does not require an Argo CD Cluster Secret in order to deploy
if clusterCreds.Serviceaccount_bearer_token == db.DefaultServiceaccount_bearer_token {
continue
}

// Check if Secret used for this ManagedEnvironment is present in GitOpsEngineInstance namespace.
secretName := argosharedutil.GenerateArgoCDClusterSecretName(managedEnvironment)

Expand Down
Loading

0 comments on commit 136ee66

Please sign in to comment.