Skip to content

Commit 3e5be56

Browse files
committed
added spire package with unit tests
Signed-off-by: pxp928 <parth.psu@gmail.com>
1 parent a1ca389 commit 3e5be56

File tree

212 files changed

+29889
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+29889
-698
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ run:
4444
skip-dirs:
4545
- vendor
4646
- pkg/client
47+
- pkg/spire/test
4748
timeout: 10m
4849
modules-download-mode: vendor

go.mod

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/tektoncd/pipeline
33
go 1.18
44

55
require (
6+
github.com/Microsoft/go-winio v0.5.2 // indirect
67
github.com/ahmetb/gen-crd-api-reference-docs v0.3.1-0.20220720053627-e327d0730470 // Waiting for https://github.com/ahmetb/gen-crd-api-reference-docs/pull/43/files to merge
78
github.com/cloudevents/sdk-go/v2 v2.11.0
89
github.com/containerd/containerd v1.5.13
@@ -18,11 +19,14 @@ require (
1819
github.com/mitchellh/go-homedir v1.1.0
1920
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198
2021
github.com/pkg/errors v0.9.1
22+
github.com/spiffe/go-spiffe/v2 v2.1.1
23+
github.com/spiffe/spire-api-sdk v1.3.1
2124
github.com/tektoncd/plumbing v0.0.0-20220817140952-3da8ce01aeeb
2225
go.opencensus.io v0.23.0
2326
go.uber.org/zap v1.23.0
2427
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
2528
gomodules.xyz/jsonpatch/v2 v2.2.0
29+
gopkg.in/square/go-jose.v2 v2.5.1
2630
k8s.io/api v0.23.9
2731
k8s.io/apimachinery v0.23.9
2832
k8s.io/client-go v0.23.9
@@ -38,7 +42,6 @@ require github.com/benbjohnson/clock v1.1.0 // indirect
3842
require k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
3943

4044
require (
41-
github.com/Microsoft/go-winio v0.5.1 // indirect
4245
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
4346
github.com/acomagu/bufpipe v1.0.3 // indirect
4447
github.com/emirpasic/gods v1.12.0 // indirect
@@ -51,6 +54,8 @@ require (
5154
gopkg.in/warnings.v0 v0.1.2 // indirect
5255
)
5356

57+
require github.com/zeebo/errs v1.2.2 // indirect
58+
5459
require (
5560
cloud.google.com/go/compute v1.5.0 // indirect
5661
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
@@ -136,7 +141,7 @@ require (
136141
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
137142
github.com/sirupsen/logrus v1.8.1 // indirect
138143
github.com/spf13/pflag v1.0.5 // indirect
139-
github.com/stretchr/testify v1.8.0 // indirect
144+
github.com/stretchr/testify v1.8.0
140145
github.com/vbatts/tar-split v0.11.2 // indirect
141146
go.uber.org/atomic v1.9.0 // indirect
142147
go.uber.org/automaxprocs v1.4.0 // indirect
@@ -155,8 +160,8 @@ require (
155160
google.golang.org/api v0.70.0 // indirect
156161
google.golang.org/appengine v1.6.7 // indirect
157162
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc // indirect
158-
google.golang.org/grpc v1.44.0 // indirect
159-
google.golang.org/protobuf v1.27.1 // indirect
163+
google.golang.org/grpc v1.46.0
164+
google.golang.org/protobuf v1.28.0
160165
gopkg.in/inf.v0 v0.9.1 // indirect
161166
gopkg.in/yaml.v2 v2.4.0 // indirect
162167
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

+18-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/reconciler/testing/logger.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
_ "knative.dev/pkg/client/injection/kube/informers/factory/filtered/fake"
2222
)
2323

24-
// SetupFakeContext sets up the the Context and the fake filtered informers for the tests.
24+
// SetupFakeContext sets up the Context and the fake filtered informers for the tests.
2525
func SetupFakeContext(t *testing.T) (context.Context, []controller.Informer) {
2626
ctx, _, informer := setupFakeContextWithLabelKey(t)
2727
cloudEventClientBehaviour := cloudevent.FakeClientBehaviour{
@@ -31,6 +31,12 @@ func SetupFakeContext(t *testing.T) (context.Context, []controller.Informer) {
3131
return WithLogger(ctx, t), informer
3232
}
3333

34+
// SetupDefaultContext sets up the Context and the default filtered informers for the tests.
35+
func SetupDefaultContext(t *testing.T) (context.Context, []controller.Informer) {
36+
ctx, _, informer := setupDefaultContextWithLabelKey(t)
37+
return WithLogger(ctx, t), informer
38+
}
39+
3440
// WithLogger returns the the Logger
3541
func WithLogger(ctx context.Context, t *testing.T) context.Context {
3642
return logging.WithLogger(ctx, TestLogger(t))
@@ -42,7 +48,7 @@ func TestLogger(t *testing.T) *zap.SugaredLogger {
4248
return logger.Sugar().Named(t.Name())
4349
}
4450

45-
// setupFakeContextWithLabelKey sets up the the Context and the fake informers for the tests
51+
// setupFakeContextWithLabelKey sets up the Context and the fake informers for the tests
4652
// The provided context includes the FilteredInformerFactory LabelKey.
4753
func setupFakeContextWithLabelKey(t zaptest.TestingT) (context.Context, context.CancelFunc, []controller.Informer) {
4854
ctx, c := context.WithCancel(logtesting.TestContextWithLogger(t))
@@ -51,3 +57,12 @@ func setupFakeContextWithLabelKey(t zaptest.TestingT) (context.Context, context.
5157
ctx, is := injection.Fake.SetupInformers(ctx, &rest.Config{})
5258
return ctx, c, is
5359
}
60+
61+
// setupDefaultContextWithLabelKey sets up the Context and the default informers for the tests
62+
// The provided context includes the FilteredInformerFactory LabelKey.
63+
func setupDefaultContextWithLabelKey(t zaptest.TestingT) (context.Context, context.CancelFunc, []controller.Informer) {
64+
ctx, c := context.WithCancel(logtesting.TestContextWithLogger(t))
65+
ctx = filteredinformerfactory.WithSelectors(ctx, v1beta1.ManagedByLabelKey)
66+
ctx, is := injection.Default.SetupInformers(ctx, &rest.Config{})
67+
return ctx, c, is
68+
}

pkg/spire/config/config.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2022 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 config
18+
19+
import (
20+
"fmt"
21+
"sort"
22+
"strings"
23+
)
24+
25+
// SpireConfig holds the images reference for a number of container images used
26+
// across tektoncd pipelines.
27+
type SpireConfig struct {
28+
// The trust domain corresponds to the trust root of a SPIFFE identity provider.
29+
TrustDomain string
30+
// Path to the spire agent socket defined by the CSI driver
31+
SocketPath string
32+
// Spire server address
33+
ServerAddr string
34+
// Prefix to attach to the node name when registering it with the spire server
35+
NodeAliasPrefix string
36+
37+
// MockSpire only to be used for testing the controller, will not exhibit
38+
// all characteristics of spire since it is only being used in the context
39+
// of process memory.
40+
MockSpire bool
41+
}
42+
43+
// Validate returns an error if any image is not set.
44+
func (c SpireConfig) Validate() error {
45+
var unset []string
46+
for _, f := range []struct {
47+
v, name string
48+
}{
49+
{c.TrustDomain, "spire-trust-domain"},
50+
{c.SocketPath, "spire-socket-path"},
51+
{c.ServerAddr, "spire-server-addr"},
52+
{c.NodeAliasPrefix, "spire-node-alias-prefix"},
53+
} {
54+
if f.v == "" {
55+
unset = append(unset, f.name)
56+
}
57+
}
58+
if len(unset) > 0 {
59+
sort.Strings(unset)
60+
return fmt.Errorf("found unset spire configuration flags: %s", unset)
61+
}
62+
63+
if !strings.HasPrefix(c.NodeAliasPrefix, "/") {
64+
return fmt.Errorf("Spire node alias should start with a /")
65+
}
66+
67+
return nil
68+
}

0 commit comments

Comments
 (0)