Skip to content

Commit

Permalink
Merge branch 'trustyai-explainability:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ruivieira authored Aug 9, 2024
2 parents 83d19cd + 4458d0d commit b9d3649
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
22 changes: 18 additions & 4 deletions controllers/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ var _ = Describe("TrustyAI operator", func() {
namespace := "trusty-ns-a-1-db"
instance = createDefaultDBCustomResource(namespace)
WaitFor(func() error {
secret := createDatabaseConfiguration(namespace, defaultDatabaseConfigurationName, "mysql")
secret := createDatabaseConfiguration(namespace, defaultDatabaseConfigurationName, "mysql", "trustyai_service")
return k8sClient.Create(ctx, secret)
}, "failed to create ConfigMap")
setupAndTestDeploymentDefault(instance, namespace)
Expand All @@ -368,7 +368,7 @@ var _ = Describe("TrustyAI operator", func() {
namespace := "trusty-ns-a-1-db"
instance = createDefaultDBCustomResource(namespace)
WaitFor(func() error {
secret := createDatabaseConfiguration(namespace, defaultDatabaseConfigurationName, "mariadb")
secret := createDatabaseConfiguration(namespace, defaultDatabaseConfigurationName, "mariadb", "trustyai_service")
return k8sClient.Create(ctx, secret)
}, "failed to create ConfigMap")
setupAndTestDeploymentDefault(instance, namespace)
Expand Down Expand Up @@ -584,9 +584,16 @@ var _ = Describe("TrustyAI operator", func() {
Expect(envVar.ValueFrom.SecretKeyRef.Name).To(Equal(defaultDatabaseConfigurationName), "Secret name does not match")
Expect(envVar.ValueFrom.SecretKeyRef.Key).To(Equal("databasePort"), "Secret key does not match")

envVar = foundEnvVar(trustyaiServiceContainer.Env, "DATABASE_NAME")
Expect(envVar).NotTo(BeNil(), "Env var DATABASE_NAME not found")
Expect(envVar.ValueFrom).NotTo(BeNil(), "Env var DATABASE_NAME does not have ValueFrom set")
Expect(envVar.ValueFrom.SecretKeyRef).NotTo(BeNil(), "Env var DATABASE_NAME is not using SecretKeyRef")
Expect(envVar.ValueFrom.SecretKeyRef.Name).To(Equal(defaultDatabaseConfigurationName), "Secret name does not match")
Expect(envVar.ValueFrom.SecretKeyRef.Key).To(Equal("databaseName"), "Secret key does not match")

envVar = foundEnvVar(trustyaiServiceContainer.Env, "QUARKUS_DATASOURCE_JDBC_URL")
Expect(envVar).NotTo(BeNil(), "Env var QUARKUS_DATASOURCE_JDBC_URL not found")
Expect(envVar.Value).To(Equal("jdbc:${QUARKUS_DATASOURCE_DB_KIND}://${DATABASE_SERVICE}:${DATABASE_PORT}/trustyai_database"))
Expect(envVar.Value).To(Equal("jdbc:${QUARKUS_DATASOURCE_DB_KIND}://${DATABASE_SERVICE}:${DATABASE_PORT}/${DATABASE_NAME}"))

})

Expand Down Expand Up @@ -695,9 +702,16 @@ var _ = Describe("TrustyAI operator", func() {
Expect(envVar.ValueFrom.SecretKeyRef.Name).To(Equal(defaultDatabaseConfigurationName), "Secret name does not match")
Expect(envVar.ValueFrom.SecretKeyRef.Key).To(Equal("databasePort"), "Secret key does not match")

envVar = foundEnvVar(trustyaiServiceContainer.Env, "DATABASE_NAME")
Expect(envVar).NotTo(BeNil(), "Env var DATABASE_NAME not found")
Expect(envVar.ValueFrom).NotTo(BeNil(), "Env var DATABASE_NAME does not have ValueFrom set")
Expect(envVar.ValueFrom.SecretKeyRef).NotTo(BeNil(), "Env var DATABASE_NAME is not using SecretKeyRef")
Expect(envVar.ValueFrom.SecretKeyRef.Name).To(Equal(defaultDatabaseConfigurationName), "Secret name does not match")
Expect(envVar.ValueFrom.SecretKeyRef.Key).To(Equal("databaseName"), "Secret key does not match")

envVar = foundEnvVar(trustyaiServiceContainer.Env, "QUARKUS_DATASOURCE_JDBC_URL")
Expect(envVar).NotTo(BeNil(), "Env var QUARKUS_DATASOURCE_JDBC_URL not found")
Expect(envVar.Value).To(Equal("jdbc:${QUARKUS_DATASOURCE_DB_KIND}://${DATABASE_SERVICE}:${DATABASE_PORT}/trustyai_database"))
Expect(envVar.Value).To(Equal("jdbc:${QUARKUS_DATASOURCE_DB_KIND}://${DATABASE_SERVICE}:${DATABASE_PORT}/${DATABASE_NAME}"))

})

Expand Down
9 changes: 8 additions & 1 deletion controllers/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ func (r *TrustyAIServiceReconciler) findDatabaseSecret(ctx context.Context, inst
// validateDatabaseSecret validates the DB configuration secret
func (r *TrustyAIServiceReconciler) validateDatabaseSecret(secret *corev1.Secret) error {

mandatoryKeys := []string{"databaseKind", "databaseUsername", "databasePassword", "databaseService", "databasePort"}
mandatoryKeys := []string{
"databaseKind",
"databaseUsername",
"databasePassword",
"databaseService",
"databasePort",
"databaseName",
}

for _, key := range mandatoryKeys {
value, exists := secret.Data[key]
Expand Down
3 changes: 2 additions & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,14 @@ func createSecret(namespace string, secretName string, data map[string]string) *
}
}

func createDatabaseConfiguration(namespace string, name string, dbKind string) *corev1.Secret {
func createDatabaseConfiguration(namespace string, name string, dbKind string, databaseName string) *corev1.Secret {
return createSecret(namespace, name, map[string]string{
"databaseKind": dbKind,
"databaseUsername": "foo",
"databasePassword": "bar",
"databaseService": "mariadb-service",
"databasePort": "3306",
"databaseName": databaseName,
})
}

Expand Down
9 changes: 7 additions & 2 deletions controllers/templates/service/deployment.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ spec:
secretKeyRef:
name: {{ .Instance.Spec.Storage.DatabaseConfigurations }}
key: databasePort
- name: DATABASE_NAME
valueFrom:
secretKeyRef:
name: {{ .Instance.Spec.Storage.DatabaseConfigurations }}
key: databaseName
- name: QUARKUS_DATASOURCE_JDBC_URL
{{ if .UseDBTLSCerts }}
value: "jdbc:${QUARKUS_DATASOURCE_DB_KIND}://${DATABASE_SERVICE}:${DATABASE_PORT}/trustyai_database?sslMode=verify-ca&serverSslCert=/etc/tls/db/tls.crt"
value: "jdbc:${QUARKUS_DATASOURCE_DB_KIND}://${DATABASE_SERVICE}:${DATABASE_PORT}/${DATABASE_NAME}?sslMode=verify-ca&serverSslCert=/etc/tls/db/tls.crt"
{{ else }}
value: "jdbc:${QUARKUS_DATASOURCE_DB_KIND}://${DATABASE_SERVICE}:${DATABASE_PORT}/trustyai_database"
value: "jdbc:${QUARKUS_DATASOURCE_DB_KIND}://${DATABASE_SERVICE}:${DATABASE_PORT}/${DATABASE_NAME}"
{{ end }}
- name: SERVICE_DATA_FORMAT
value: "HIBERNATE"
Expand Down

0 comments on commit b9d3649

Please sign in to comment.