Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ linters:
revive:
rules:
- name: comment-spacings
goconst:
ignore-tests: true
exclusions:
generated: lax
rules:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.2
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
GOLANGCI_LINT_VERSION ?= v2.11.4
GOLANGCI_LINT_VERSION ?= v2.12.2

.PHONY: helm
helm: $(HELM) ## Download helm locally if necessary.
Expand Down
27 changes: 16 additions & 11 deletions internal/controller/postgresrole_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ import (
"github.com/jackc/pgx/v5"
)

const PostgresRoleFinalizer = "postgresrole.managed-postgres-operator.hoppscale.com/finalizer"
const (
PostgresRoleFinalizer = "postgresrole.managed-postgres-operator.hoppscale.com/finalizer"

K8SLabelManagedByName = "app.kubernetes.io/managed-by"
K8SLabelManagedByValue = "managed-postgres-operator.hoppscale.com"
)

// PostgresRoleReconciler reconciles a PostgresRole object
type PostgresRoleReconciler struct {
Expand Down Expand Up @@ -365,11 +370,11 @@ func (r *PostgresRoleReconciler) reconcileRoleSecret(secretNamespace, secretName
}

desiredSecretData := map[string][]byte{
"PGUSER": []byte(secretDataTemplateVars.Role),
"PGPASSWORD": []byte(secretDataTemplateVars.Password),
"PGHOST": []byte(secretDataTemplateVars.Host),
"PGPORT": []byte(secretDataTemplateVars.Port),
"PGDATABASE": []byte(secretDataTemplateVars.Database),
postgresql.PGUSER: []byte(secretDataTemplateVars.Role),
postgresql.PGPASSWORD: []byte(secretDataTemplateVars.Password),
postgresql.PGHOST: []byte(secretDataTemplateVars.Host),
postgresql.PGPORT: []byte(secretDataTemplateVars.Port),
postgresql.PGDATABASE: []byte(secretDataTemplateVars.Database),
}

for secretKey, secretValue := range secretTemplate {
Expand All @@ -394,7 +399,7 @@ func (r *PostgresRoleReconciler) reconcileRoleSecret(secretNamespace, secretName
Namespace: secretNamespace,
Name: secretName,
Labels: map[string]string{
"app.kubernetes.io/managed-by": "managed-postgres-operator.hoppscale.com",
K8SLabelManagedByName: K8SLabelManagedByValue,
},
},
Type: "Opaque",
Expand All @@ -413,11 +418,11 @@ func (r *PostgresRoleReconciler) reconcileRoleSecret(secretNamespace, secretName

// Update secret if needed
toUpdate := false
if val, ok := resourceSecret.Labels["app.kubernetes.io/managed-by"]; !ok || val != "managed-postgres-operator.hoppscale.com" {
if val, ok := resourceSecret.Labels[K8SLabelManagedByName]; !ok || val != K8SLabelManagedByValue {
if resourceSecret.Labels == nil {
resourceSecret.Labels = make(map[string]string)
}
resourceSecret.Labels["app.kubernetes.io/managed-by"] = "managed-postgres-operator.hoppscale.com"
resourceSecret.Labels[K8SLabelManagedByName] = K8SLabelManagedByValue
toUpdate = true
}

Expand Down Expand Up @@ -488,9 +493,9 @@ func (r *PostgresRoleReconciler) retrieveRolePassword(resource *managedpostgreso
}
} else {
// Retrieve password from the Secret
password, ok := resourceSecret.Data["PGPASSWORD"]
password, ok := resourceSecret.Data[postgresql.PGPASSWORD]
if !ok {
err = fmt.Errorf("failed to retrieve password from secret `%s`: key `%s` doesn't exist", secretNamespacedName, "PGPASSWORD")
err = fmt.Errorf("failed to retrieve password from secret `%s`: key `%s` doesn't exist", secretNamespacedName, postgresql.PGPASSWORD)
}
return string(password), err
}
Expand Down
10 changes: 10 additions & 0 deletions internal/postgresql/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package postgresql

const (
// Environment variables from libpq
PGHOST = "PGHOST"
PGPORT = "PGPORT"
PGUSER = "PGUSER"
PGPASSWORD = "PGPASSWORD"
PGDATABASE = "PGDATABASE"
)
Loading