MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / CreateSecret

Function CreateSecret

pkg/specs/secrets.go:35–98  ·  view source on GitHub ↗

CreateSecret creates a secret with the PostgreSQL and the owner passwords

(
	name string,
	namespace string,
	hostname string,
	dbname string,
	username string,
	password string,
	usertype utils.UserType,
)

Source from the content-addressed store, hash-verified

33
34// CreateSecret creates a secret with the PostgreSQL and the owner passwords
35func CreateSecret(
36 name string,
37 namespace string,
38 hostname string,
39 dbname string,
40 username string,
41 password string,
42 usertype utils.UserType,
43) *corev1.Secret {
44 hostWithNamespace := fmt.Sprintf("%s.%s:%d", hostname, namespace, postgres.ServerPort)
45 hostWithFQDN := fmt.Sprintf(
46 "%s.%s.svc.%s:%d",
47 hostname,
48 namespace,
49 configuration.Current.KubernetesClusterDomain,
50 postgres.ServerPort,
51 )
52
53 namespacedBuilder := &connectionStringBuilder{
54 host: hostWithNamespace,
55 dbname: dbname,
56 username: username,
57 password: password,
58 }
59
60 fqdnBuilder := &connectionStringBuilder{
61 host: hostWithFQDN,
62 dbname: dbname,
63 username: username,
64 password: password,
65 }
66
67 return &corev1.Secret{
68 ObjectMeta: metav1.ObjectMeta{
69 Name: name,
70 Namespace: namespace,
71 Labels: map[string]string{
72 utils.UserTypeLabelName: string(usertype),
73 utils.WatchedLabelName: "true",
74 utils.KubernetesAppManagedByLabelName: utils.ManagerName,
75 },
76 },
77 Type: corev1.SecretTypeBasicAuth,
78 StringData: map[string]string{
79 "username": username,
80 "user": username,
81 "password": password,
82 "dbname": dbname,
83 "host": hostname,
84 "port": fmt.Sprintf("%d", postgres.ServerPort),
85 "pgpass": fmt.Sprintf(
86 "%v:%v:%v:%v:%v\n",
87 hostname,
88 postgres.ServerPort,
89 dbname,
90 username,
91 password),
92 "uri": namespacedBuilder.buildPostgres(),

Callers 3

secrets_test.goFile · 0.85

Calls 2

buildPostgresMethod · 0.95
buildJdbcMethod · 0.95

Tested by

no test coverage detected