Skip to content

Commit b744aba

Browse files
enarhacursoragent
andcommitted
Enable centralized TLS configuration for TektonResult
Activate the centralized TLS configuration infrastructure for the TektonResult component: - Resolve TLS config from APIServer via ResolveTLSConfig in PreReconcile - Inject TLS env vars into the results-api deployment using the generic InjectTLSEnvVars transformer - Include TLS config fingerprint in GetPlatformData for installer set hash computation, triggering updates on TLS profile changes - Log injected TLS config at Info level for observability Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5ec72d6 commit b744aba

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
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.GetPlatformData(),
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.GetPlatformData(),
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: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ package tektonresult
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"os"
2223
"path/filepath"
2324
"strings"
2425

2526
mf "github.com/manifestival/manifestival"
2627
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
2728
operatorclient "github.com/tektoncd/operator/pkg/client/injection/client"
29+
tektonConfiginformer "github.com/tektoncd/operator/pkg/client/injection/informers/operator/v1alpha1/tektonconfig"
2830
"github.com/tektoncd/operator/pkg/reconciler/common"
2931
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client"
3032
occommon "github.com/tektoncd/operator/pkg/reconciler/openshift/common"
@@ -71,11 +73,15 @@ func OpenShiftExtension(ctx context.Context) common.Extension {
7173
logger.Fatalf("Failed to fetch logs RBAC manifest: %v", err)
7274
}
7375

76+
// Get TektonConfig lister to check EnableCentralTLSConfig flag
77+
tektonConfigLister := tektonConfiginformer.Get(ctx).Lister()
78+
7479
ext := &openshiftExtension{
7580
installerSetClient: client.NewInstallerSetClient(operatorclient.Get(ctx).OperatorV1alpha1().TektonInstallerSets(),
7681
version, "results-ext", v1alpha1.KindTektonResult, nil),
77-
routeManifest: routeManifest,
78-
logsRBACManifest: logsRBACManifest,
82+
routeManifest: routeManifest,
83+
logsRBACManifest: logsRBACManifest,
84+
tektonConfigLister: tektonConfigLister,
7985
}
8086
return ext
8187
}
@@ -84,12 +90,14 @@ type openshiftExtension struct {
8490
installerSetClient *client.InstallerSetClient
8591
routeManifest *mf.Manifest
8692
logsRBACManifest *mf.Manifest
93+
tektonConfigLister occommon.TektonConfigLister
94+
resolvedTLSConfig *occommon.TLSEnvVars
8795
}
8896

89-
func (oe openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Transformer {
97+
func (oe *openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Transformer {
9098
instance := comp.(*v1alpha1.TektonResult)
9199

92-
return []mf.Transformer{
100+
transformers := []mf.Transformer{
93101
occommon.RemoveRunAsUser(),
94102
occommon.RemoveRunAsGroup(),
95103
occommon.ApplyCABundlesToDeployment,
@@ -101,18 +109,45 @@ func (oe openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Tr
101109
injectResultsAPIServiceCACert(instance.Spec.ResultsAPIProperties),
102110
injectPostgresUpgradeSupport(),
103111
}
112+
113+
// Use TLS config resolved in PreReconcile
114+
if oe.resolvedTLSConfig != nil {
115+
transformers = append(transformers, occommon.InjectTLSEnvVars(oe.resolvedTLSConfig, "Deployment", deploymentAPI, []string{apiContainerName}))
116+
}
117+
118+
return transformers
119+
}
120+
121+
122+
// GetPlatformData returns TLS config fingerprint for hash computation.
123+
// This ensures installer set is updated when TLS config changes.
124+
func (oe *openshiftExtension) GetPlatformData() string {
125+
if oe.resolvedTLSConfig == nil {
126+
return ""
127+
}
128+
return fmt.Sprintf("%s:%s:%s", oe.resolvedTLSConfig.MinVersion, oe.resolvedTLSConfig.CipherSuites, oe.resolvedTLSConfig.CurvePreferences)
104129
}
105130

106131
func (oe *openshiftExtension) PreReconcile(ctx context.Context, tc v1alpha1.TektonComponent) error {
132+
logger := logging.FromContext(ctx)
107133
result := tc.(*v1alpha1.TektonResult)
108-
mf := mf.Manifest{}
134+
manifest := mf.Manifest{}
109135

110136
if (result.Spec.LokiStackName != "" && result.Spec.LokiStackNamespace != "") ||
111137
strings.EqualFold(result.Spec.LogsType, "LOKI") {
112-
mf = mf.Append(*oe.logsRBACManifest)
138+
manifest = manifest.Append(*oe.logsRBACManifest)
113139
}
114140

115-
return oe.installerSetClient.PreSet(ctx, tc, &mf, filterAndTransform())
141+
resolvedTLS, err := occommon.ResolveTLSConfig(ctx, oe.tektonConfigLister)
142+
if err != nil {
143+
return err
144+
}
145+
oe.resolvedTLSConfig = resolvedTLS
146+
if oe.resolvedTLSConfig != nil {
147+
logger.Infof("Injecting central TLS config: MinVersion=%s", oe.resolvedTLSConfig.MinVersion)
148+
}
149+
150+
return oe.installerSetClient.PreSet(ctx, tc, &manifest, filterAndTransform())
116151
}
117152

118153
func (oe openshiftExtension) PostReconcile(ctx context.Context, tc v1alpha1.TektonComponent) error {
@@ -130,10 +165,6 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, tc v1alpha1.Tekt
130165
return oe.installerSetClient.PostSet(ctx, tc, &manifest, filterAndTransform())
131166
}
132167

133-
func (oe openshiftExtension) GetPlatformData() string {
134-
return ""
135-
}
136-
137168
func (oe openshiftExtension) Finalize(ctx context.Context, tc v1alpha1.TektonComponent) error {
138169
if err := oe.installerSetClient.CleanupPostSet(ctx); err != nil {
139170
return err
@@ -474,3 +505,4 @@ func injectPostgresUpgradeSupport() mf.Transformer {
474505
return nil
475506
}
476507
}
508+

0 commit comments

Comments
 (0)