Skip to content

Commit f73b726

Browse files
cleanup: refactor to disable metrics
Signed-off-by: PuneetPunamiya <[email protected]>
1 parent 5be87c6 commit f73b726

11 files changed

+111
-64
lines changed

pkg/apis/config/feature_flags.go

-18
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ limitations under the License.
1717
package config
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"os"
2322
"strconv"
2423
"strings"
25-
26-
corev1 "k8s.io/api/core/v1"
2724
)
2825

2926
const (
@@ -448,21 +445,6 @@ func setVerificationNoMatchPolicy(cfgMap map[string]string, defaultValue string,
448445
return nil
449446
}
450447

451-
// NewFeatureFlagsFromConfigMap returns a Config for the given configmap
452-
func NewFeatureFlagsFromConfigMap(config *corev1.ConfigMap) (*FeatureFlags, error) {
453-
return NewFeatureFlagsFromMap(config.Data)
454-
}
455-
456-
// GetVerificationNoMatchPolicy returns the "trusted-resources-verification-no-match-policy" value
457-
func GetVerificationNoMatchPolicy(ctx context.Context) string {
458-
return FromContextOrDefaults(ctx).FeatureFlags.VerificationNoMatchPolicy
459-
}
460-
461-
// IsSpireEnabled checks if non-falsifiable provenance is enforced through SPIRE
462-
func IsSpireEnabled(ctx context.Context) bool {
463-
return FromContextOrDefaults(ctx).FeatureFlags.EnforceNonfalsifiability == EnforceNonfalsifiabilityWithSpire
464-
}
465-
466448
type PerFeatureFlag struct {
467449
// Name of the feature flag
468450
Name string

pkg/apis/config/featureflags_validation.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !disable_tls
2+
13
/*
24
Copyright 2021 The Tekton Authors
35

pkg/apis/config/metrics.go

-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package config
1818

1919
import (
2020
corev1 "k8s.io/api/core/v1"
21-
"knative.dev/pkg/metrics"
2221
)
2322

2423
const (
@@ -109,12 +108,6 @@ type Metrics struct {
109108
ThrottleWithNamespace bool
110109
}
111110

112-
// GetMetricsConfigName returns the name of the configmap containing all
113-
// customizations for the storage bucket.
114-
func GetMetricsConfigName() string {
115-
return metrics.ConfigMapName()
116-
}
117-
118111
// Equals returns true if two Configs are identical
119112
func (cfg *Metrics) Equals(other *Metrics) bool {
120113
if cfg == nil && other == nil {

pkg/apis/config/metrics_notls.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build disable_tls
2+
3+
package config
4+
5+
// GetMetricsConfigName returns the name of the configmap containing all
6+
// customizations for the storage bucket.
7+
func GetMetricsConfigName() string { panic("not supported when tls is disabled") }

pkg/apis/config/metrics_tls.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//go:build !disable_tls
2+
3+
package config
4+
5+
import (
6+
"context"
7+
8+
corev1 "k8s.io/api/core/v1"
9+
"knative.dev/pkg/metrics"
10+
)
11+
12+
// GetMetricsConfigName returns the name of the configmap containing all
13+
// customizations for the storage bucket.
14+
func GetMetricsConfigName() string {
15+
return metrics.ConfigMapName()
16+
}
17+
18+
// NewFeatureFlagsFromConfigMap returns a Config for the given configmap
19+
func NewFeatureFlagsFromConfigMap(config *corev1.ConfigMap) (*FeatureFlags, error) {
20+
return NewFeatureFlagsFromMap(config.Data)
21+
}
22+
23+
// GetVerificationNoMatchPolicy returns the "trusted-resources-verification-no-match-policy" value
24+
func GetVerificationNoMatchPolicy(ctx context.Context) string {
25+
return FromContextOrDefaults(ctx).FeatureFlags.VerificationNoMatchPolicy
26+
}
27+
28+
// IsSpireEnabled checks if non-falsifiable provenance is enforced through SPIRE
29+
func IsSpireEnabled(ctx context.Context) bool {
30+
return FromContextOrDefaults(ctx).FeatureFlags.EnforceNonfalsifiability == EnforceNonfalsifiabilityWithSpire
31+
}

pkg/apis/config/resolver/store.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !disable_tls
2+
13
/*
24
Copyright 2022 The Tekton Authors
35

pkg/apis/config/spire_config.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !disable_tls
2+
13
/*
24
Copyright 2022 The Tekton Authors
35

pkg/apis/config/store.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !disable_tls
2+
13
/*
24
Copyright 2019 The Tekton Authors
35

pkg/substitution/replacements.go

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2025 The Tekton Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package substitution
18+
19+
import (
20+
"fmt"
21+
"strings"
22+
)
23+
24+
// ApplyReplacements returns a string with references to parameters replaced,
25+
// based on the mapping provided in replacements.
26+
// For example, if the input string is "foo: $(params.foo)", and replacements maps "params.foo" to "bar",
27+
// the output would be "foo: bar".
28+
func ApplyReplacements(in string, replacements map[string]string) string {
29+
replacementsList := []string{}
30+
for k, v := range replacements {
31+
replacementsList = append(replacementsList, fmt.Sprintf("$(%s)", k), v)
32+
}
33+
// strings.Replacer does all replacements in one pass, preventing multiple replacements
34+
// See #2093 for an explanation on why we need to do this.
35+
replacer := strings.NewReplacer(replacementsList...)
36+
return replacer.Replace(in)
37+
}
38+
39+
// ApplyArrayReplacements takes an input string, and output an array of strings related to possible arrayReplacements. If there aren't any
40+
// areas where the input can be split up via arrayReplacements, then just return an array with a single element,
41+
// which is ApplyReplacements(in, replacements).
42+
func ApplyArrayReplacements(in string, stringReplacements map[string]string, arrayReplacements map[string][]string) []string {
43+
for k, v := range arrayReplacements {
44+
stringToReplace := fmt.Sprintf("$(%s)", k)
45+
46+
// If the input string matches a replacement's key (without padding characters), return the corresponding array.
47+
// Note that the webhook should prevent all instances where this could evaluate to false.
48+
if (strings.Count(in, stringToReplace) == 1) && len(in) == len(stringToReplace) {
49+
return v
50+
}
51+
52+
// same replace logic for star array expressions
53+
starStringtoReplace := fmt.Sprintf("$(%s[*])", k)
54+
if (strings.Count(in, starStringtoReplace) == 1) && len(in) == len(starStringtoReplace) {
55+
return v
56+
}
57+
}
58+
59+
// Otherwise return a size-1 array containing the input string with standard stringReplacements applied.
60+
return []string{ApplyReplacements(in, stringReplacements)}
61+
}

pkg/substitution/substitution.go

+2-39
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !disable_tls
2+
13
/*
24
Copyright 2019 The Tekton Authors
35
@@ -306,45 +308,6 @@ func matchGroups(matches []string, pattern *regexp.Regexp) map[string]string {
306308
return groups
307309
}
308310

309-
// ApplyReplacements returns a string with references to parameters replaced,
310-
// based on the mapping provided in replacements.
311-
// For example, if the input string is "foo: $(params.foo)", and replacements maps "params.foo" to "bar",
312-
// the output would be "foo: bar".
313-
func ApplyReplacements(in string, replacements map[string]string) string {
314-
replacementsList := []string{}
315-
for k, v := range replacements {
316-
replacementsList = append(replacementsList, fmt.Sprintf("$(%s)", k), v)
317-
}
318-
// strings.Replacer does all replacements in one pass, preventing multiple replacements
319-
// See #2093 for an explanation on why we need to do this.
320-
replacer := strings.NewReplacer(replacementsList...)
321-
return replacer.Replace(in)
322-
}
323-
324-
// ApplyArrayReplacements takes an input string, and output an array of strings related to possible arrayReplacements. If there aren't any
325-
// areas where the input can be split up via arrayReplacements, then just return an array with a single element,
326-
// which is ApplyReplacements(in, replacements).
327-
func ApplyArrayReplacements(in string, stringReplacements map[string]string, arrayReplacements map[string][]string) []string {
328-
for k, v := range arrayReplacements {
329-
stringToReplace := fmt.Sprintf("$(%s)", k)
330-
331-
// If the input string matches a replacement's key (without padding characters), return the corresponding array.
332-
// Note that the webhook should prevent all instances where this could evaluate to false.
333-
if (strings.Count(in, stringToReplace) == 1) && len(in) == len(stringToReplace) {
334-
return v
335-
}
336-
337-
// same replace logic for star array expressions
338-
starStringtoReplace := fmt.Sprintf("$(%s[*])", k)
339-
if (strings.Count(in, starStringtoReplace) == 1) && len(in) == len(starStringtoReplace) {
340-
return v
341-
}
342-
}
343-
344-
// Otherwise return a size-1 array containing the input string with standard stringReplacements applied.
345-
return []string{ApplyReplacements(in, stringReplacements)}
346-
}
347-
348311
// TrimArrayIndex replaces all `[i]` and `[*]` to "".
349312
func TrimArrayIndex(s string) string {
350313
return arrayIndexingRegex.ReplaceAllString(s, "")

pkg/termination/parse.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !disable_tls
2+
13
/*
24
Copyright 2019 The Tekton Authors
35

0 commit comments

Comments
 (0)