Skip to content

Commit 373ec2a

Browse files
committed
Initial WorkloadIdentityBinding controller
Setting up a pattern for more controllers, and adding a simple one to help with setting up WorkloadIdentityBinding.
1 parent 6e8b94a commit 373ec2a

File tree

11 files changed

+708
-42
lines changed

11 files changed

+708
-42
lines changed

porch/controllers/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.18-bullseye as builder
15+
FROM golang:1.17-bullseye as builder
1616

1717
WORKDIR /workspace
1818
COPY go.mod go.sum ./
@@ -44,7 +44,7 @@ COPY porch/api/ porch/api/
4444
COPY porch/controllers/ porch/controllers/
4545
COPY porch/pkg/ porch/pkg/
4646

47-
WORKDIR /workspace/porch/controllers/remoterootsync/
47+
WORKDIR /workspace/porch/controllers/
4848
RUN CGO_ENABLED=0 go build -o /porch-controllers -v .
4949

5050
FROM gcr.io/distroless/static

porch/controllers/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ push-image:
2525
.PHONY: build-image
2626
build-image:
2727
cd ../..; docker buildx build --load --tag $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) -f porch/controllers/Dockerfile .
28+
29+
30+
.PHONY: run-local
31+
run-local:
32+
GCP_PROJECT_ID=${GCP_PROJECT_ID} HACK_ENABLE_LOOPBACK=1 go run .
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Google LLC
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
---
162
apiVersion: apiextensions.k8s.io/v1
173
kind: CustomResourceDefinition
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.8.0
7+
creationTimestamp: null
8+
name: workloadidentitybindings.porch.kpt.dev
9+
spec:
10+
group: porch.kpt.dev
11+
names:
12+
kind: WorkloadIdentityBinding
13+
listKind: WorkloadIdentityBindingList
14+
plural: workloadidentitybindings
15+
singular: workloadidentitybinding
16+
scope: Namespaced
17+
versions:
18+
- additionalPrinterColumns:
19+
- jsonPath: .status.conditions[?(@.type=='Ready')].reason
20+
name: Ready
21+
type: string
22+
name: v1alpha1
23+
schema:
24+
openAPIV3Schema:
25+
description: WorkloadIdentityBinding
26+
properties:
27+
apiVersion:
28+
description: 'APIVersion defines the versioned schema of this representation
29+
of an object. Servers should convert recognized schemas to the latest
30+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
31+
type: string
32+
kind:
33+
description: 'Kind is a string value representing the REST resource this
34+
object represents. Servers may infer this from the endpoint the client
35+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
36+
type: string
37+
metadata:
38+
type: object
39+
spec:
40+
description: WorkloadIdentityBindingSpec defines the desired state of
41+
RemoteRootSync
42+
properties:
43+
resourceRef:
44+
properties:
45+
apiVersion:
46+
type: string
47+
external:
48+
type: string
49+
kind:
50+
type: string
51+
name:
52+
type: string
53+
namespace:
54+
type: string
55+
type: object
56+
serviceAccountRef:
57+
properties:
58+
apiVersion:
59+
type: string
60+
kind:
61+
type: string
62+
name:
63+
type: string
64+
namespace:
65+
type: string
66+
type: object
67+
type: object
68+
status:
69+
description: WorkloadIdentityBindingStatus defines the observed state
70+
of WorkloadIdentityBinding
71+
properties:
72+
conditions:
73+
description: Conditions describes the reconciliation state of the
74+
object.
75+
items:
76+
description: "Condition contains details for one aspect of the current
77+
state of this API Resource. --- This struct is intended for direct
78+
use as an array at the field path .status.conditions. For example,
79+
type FooStatus struct{ // Represents the observations of a foo's
80+
current state. // Known .status.conditions.type are: \"Available\",
81+
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
82+
// +listType=map // +listMapKey=type Conditions []metav1.Condition
83+
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
84+
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
85+
properties:
86+
lastTransitionTime:
87+
description: lastTransitionTime is the last time the condition
88+
transitioned from one status to another. This should be when
89+
the underlying condition changed. If that is not known, then
90+
using the time when the API field changed is acceptable.
91+
format: date-time
92+
type: string
93+
message:
94+
description: message is a human readable message indicating
95+
details about the transition. This may be an empty string.
96+
maxLength: 32768
97+
type: string
98+
observedGeneration:
99+
description: observedGeneration represents the .metadata.generation
100+
that the condition was set based upon. For instance, if .metadata.generation
101+
is currently 12, but the .status.conditions[x].observedGeneration
102+
is 9, the condition is out of date with respect to the current
103+
state of the instance.
104+
format: int64
105+
minimum: 0
106+
type: integer
107+
reason:
108+
description: reason contains a programmatic identifier indicating
109+
the reason for the condition's last transition. Producers
110+
of specific condition types may define expected values and
111+
meanings for this field, and whether the values are considered
112+
a guaranteed API. The value should be a CamelCase string.
113+
This field may not be empty.
114+
maxLength: 1024
115+
minLength: 1
116+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
117+
type: string
118+
status:
119+
description: status of the condition, one of True, False, Unknown.
120+
enum:
121+
- "True"
122+
- "False"
123+
- Unknown
124+
type: string
125+
type:
126+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
127+
--- Many .condition.type values are consistent across resources
128+
like Available, but because arbitrary conditions can be useful
129+
(see .node.status.conditions), the ability to deconflict is
130+
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
131+
maxLength: 316
132+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
133+
type: string
134+
required:
135+
- lastTransitionTime
136+
- message
137+
- reason
138+
- status
139+
- type
140+
type: object
141+
type: array
142+
type: object
143+
type: object
144+
served: true
145+
storage: true
146+
subresources:
147+
status: {}
148+
status:
149+
acceptedNames:
150+
kind: ""
151+
plural: ""
152+
conditions: []
153+
storedVersions: []

porch/controllers/remoterootsync/config/rbac/role.yaml renamed to porch/controllers/config/rbac/role.yaml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# Copyright 2022 Google LLC
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
14-
151
---
162
apiVersion: rbac.authorization.k8s.io/v1
173
kind: ClusterRole
@@ -52,6 +38,32 @@ rules:
5238
- get
5339
- patch
5440
- update
41+
- apiGroups:
42+
- config.cloud.google.com
43+
resources:
44+
- workloadidentitybindings
45+
verbs:
46+
- create
47+
- delete
48+
- get
49+
- list
50+
- patch
51+
- update
52+
- watch
53+
- apiGroups:
54+
- config.cloud.google.com
55+
resources:
56+
- workloadidentitybindings/finalizers
57+
verbs:
58+
- update
59+
- apiGroups:
60+
- config.cloud.google.com
61+
resources:
62+
- workloadidentitybindings/status
63+
verbs:
64+
- get
65+
- patch
66+
- update
5567
- apiGroups:
5668
- coordination.k8s.io
5769
resources:

porch/controllers/remoterootsync/main.go renamed to porch/controllers/main.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
package main
1616

17-
//go:generate go run sigs.k8s.io/controller-tools/cmd/[email protected] crd rbac:roleName=configmanagement-operator webhook paths="./..." output:crd:artifacts:config=config/crd/bases
17+
//go:generate go run sigs.k8s.io/controller-tools/cmd/[email protected] rbac:roleName=configmanagement-operator webhook paths="./..."
18+
19+
//go:generate go run sigs.k8s.io/controller-tools/cmd/[email protected] crd paths="./..." output:crd:artifacts:config=config/crd/bases
1820

1921
import (
2022
"context"
@@ -35,8 +37,10 @@ import (
3537
ctrl "sigs.k8s.io/controller-runtime"
3638
"sigs.k8s.io/controller-runtime/pkg/healthz"
3739

40+
porchapi "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1"
3841
api "github.com/GoogleContainerTools/kpt/porch/controllers/remoterootsync/api/v1alpha1"
3942
"github.com/GoogleContainerTools/kpt/porch/controllers/remoterootsync/pkg/controllers/remoterootsyncset"
43+
"github.com/GoogleContainerTools/kpt/porch/controllers/workloadidentitybinding/pkg/controllers/workloadidentitybinding"
4044
//+kubebuilder:scaffold:imports
4145
)
4246

@@ -52,6 +56,7 @@ var (
5256
func init() {
5357
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5458

59+
utilruntime.Must(porchapi.AddToScheme(scheme))
5560
utilruntime.Must(api.AddToScheme(scheme))
5661
//+kubebuilder:scaffold:scheme
5762
}
@@ -67,27 +72,23 @@ func main() {
6772
func run(ctx context.Context) error {
6873
// var metricsAddr string
6974
// var enableLeaderElection bool
70-
// var useAutopushEnv bool
7175
// var probeAddr string
72-
// var reconcilers string
7376

7477
klog.InitFlags(nil)
7578

76-
// flag.BoolVar(&useAutopushEnv, "autopush-env", false, "Use autopush environment endpoint.")
7779
// flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7880
// flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7981
// flag.BoolVar(&enableLeaderElection, "leader-elect", false,
8082
// "Enable leader election for controller manager. "+
8183
// "Enabling this will ensure there is only one active controller manager.")
82-
// flag.StringVar(&reconcilers, "reconcilers", "hub", "Reconcilers to enable")
8384

8485
managerOptions := ctrl.Options{
8586
Scheme: scheme,
8687
MetricsBindAddress: ":8080",
8788
Port: 9443,
8889
HealthProbeBindAddress: ":8081",
8990
LeaderElection: false,
90-
LeaderElectionID: "configmanagement-operator.config.cloud.google.com",
91+
LeaderElectionID: "porch-operators.config.cloud.google.com",
9192
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
9293
}
9394

@@ -106,6 +107,11 @@ func run(ctx context.Context) error {
106107
}).SetupWithManager(mgr); err != nil {
107108
return fmt.Errorf("error creating RemoteRootSyncSetReconciler controller: %w", err)
108109
}
110+
111+
if err = (&workloadidentitybinding.WorkloadIdentityBindingReconciler{}).SetupWithManager(mgr); err != nil {
112+
return fmt.Errorf("error creating WorkloadIdentityBindingReconciler controller: %w", err)
113+
}
114+
109115
//+kubebuilder:scaffold:builder
110116
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
111117
return fmt.Errorf("error adding health check: %w", err)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package v1alpha1 contains API Schema definitions for the porch.kpt.dev v1alpha1 API group
16+
// +kubebuilder:object:generate=true
17+
// +groupName=porch.kpt.dev
18+
package v1alpha1
19+
20+
import (
21+
"k8s.io/apimachinery/pkg/runtime/schema"
22+
"sigs.k8s.io/controller-runtime/pkg/scheme"
23+
)
24+
25+
//go:generate go run sigs.k8s.io/controller-tools/cmd/[email protected] object object:headerFile="../../../../scripts/boilerplate.go.txt" paths="./..."
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "porch.kpt.dev", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

0 commit comments

Comments
 (0)