@@ -32,6 +32,8 @@ import (
3232 corev1 "k8s.io/api/core/v1"
3333 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3434 k8sruntime "k8s.io/apimachinery/pkg/runtime"
35+ "k8s.io/client-go/rest"
36+ "knative.dev/pkg/injection"
3537 "knative.dev/pkg/logging"
3638)
3739
@@ -71,11 +73,16 @@ func OpenShiftExtension(ctx context.Context) common.Extension {
7173 logger .Fatalf ("Failed to fetch logs RBAC manifest: %v" , err )
7274 }
7375
76+ // Get the rest.Config from the context for accessing OpenShift APIServer
77+ restConfig := injection .GetConfig (ctx )
78+
7479 ext := & openshiftExtension {
7580 installerSetClient : client .NewInstallerSetClient (operatorclient .Get (ctx ).OperatorV1alpha1 ().TektonInstallerSets (),
7681 version , "results-ext" , v1alpha1 .KindTektonResult , nil ),
7782 routeManifest : routeManifest ,
7883 logsRBACManifest : logsRBACManifest ,
84+ restConfig : restConfig ,
85+ ctx : ctx ,
7986 }
8087 return ext
8188}
@@ -84,12 +91,15 @@ type openshiftExtension struct {
8491 installerSetClient * client.InstallerSetClient
8592 routeManifest * mf.Manifest
8693 logsRBACManifest * mf.Manifest
94+ restConfig * rest.Config
95+ ctx context.Context
8796}
8897
8998func (oe openshiftExtension ) Transformers (comp v1alpha1.TektonComponent ) []mf.Transformer {
9099 instance := comp .(* v1alpha1.TektonResult )
100+ logger := logging .FromContext (oe .ctx )
91101
92- return []mf.Transformer {
102+ transformers := []mf.Transformer {
93103 occommon .RemoveRunAsUser (),
94104 occommon .RemoveRunAsGroup (),
95105 occommon .ApplyCABundlesToDeployment ,
@@ -101,6 +111,16 @@ func (oe openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Tr
101111 injectResultsAPIServiceCACert (instance .Spec .ResultsAPIProperties ),
102112 injectPostgresUpgradeSupport (),
103113 }
114+
115+ // Fetch TLS configuration once and create the transformer if available
116+ tlsEnvVars , err := occommon .GetTLSEnvVarsFromAPIServer (oe .ctx , oe .restConfig )
117+ if err != nil {
118+ logger .Warnf ("Failed to get TLS configuration from APIServer: %v" , err )
119+ } else if tlsEnvVars != nil {
120+ transformers = append (transformers , injectTLSConfig (tlsEnvVars ))
121+ }
122+
123+ return transformers
104124}
105125
106126func (oe * openshiftExtension ) PreReconcile (ctx context.Context , tc v1alpha1.TektonComponent ) error {
@@ -470,3 +490,69 @@ func injectPostgresUpgradeSupport() mf.Transformer {
470490 return nil
471491 }
472492}
493+
494+ // injectTLSConfig injects the TLS configuration as environment variables into the Results API deployment
495+ func injectTLSConfig (tlsEnvVars * occommon.TLSEnvVars ) mf.Transformer {
496+ return func (u * unstructured.Unstructured ) error {
497+ if u .GetKind () != "Deployment" || u .GetName () != deploymentAPI {
498+ return nil
499+ }
500+
501+ d := & appsv1.Deployment {}
502+ if err := k8sruntime .DefaultUnstructuredConverter .FromUnstructured (u .Object , d ); err != nil {
503+ return err
504+ }
505+
506+ for i , container := range d .Spec .Template .Spec .Containers {
507+ if container .Name != apiContainerName {
508+ continue
509+ }
510+
511+ envVars := []corev1.EnvVar {}
512+ if tlsEnvVars .MinVersion != "" {
513+ envVars = append (envVars , corev1.EnvVar {
514+ Name : occommon .TLSMinVersionEnvVar ,
515+ Value : tlsEnvVars .MinVersion ,
516+ })
517+ }
518+ if tlsEnvVars .CipherSuites != "" {
519+ envVars = append (envVars , corev1.EnvVar {
520+ Name : occommon .TLSCipherSuitesEnvVar ,
521+ Value : tlsEnvVars .CipherSuites ,
522+ })
523+ }
524+ // CurvePreferences will be populated once openshift/api#2583 is merged
525+ if tlsEnvVars .CurvePreferences != "" {
526+ envVars = append (envVars , corev1.EnvVar {
527+ Name : occommon .TLSCurvePreferencesEnvVar ,
528+ Value : tlsEnvVars .CurvePreferences ,
529+ })
530+ }
531+
532+ // Merge with existing env vars
533+ existingEnv := container .Env
534+ for _ , newEnv := range envVars {
535+ found := false
536+ for j , existing := range existingEnv {
537+ if existing .Name == newEnv .Name {
538+ existingEnv [j ] = newEnv
539+ found = true
540+ break
541+ }
542+ }
543+ if ! found {
544+ existingEnv = append (existingEnv , newEnv )
545+ }
546+ }
547+ d .Spec .Template .Spec .Containers [i ].Env = existingEnv
548+ break
549+ }
550+
551+ uObj , err := k8sruntime .DefaultUnstructuredConverter .ToUnstructured (d )
552+ if err != nil {
553+ return err
554+ }
555+ u .SetUnstructuredContent (uObj )
556+ return nil
557+ }
558+ }
0 commit comments