Skip to content

Commit 356c115

Browse files
authored
updated condition to retrieve the license from secret and then variable
1 parent 86203c0 commit 356c115

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

pkg/wandb/spec/utils/license.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,55 +25,62 @@ func GetLicense(specs ...*spec.Spec) string {
2525
continue
2626
}
2727

28-
license := s.Values.GetString("global.license")
29-
if license != "" {
30-
log.Info("License retrieved from values.yaml")
31-
return license
32-
}
33-
3428
secretName := s.Values.GetString("global.licenseSecret.name")
3529
secretKey := s.Values.GetString("global.licenseSecret.key")
30+
secretNamespace := s.Values.GetString("global.licenseSecret.namespace")
31+
if secretNamespace == "" {
32+
secretNamespace = "default"
33+
}
3634

3735
if secretName != "" && secretKey != "" {
38-
license := getLicenseFromSecret(kubeClient, secretName, secretKey)
36+
license := getLicenseFromSecret(kubeClient, secretName, secretKey, secretNamespace)
3937
if license != "" {
40-
log.Info("License retrieved from Kubernetes secret", "secretName", secretName)
38+
log.Info("License retrieved from Kubernetes secret", "secretName", secretName, "namespace", secretNamespace)
4139
return license
4240
}
4341
}
42+
43+
license := s.Values.GetString("global.license")
44+
if license != "" {
45+
log.Info("License retrieved from values.yaml")
46+
return license
47+
}
4448
}
45-
return ""
49+
return ""
4650
}
4751

4852
func createKubeClient() (client.Client, error) {
49-
kubeConfig := config.GetConfigOrDie()
53+
kubeConfig, err := config.GetConfig()
54+
if err != nil {
55+
return nil, err
56+
}
5057
kubeClient, err := client.New(kubeConfig, client.Options{})
5158
if err != nil {
5259
return nil, err
5360
}
5461
return kubeClient, nil
5562
}
5663

57-
func getLicenseFromSecret(kubeClient client.Client, secretName, secretKey string) string {
64+
func getLicenseFromSecret(kubeClient client.Client, secretName, secretKey, secretNamespace string) string {
5865
log := ctrllog.Log.WithName("getLicenseFromSecret")
5966
secret := &corev1.Secret{}
6067
ctx := context.TODO()
6168

62-
err := kubeClient.Get(ctx, client.ObjectKey{Name: secretName, Namespace: "default"}, secret)
69+
err := kubeClient.Get(ctx, client.ObjectKey{Name: secretName, Namespace: secretNamespace}, secret)
6370
if err != nil {
64-
log.Error(err, "Error retrieving secret", "secretName", secretName)
71+
log.Error(err, "Error retrieving secret", "secretName", secretName, "namespace", secretNamespace)
6572
return ""
6673
}
6774

6875
if secret.Data == nil {
69-
log.Info("Secret has no data", "secretName", secretName)
76+
log.Info("Secret has no data", "secretName", secretName, "namespace", secretNamespace)
7077
return ""
7178
}
7279
license, exists := secret.Data[secretKey]
7380
if !exists {
74-
log.Info("Key not found in secret", "secretKey", secretKey, "secretName", secretName)
81+
log.Info("Key not found in secret", "secretKey", secretKey, "secretName", secretName, "namespace", secretNamespace)
7582
return ""
7683
}
77-
log.Info("Successfully retrieved license from secret", "secretName", secretName)
84+
log.Info("Successfully retrieved license from secret", "secretName", secretName, "namespace", secretNamespace)
7885
return string(license)
7986
}

0 commit comments

Comments
 (0)