Skip to content

Commit 2de7f83

Browse files
enarhacursoragent
andcommitted
Enable centralized TLS configuration for TektonResult
Activate the centralized TLS configuration feature for the TektonResult component. When EnableCentralTLSConfig is set in TektonConfig, the TLS settings from the cluster's APIServer are automatically injected into the Results API deployment. Changes: - Implement GetHashData() in tektonresult extension to include TLS config fingerprint, triggering installer set updates when TLS configuration changes - Update hash computation in tektonresult reconciler and installerset to include platform-specific data from the extension Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 013878e commit 2de7f83

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

pkg/reconciler/kubernetes/tektonresult/installerset.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ func (r *Reconciler) createInstallerSet(ctx context.Context, tr *v1alpha1.Tekton
3333
return nil, err
3434
}
3535

36-
// compute the hash of tektonresult spec and store as an annotation
37-
// in further reconciliation we compute hash of td spec and check with
38-
// annotation, if they are same then we skip updating the object
36+
// compute the hash of tektonresult spec (including platform-specific data)
37+
// and store as an annotation. In further reconciliation we compute hash
38+
// and check with annotation, if they are same then we skip updating the object
3939
// otherwise we update the manifest
40-
specHash, err := hash.Compute(tr.Spec)
40+
hashInput := struct {
41+
Spec v1alpha1.TektonResultSpec
42+
ExtraData string
43+
}{
44+
Spec: tr.Spec,
45+
ExtraData: r.extension.GetHashData(),
46+
}
47+
specHash, err := hash.Compute(hashInput)
4148
if err != nil {
4249
return nil, err
4350
}

pkg/reconciler/kubernetes/tektonresult/tektonresult.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,15 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tr *v1alpha1.TektonResul
322322
// of TektonResult is changed by checking hash stored as annotation on
323323
// TektonInstallerSet with computing new hash of TektonResult Spec
324324
logger.Debug("Checking for spec changes in TektonResult")
325-
// Hash of TektonResult Spec
326-
expectedSpecHash, err := hash.Compute(tr.Spec)
325+
// Hash of TektonResult Spec including platform-specific data (e.g., TLS config)
326+
hashInput := struct {
327+
Spec v1alpha1.TektonResultSpec
328+
ExtraData string
329+
}{
330+
Spec: tr.Spec,
331+
ExtraData: r.extension.GetHashData(),
332+
}
333+
expectedSpecHash, err := hash.Compute(hashInput)
327334
if err != nil {
328335
logger.Errorw("Failed to compute spec hash", "error", err)
329336
return err

pkg/reconciler/openshift/tektonresult/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package tektonresult
1919
import (
2020
"context"
2121

22-
k8s_ctrl "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektonresult"
2322
"knative.dev/pkg/configmap"
2423
"knative.dev/pkg/controller"
24+
25+
k8s_ctrl "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektonresult"
2526
)
2627

2728
// NewController initializes the controller and is called by the generated code

pkg/reconciler/openshift/tektonresult/extension.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package tektonresult
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"os"
2223
"path/filepath"
2324
"strings"
@@ -84,7 +85,6 @@ func OpenShiftExtension(ctx context.Context) common.Extension {
8485
logsRBACManifest: logsRBACManifest,
8586
tektonConfigLister: tektonConfigLister,
8687
restConfig: injection.GetConfig(ctx),
87-
ctx: ctx,
8888
}
8989
return ext
9090
}
@@ -96,13 +96,12 @@ type openshiftExtension struct {
9696
tektonConfigLister interface {
9797
Get(name string) (*v1alpha1.TektonConfig, error)
9898
}
99-
restConfig *rest.Config
100-
ctx context.Context
99+
restConfig *rest.Config
100+
resolvedTLSConfig *occommon.TLSEnvVars
101101
}
102102

103-
func (oe openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Transformer {
103+
func (oe *openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Transformer {
104104
instance := comp.(*v1alpha1.TektonResult)
105-
logger := logging.FromContext(oe.ctx)
106105

107106
transformers := []mf.Transformer{
108107
occommon.RemoveRunAsUser(),
@@ -117,21 +116,18 @@ func (oe openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Tr
117116
injectPostgresUpgradeSupport(),
118117
}
119118

120-
// Resolve TLS configuration with proper precedence:
121-
// 1. If EnableCentralTLSConfig AND APIServer has TLS → use APIServer TLS
122-
// 2. Otherwise → user-specified config takes effect (handled by component itself)
123-
if tlsEnvVars := oe.resolveTLSConfig(); tlsEnvVars != nil {
124-
transformers = append(transformers, injectTLSConfig(tlsEnvVars))
125-
logger.Infof("Injecting central TLS config: MinVersion=%s", tlsEnvVars.MinVersion)
119+
// Use TLS config resolved in PreReconcile
120+
if oe.resolvedTLSConfig != nil {
121+
transformers = append(transformers, injectTLSConfig(oe.resolvedTLSConfig))
126122
}
127123

128124
return transformers
129125
}
130126

131127
// resolveTLSConfig reads TLS config from the shared APIServer lister.
132128
// Returns nil if central TLS is disabled or no TLS config is available.
133-
func (oe *openshiftExtension) resolveTLSConfig() *occommon.TLSEnvVars {
134-
logger := logging.FromContext(oe.ctx)
129+
func (oe *openshiftExtension) resolveTLSConfig(ctx context.Context) *occommon.TLSEnvVars {
130+
logger := logging.FromContext(ctx)
135131

136132
tc, err := oe.tektonConfigLister.Get(v1alpha1.ConfigResourceName)
137133
if err != nil {
@@ -144,7 +140,7 @@ func (oe *openshiftExtension) resolveTLSConfig() *occommon.TLSEnvVars {
144140
}
145141

146142
// Read TLS config from the shared APIServer lister
147-
tlsEnvVars, err := occommon.GetTLSEnvVarsFromAPIServer(oe.ctx, oe.restConfig)
143+
tlsEnvVars, err := occommon.GetTLSEnvVarsFromAPIServer(ctx, oe.restConfig)
148144
if err != nil {
149145
logger.Warnf("Failed to get TLS config from APIServer: %v", err)
150146
return nil
@@ -153,20 +149,31 @@ func (oe *openshiftExtension) resolveTLSConfig() *occommon.TLSEnvVars {
153149
return tlsEnvVars
154150
}
155151

152+
// GetHashData returns TLS config fingerprint for hash computation.
153+
// This ensures installer set is updated when TLS config changes.
156154
func (oe *openshiftExtension) GetHashData() string {
157-
return ""
155+
if oe.resolvedTLSConfig == nil {
156+
return ""
157+
}
158+
return fmt.Sprintf("%s:%s:%s", oe.resolvedTLSConfig.MinVersion, oe.resolvedTLSConfig.CipherSuites, oe.resolvedTLSConfig.CurvePreferences)
158159
}
159160

160161
func (oe *openshiftExtension) PreReconcile(ctx context.Context, tc v1alpha1.TektonComponent) error {
162+
logger := logging.FromContext(ctx)
161163
result := tc.(*v1alpha1.TektonResult)
162-
mf := mf.Manifest{}
164+
manifest := mf.Manifest{}
163165

164166
if (result.Spec.LokiStackName != "" && result.Spec.LokiStackNamespace != "") ||
165167
strings.EqualFold(result.Spec.LogsType, "LOKI") {
166-
mf = mf.Append(*oe.logsRBACManifest)
168+
manifest = manifest.Append(*oe.logsRBACManifest)
169+
}
170+
171+
oe.resolvedTLSConfig = oe.resolveTLSConfig(ctx)
172+
if oe.resolvedTLSConfig != nil {
173+
logger.Infof("Injecting central TLS config: MinVersion=%s", oe.resolvedTLSConfig.MinVersion)
167174
}
168175

169-
return oe.installerSetClient.PreSet(ctx, tc, &mf, filterAndTransform())
176+
return oe.installerSetClient.PreSet(ctx, tc, &manifest, filterAndTransform())
170177
}
171178

172179
func (oe openshiftExtension) PostReconcile(ctx context.Context, tc v1alpha1.TektonComponent) error {

0 commit comments

Comments
 (0)