Skip to content

Commit

Permalink
small reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
frodopwns committed Oct 10, 2019
1 parent 66b2db1 commit 3bf8121
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions controllers/sqlserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,33 +145,25 @@ func (r *SqlServerReconciler) reconcileExternal(instance *azurev1.SqlServer) err

// Check to see if secret already exists for admin username/password
var checkForSecretsErr error
secret := &v1.Secret{}
secret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: instance.Namespace,
},
Data: map[string][]byte{
"username": []byte(*sqlServerProperties.AdministratorLogin),
"password": []byte(*sqlServerProperties.AdministratorLoginPassword),
"sqlservernamespace": []byte(instance.Namespace),
"sqlservername": []byte(name),
},
Type: "Opaque",
}

checkForSecretsErr = r.Get(context.Background(), types.NamespacedName{Name: name, Namespace: instance.Namespace}, secret)

// If secret doesn't exist, generate creds
// Note: sql server enforces password policy. Details can be found here:
// https://docs.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-2017
if checkForSecretsErr != nil {
r.Log.Info("secret does not exist, using randomly generated creds")
secret = &v1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: "apps/v1beta1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: instance.Namespace,
},
Data: map[string][]byte{
"username": []byte(*sqlServerProperties.AdministratorLogin),
"password": []byte(*sqlServerProperties.AdministratorLoginPassword),
"sqlservernamespace": []byte(instance.Namespace),
"sqlservername": []byte(name),
},
Type: "Opaque",
}
} else {
if checkForSecretsErr == nil {
r.Log.Info("secret already exists, pulling creds now")
sqlServerProperties.AdministratorLogin = to.StringPtr(string(secret.Data["username"]))
sqlServerProperties.AdministratorLoginPassword = to.StringPtr(string(secret.Data["password"]))
Expand Down

0 comments on commit 3bf8121

Please sign in to comment.