-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup: refactor to disable metrics
Signed-off-by: PuneetPunamiya <[email protected]>
- Loading branch information
1 parent
2277f66
commit 54b6e02
Showing
11 changed files
with
111 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !disable_tls | ||
|
||
/* | ||
Copyright 2021 The Tekton Authors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build disable_tls | ||
|
||
package config | ||
|
||
// GetMetricsConfigName returns the name of the configmap containing all | ||
// customizations for the storage bucket. | ||
func GetMetricsConfigName() string { panic("not supported when tls is disabled") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//go:build !disable_tls | ||
|
||
package config | ||
|
||
import ( | ||
"context" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"knative.dev/pkg/metrics" | ||
) | ||
|
||
// GetMetricsConfigName returns the name of the configmap containing all | ||
// customizations for the storage bucket. | ||
func GetMetricsConfigName() string { | ||
return metrics.ConfigMapName() | ||
} | ||
|
||
// NewFeatureFlagsFromConfigMap returns a Config for the given configmap | ||
func NewFeatureFlagsFromConfigMap(config *corev1.ConfigMap) (*FeatureFlags, error) { | ||
return NewFeatureFlagsFromMap(config.Data) | ||
} | ||
|
||
// GetVerificationNoMatchPolicy returns the "trusted-resources-verification-no-match-policy" value | ||
func GetVerificationNoMatchPolicy(ctx context.Context) string { | ||
return FromContextOrDefaults(ctx).FeatureFlags.VerificationNoMatchPolicy | ||
} | ||
|
||
// IsSpireEnabled checks if non-falsifiable provenance is enforced through SPIRE | ||
func IsSpireEnabled(ctx context.Context) bool { | ||
return FromContextOrDefaults(ctx).FeatureFlags.EnforceNonfalsifiability == EnforceNonfalsifiabilityWithSpire | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !disable_tls | ||
|
||
/* | ||
Copyright 2022 The Tekton Authors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !disable_tls | ||
|
||
/* | ||
Copyright 2022 The Tekton Authors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !disable_tls | ||
|
||
/* | ||
Copyright 2019 The Tekton Authors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2025 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package substitution | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ApplyReplacements returns a string with references to parameters replaced, | ||
// based on the mapping provided in replacements. | ||
// For example, if the input string is "foo: $(params.foo)", and replacements maps "params.foo" to "bar", | ||
// the output would be "foo: bar". | ||
func ApplyReplacements(in string, replacements map[string]string) string { | ||
replacementsList := []string{} | ||
for k, v := range replacements { | ||
replacementsList = append(replacementsList, fmt.Sprintf("$(%s)", k), v) | ||
} | ||
// strings.Replacer does all replacements in one pass, preventing multiple replacements | ||
// See #2093 for an explanation on why we need to do this. | ||
replacer := strings.NewReplacer(replacementsList...) | ||
return replacer.Replace(in) | ||
} | ||
|
||
// ApplyArrayReplacements takes an input string, and output an array of strings related to possible arrayReplacements. If there aren't any | ||
// areas where the input can be split up via arrayReplacements, then just return an array with a single element, | ||
// which is ApplyReplacements(in, replacements). | ||
func ApplyArrayReplacements(in string, stringReplacements map[string]string, arrayReplacements map[string][]string) []string { | ||
for k, v := range arrayReplacements { | ||
stringToReplace := fmt.Sprintf("$(%s)", k) | ||
|
||
// If the input string matches a replacement's key (without padding characters), return the corresponding array. | ||
// Note that the webhook should prevent all instances where this could evaluate to false. | ||
if (strings.Count(in, stringToReplace) == 1) && len(in) == len(stringToReplace) { | ||
return v | ||
} | ||
|
||
// same replace logic for star array expressions | ||
starStringtoReplace := fmt.Sprintf("$(%s[*])", k) | ||
if (strings.Count(in, starStringtoReplace) == 1) && len(in) == len(starStringtoReplace) { | ||
return v | ||
} | ||
} | ||
|
||
// Otherwise return a size-1 array containing the input string with standard stringReplacements applied. | ||
return []string{ApplyReplacements(in, stringReplacements)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !disable_tls | ||
|
||
/* | ||
Copyright 2019 The Tekton Authors | ||
|