Skip to content

Commit 11834ef

Browse files
refactor
Signed-off-by: PuneetPunamiya <[email protected]>
1 parent 8a41001 commit 11834ef

21 files changed

+724
-108
lines changed

cmd/entrypoint/main.go

+16-18
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ import (
3030

3131
"github.com/containerd/containerd/platforms"
3232
"github.com/tektoncd/pipeline/cmd/entrypoint/subcommands"
33-
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
34-
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
35-
"github.com/tektoncd/pipeline/pkg/credentials"
36-
"github.com/tektoncd/pipeline/pkg/credentials/dockercreds"
37-
"github.com/tektoncd/pipeline/pkg/credentials/gitcreds"
33+
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1/types"
34+
35+
// "github.com/tektoncd/pipeline/pkg/credentials"
3836
"github.com/tektoncd/pipeline/pkg/entrypoint"
39-
"github.com/tektoncd/pipeline/pkg/termination"
37+
message "github.com/tektoncd/pipeline/pkg/termination/message"
4038
)
4139

4240
var (
@@ -66,8 +64,8 @@ const (
6664
func main() {
6765
// Add credential flags originally introduced with our legacy credentials helper
6866
// image (creds-init).
69-
gitcreds.AddFlags(flag.CommandLine)
70-
dockercreds.AddFlags(flag.CommandLine)
67+
// gitcreds.AddFlags(flag.CommandLine)
68+
// dockercreds.AddFlags(flag.CommandLine)
7169

7270
// Split args with `--` for the entrypoint and what it should execute
7371
args, commandArgs := extractArgs(os.Args[1:])
@@ -91,12 +89,12 @@ func main() {
9189
// from secret volume mounts to /tekton/creds. This is done to support the expansion
9290
// of a variable, $(credentials.path), that resolves to a single place with all the
9391
// stored credentials.
94-
builders := []credentials.Builder{dockercreds.NewBuilder(), gitcreds.NewBuilder()}
95-
for _, c := range builders {
96-
if err := c.Write(pipeline.CredsDir); err != nil {
97-
log.Printf("Error initializing credentials: %s", err)
98-
}
99-
}
92+
// builders := []credentials.Builder{dockercreds.NewBuilder(), gitcreds.NewBuilder()}
93+
// for _, c := range builders {
94+
// if err := c.Write(pipeline.CredsDir); err != nil {
95+
// log.Printf("Error initializing credentials: %s", err)
96+
// }
97+
// }
10098

10199
var cmd []string
102100
if *ep != "" {
@@ -153,9 +151,9 @@ func main() {
153151

154152
// Copy any creds injected by the controller into the $HOME directory of the current
155153
// user so that they're discoverable by git / ssh.
156-
if err := credentials.CopyCredsToHome(credentials.CredsInitCredentials); err != nil {
157-
log.Printf("non-fatal error copying credentials: %q", err)
158-
}
154+
// if err := credentials.CopyCredsToHome(credentials.CredsInitCredentials); err != nil {
155+
// log.Printf("non-fatal error copying credentials: %q", err)
156+
// }
159157

160158
if err := e.Go(); err != nil {
161159
switch t := err.(type) { //nolint:errorlint // checking for multiple types with errors.As is ugly.
@@ -165,7 +163,7 @@ func main() {
165163
case entrypoint.SkipError:
166164
log.Print("Skipping step because a previous step failed")
167165
os.Exit(1)
168-
case termination.MessageLengthError:
166+
case message.MessageLengthError:
169167
log.Print(err.Error())
170168
os.Exit(1)
171169
case entrypoint.ContextError:

pkg/apis/config/feature_flags.go

+12-15
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 (
@@ -441,20 +438,20 @@ func setVerificationNoMatchPolicy(cfgMap map[string]string, defaultValue string,
441438
return nil
442439
}
443440

444-
// NewFeatureFlagsFromConfigMap returns a Config for the given configmap
445-
func NewFeatureFlagsFromConfigMap(config *corev1.ConfigMap) (*FeatureFlags, error) {
446-
return NewFeatureFlagsFromMap(config.Data)
447-
}
441+
// // NewFeatureFlagsFromConfigMap returns a Config for the given configmap
442+
// func NewFeatureFlagsFromConfigMap(config *corev1.ConfigMap) (*FeatureFlags, error) {
443+
// return NewFeatureFlagsFromMap(config.Data)
444+
// }
448445

449-
// GetVerificationNoMatchPolicy returns the "trusted-resources-verification-no-match-policy" value
450-
func GetVerificationNoMatchPolicy(ctx context.Context) string {
451-
return FromContextOrDefaults(ctx).FeatureFlags.VerificationNoMatchPolicy
452-
}
446+
// // GetVerificationNoMatchPolicy returns the "trusted-resources-verification-no-match-policy" value
447+
// func GetVerificationNoMatchPolicy(ctx context.Context) string {
448+
// return FromContextOrDefaults(ctx).FeatureFlags.VerificationNoMatchPolicy
449+
// }
453450

454-
// IsSpireEnabled checks if non-falsifiable provenance is enforced through SPIRE
455-
func IsSpireEnabled(ctx context.Context) bool {
456-
return FromContextOrDefaults(ctx).FeatureFlags.EnforceNonfalsifiability == EnforceNonfalsifiabilityWithSpire
457-
}
451+
// // IsSpireEnabled checks if non-falsifiable provenance is enforced through SPIRE
452+
// func IsSpireEnabled(ctx context.Context) bool {
453+
// return FromContextOrDefaults(ctx).FeatureFlags.EnforceNonfalsifiability == EnforceNonfalsifiabilityWithSpire
454+
// }
458455

459456
type PerFeatureFlag struct {
460457
// Name of the feature flag

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

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

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

2424
const (
@@ -111,9 +111,9 @@ type Metrics struct {
111111

112112
// GetMetricsConfigName returns the name of the configmap containing all
113113
// customizations for the storage bucket.
114-
func GetMetricsConfigName() string {
115-
return metrics.ConfigMapName()
116-
}
114+
// func GetMetricsConfigName() string {
115+
// return metrics.ConfigMapName()
116+
// }
117117

118118
// Equals returns true if two Configs are identical
119119
func (cfg *Metrics) Equals(other *Metrics) bool {

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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
Copyright 2024 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 types
18+
19+
import (
20+
"github.com/google/go-cmp/cmp"
21+
)
22+
23+
// Algorithm Standard cryptographic hash algorithm
24+
type Algorithm string
25+
26+
// Artifact represents an artifact within a system, potentially containing multiple values
27+
// associated with it.
28+
type Artifact struct {
29+
// The artifact's identifying category name
30+
Name string `json:"name,omitempty"`
31+
// A collection of values related to the artifact
32+
Values []ArtifactValue `json:"values,omitempty"`
33+
// Indicate if the artifact is a build output or a by-product
34+
BuildOutput bool `json:"buildOutput,omitempty"`
35+
}
36+
37+
// ArtifactValue represents a specific value or data element within an Artifact.
38+
type ArtifactValue struct {
39+
Digest map[Algorithm]string `json:"digest,omitempty"` // Algorithm-specific digests for verifying the content (e.g., SHA256)
40+
Uri string `json:"uri,omitempty"` // Location where the artifact value can be retrieved
41+
}
42+
43+
// TaskRunStepArtifact represents an artifact produced or used by a step within a task run.
44+
// It directly uses the Artifact type for its structure.
45+
type TaskRunStepArtifact = Artifact
46+
47+
// Artifacts represents the collection of input and output artifacts associated with
48+
// a task run or a similar process. Artifacts in this context are units of data or resources
49+
// that the process either consumes as input or produces as output.
50+
type Artifacts struct {
51+
Inputs []Artifact `json:"inputs,omitempty"`
52+
Outputs []Artifact `json:"outputs,omitempty"`
53+
}
54+
55+
func (a *Artifacts) Merge(another *Artifacts) {
56+
inputMap := make(map[string][]ArtifactValue)
57+
var newInputs []Artifact
58+
59+
for _, v := range a.Inputs {
60+
inputMap[v.Name] = v.Values
61+
}
62+
if another != nil {
63+
for _, v := range another.Inputs {
64+
_, ok := inputMap[v.Name]
65+
if !ok {
66+
inputMap[v.Name] = []ArtifactValue{}
67+
}
68+
for _, vv := range v.Values {
69+
exists := false
70+
for _, av := range inputMap[v.Name] {
71+
if cmp.Equal(vv, av) {
72+
exists = true
73+
break
74+
}
75+
}
76+
if !exists {
77+
inputMap[v.Name] = append(inputMap[v.Name], vv)
78+
}
79+
}
80+
}
81+
}
82+
83+
for k, v := range inputMap {
84+
newInputs = append(newInputs, Artifact{
85+
Name: k,
86+
Values: v,
87+
})
88+
}
89+
90+
outputMap := make(map[string]Artifact)
91+
var newOutputs []Artifact
92+
for _, v := range a.Outputs {
93+
outputMap[v.Name] = v
94+
}
95+
96+
if another != nil {
97+
for _, v := range another.Outputs {
98+
_, ok := outputMap[v.Name]
99+
if !ok {
100+
outputMap[v.Name] = Artifact{Name: v.Name, Values: []ArtifactValue{}, BuildOutput: v.BuildOutput}
101+
}
102+
// only update buildOutput to true.
103+
// Do not convert to false if it was true before.
104+
if v.BuildOutput {
105+
art := outputMap[v.Name]
106+
art.BuildOutput = v.BuildOutput
107+
outputMap[v.Name] = art
108+
}
109+
for _, vv := range v.Values {
110+
exists := false
111+
for _, av := range outputMap[v.Name].Values {
112+
if cmp.Equal(vv, av) {
113+
exists = true
114+
break
115+
}
116+
}
117+
if !exists {
118+
art := outputMap[v.Name]
119+
art.Values = append(art.Values, vv)
120+
outputMap[v.Name] = art
121+
}
122+
}
123+
}
124+
}
125+
126+
for _, v := range outputMap {
127+
newOutputs = append(newOutputs, Artifact{
128+
Name: v.Name,
129+
Values: v.Values,
130+
BuildOutput: v.BuildOutput,
131+
})
132+
}
133+
a.Inputs = newInputs
134+
a.Outputs = newOutputs
135+
}

0 commit comments

Comments
 (0)