Skip to content

Commit 04296ed

Browse files
committed
Enable centralized TLS configuration for TektonResult
Activate the centralized TLS configuration infrastructure for the TektonResult component: - Resolve TLS config from APIServer via ResolveCentralTLSToEnvVars 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 Assisted-by: Cursor
1 parent b662d91 commit 04296ed

File tree

4 files changed

+69
-23
lines changed

4 files changed

+69
-23
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: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@ package tektonresult
1818

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

2526
mf "github.com/manifestival/manifestival"
26-
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
27-
operatorclient "github.com/tektoncd/operator/pkg/client/injection/client"
28-
"github.com/tektoncd/operator/pkg/reconciler/common"
29-
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client"
30-
occommon "github.com/tektoncd/operator/pkg/reconciler/openshift/common"
3127
appsv1 "k8s.io/api/apps/v1"
3228
corev1 "k8s.io/api/core/v1"
3329
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3430
k8sruntime "k8s.io/apimachinery/pkg/runtime"
3531
"knative.dev/pkg/logging"
32+
33+
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
34+
operatorclient "github.com/tektoncd/operator/pkg/client/injection/client"
35+
tektonConfiginformer "github.com/tektoncd/operator/pkg/client/injection/informers/operator/v1alpha1/tektonconfig"
36+
"github.com/tektoncd/operator/pkg/reconciler/common"
37+
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client"
38+
occommon "github.com/tektoncd/operator/pkg/reconciler/openshift/common"
3639
)
3740

3841
const (
@@ -71,11 +74,15 @@ func OpenShiftExtension(ctx context.Context) common.Extension {
7174
logger.Fatalf("Failed to fetch logs RBAC manifest: %v", err)
7275
}
7376

77+
// Get TektonConfig lister to check EnableCentralTLSConfig flag
78+
tektonConfigLister := tektonConfiginformer.Get(ctx).Lister()
79+
7480
ext := &openshiftExtension{
7581
installerSetClient: client.NewInstallerSetClient(operatorclient.Get(ctx).OperatorV1alpha1().TektonInstallerSets(),
7682
version, "results-ext", v1alpha1.KindTektonResult, nil),
77-
routeManifest: routeManifest,
78-
logsRBACManifest: logsRBACManifest,
83+
routeManifest: routeManifest,
84+
logsRBACManifest: logsRBACManifest,
85+
tektonConfigLister: tektonConfigLister,
7986
}
8087
return ext
8188
}
@@ -84,12 +91,14 @@ type openshiftExtension struct {
8491
installerSetClient *client.InstallerSetClient
8592
routeManifest *mf.Manifest
8693
logsRBACManifest *mf.Manifest
94+
tektonConfigLister occommon.TektonConfigLister
95+
resolvedTLSConfig *occommon.TLSEnvVars
8796
}
8897

89-
func (oe openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Transformer {
98+
func (oe *openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Transformer {
9099
instance := comp.(*v1alpha1.TektonResult)
91100

92-
return []mf.Transformer{
101+
transformers := []mf.Transformer{
93102
occommon.RemoveRunAsUser(),
94103
occommon.RemoveRunAsGroup(),
95104
occommon.ApplyCABundlesToDeployment,
@@ -101,18 +110,44 @@ func (oe openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Tr
101110
injectResultsAPIServiceCACert(instance.Spec.ResultsAPIProperties),
102111
injectPostgresUpgradeSupport(),
103112
}
113+
114+
// Use TLS config resolved in PreReconcile
115+
if oe.resolvedTLSConfig != nil {
116+
transformers = append(transformers, occommon.InjectTLSEnvVars(oe.resolvedTLSConfig, "Deployment", deploymentAPI, []string{apiContainerName}))
117+
}
118+
119+
return transformers
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.ResolveCentralTLSToEnvVars(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

0 commit comments

Comments
 (0)