Skip to content

Commit 18df1de

Browse files
enarhatekton-robot
authored andcommitted
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 243ea3b commit 18df1de

File tree

6 files changed

+79
-23
lines changed

6 files changed

+79
-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: tr.Annotations[v1alpha1.PlatformDataHashKey],
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: tr.Annotations[v1alpha1.PlatformDataHashKey],
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: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ import (
2323
"strings"
2424

2525
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"
3126
appsv1 "k8s.io/api/apps/v1"
3227
corev1 "k8s.io/api/core/v1"
3328
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3429
k8sruntime "k8s.io/apimachinery/pkg/runtime"
3530
"knative.dev/pkg/logging"
31+
32+
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
33+
operatorclient "github.com/tektoncd/operator/pkg/client/injection/client"
34+
tektonConfiginformer "github.com/tektoncd/operator/pkg/client/injection/informers/operator/v1alpha1/tektonconfig"
35+
"github.com/tektoncd/operator/pkg/reconciler/common"
36+
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client"
37+
occommon "github.com/tektoncd/operator/pkg/reconciler/openshift/common"
3638
)
3739

3840
const (
@@ -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,39 @@ 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+
func (oe *openshiftExtension) GetPlatformData() string {
122+
return ""
104123
}
105124

106125
func (oe *openshiftExtension) PreReconcile(ctx context.Context, tc v1alpha1.TektonComponent) error {
126+
logger := logging.FromContext(ctx)
107127
result := tc.(*v1alpha1.TektonResult)
108-
mf := mf.Manifest{}
128+
manifest := mf.Manifest{}
109129

110130
if (result.Spec.LokiStackName != "" && result.Spec.LokiStackNamespace != "") ||
111131
strings.EqualFold(result.Spec.LogsType, "LOKI") {
112-
mf = mf.Append(*oe.logsRBACManifest)
132+
manifest = manifest.Append(*oe.logsRBACManifest)
113133
}
114134

115-
return oe.installerSetClient.PreSet(ctx, tc, &mf, filterAndTransform())
135+
resolvedTLS, err := occommon.ResolveCentralTLSToEnvVars(ctx, oe.tektonConfigLister)
136+
if err != nil {
137+
return err
138+
}
139+
oe.resolvedTLSConfig = resolvedTLS
140+
if oe.resolvedTLSConfig != nil {
141+
logger.Infof("Injecting central TLS config: MinVersion=%s", oe.resolvedTLSConfig.MinVersion)
142+
}
143+
144+
return oe.installerSetClient.PreSet(ctx, tc, &manifest, filterAndTransform())
116145
}
117146

118147
func (oe openshiftExtension) PostReconcile(ctx context.Context, tc v1alpha1.TektonComponent) error {
@@ -130,10 +159,6 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, tc v1alpha1.Tekt
130159
return oe.installerSetClient.PostSet(ctx, tc, &manifest, filterAndTransform())
131160
}
132161

133-
func (oe openshiftExtension) GetPlatformData() string {
134-
return ""
135-
}
136-
137162
func (oe openshiftExtension) Finalize(ctx context.Context, tc v1alpha1.TektonComponent) error {
138163
if err := oe.installerSetClient.CleanupPostSet(ctx); err != nil {
139164
return err

pkg/reconciler/shared/tektonconfig/result/result.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ func UpdateResult(ctx context.Context, old *v1alpha1.TektonResult, new *v1alpha1
157157
updated = true
158158
}
159159

160+
oldPlatformData := old.ObjectMeta.Annotations[v1alpha1.PlatformDataHashKey]
161+
newPlatformData := new.ObjectMeta.Annotations[v1alpha1.PlatformDataHashKey]
162+
if oldPlatformData != newPlatformData {
163+
if old.ObjectMeta.Annotations == nil {
164+
old.ObjectMeta.Annotations = map[string]string{}
165+
}
166+
old.ObjectMeta.Annotations[v1alpha1.PlatformDataHashKey] = newPlatformData
167+
updated = true
168+
}
169+
160170
if updated {
161171
_, err := clients.Update(ctx, old, metav1.UpdateOptions{})
162172
if err != nil {

pkg/reconciler/shared/tektonconfig/tektonconfig.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi
304304
// Ensure Result CR
305305
if !tc.Spec.Result.Disabled {
306306
tektonresult := result.GetTektonResultCR(tc, r.operatorVersion)
307+
if platformData := r.extension.GetPlatformData(); platformData != "" {
308+
if tektonresult.Annotations == nil {
309+
tektonresult.Annotations = map[string]string{}
310+
}
311+
tektonresult.Annotations[v1alpha1.PlatformDataHashKey] = platformData
312+
}
307313
logger.Debug("Ensuring TektonResult CR exists")
308314
if _, err := result.EnsureTektonResultExists(ctx, r.operatorClientSet.OperatorV1alpha1().TektonResults(), tektonresult); err != nil {
309315
errMsg := fmt.Sprintf("TektonResult %s", err.Error())

0 commit comments

Comments
 (0)