77 corev1 "k8s.io/api/core/v1"
88 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
99
10+ "github.com/openmcp-project/openmcp-operator/api/constants"
1011 "github.com/openmcp-project/openmcp-operator/api/provider/v1alpha1"
1112)
1213
@@ -35,11 +36,11 @@ func (v *Values) Environment() string {
3536func determineNamespace (provider * unstructured.Unstructured ) string {
3637 var namespacePrefix string
3738 switch provider .GroupVersionKind ().Kind {
38- case "ServiceProvider" :
39+ case v1alpha1 . ServiceProviderGKV (). Kind :
3940 namespacePrefix = "sp"
40- case "ClusterProvider" :
41+ case v1alpha1 . ClusterProviderGKV (). Kind :
4142 namespacePrefix = "cp"
42- case "PlatformService" :
43+ case v1alpha1 . PlatformServiceGKV (). Kind :
4344 namespacePrefix = "ps"
4445 default :
4546 namespacePrefix = provider .GroupVersionKind ().Kind
@@ -105,7 +106,23 @@ func (v *Values) Verbosity() string {
105106 return v .deploymentSpec .Verbosity
106107}
107108
108- func (v * Values ) EnvironmentVariables () []corev1.EnvVar {
109+ // EnvironmentVariables returns the environment variables set in the provider resource, enriched by the following:
110+ // - OPENMCP_PROVIDER_NAME: the name of the provider resource,
111+ // - OPENMCP_PROVIDER_NAMESPACE: the namespace in which the provider will be deployed.
112+ func (v * Values ) EnvironmentVariables () ([]corev1.EnvVar , error ) {
113+ varList := append (
114+ v .providerEnvironmentVariables (),
115+ corev1.EnvVar {Name : constants .EnvVariableProviderName , Value : v .provider .GetName ()},
116+ corev1.EnvVar {Name : constants .EnvVariableProviderNamespace , Value : v .namespace },
117+ )
118+
119+ if err := v .checkUniquenessOfVariableNames (varList ); err != nil {
120+ return nil , err
121+ }
122+ return varList , nil
123+ }
124+
125+ func (v * Values ) providerEnvironmentVariables () []corev1.EnvVar {
109126 env := make ([]corev1.EnvVar , len (v .deploymentSpec .Env ))
110127 for i , e := range v .deploymentSpec .Env {
111128 env [i ] = corev1.EnvVar {
@@ -115,3 +132,14 @@ func (v *Values) EnvironmentVariables() []corev1.EnvVar {
115132 }
116133 return env
117134}
135+
136+ func (v * Values ) checkUniquenessOfVariableNames (varList []corev1.EnvVar ) error {
137+ varMap := make (map [string ]bool )
138+ for _ , e := range varList {
139+ if varMap [e .Name ] {
140+ return fmt .Errorf ("environment variable is not unique: %s" , e .Name )
141+ }
142+ varMap [e .Name ] = true
143+ }
144+ return nil
145+ }
0 commit comments