Skip to content

Commit 59d0bc8

Browse files
authored
Add PackageVariantSet controller (#3707)
1 parent 6b7f4a6 commit 59d0bc8

File tree

15 files changed

+1708
-17
lines changed

15 files changed

+1708
-17
lines changed

internal/fnruntime/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func SelectInput(input []*yaml.RNode, selectors, exclusions []kptfilev1.Selector
147147
} else {
148148
for _, node := range input {
149149
for _, selector := range selectors {
150-
if isMatch(node, selector) {
150+
if IsMatch(node, selector) {
151151
selectedInput = append(selectedInput, node)
152152
}
153153
}
@@ -160,7 +160,7 @@ func SelectInput(input []*yaml.RNode, selectors, exclusions []kptfilev1.Selector
160160
for _, node := range selectedInput {
161161
matchesExclusion := false
162162
for _, exclusion := range exclusions {
163-
if !exclusion.IsEmpty() && isMatch(node, exclusion) {
163+
if !exclusion.IsEmpty() && IsMatch(node, exclusion) {
164164
matchesExclusion = true
165165
break
166166
}
@@ -172,8 +172,8 @@ func SelectInput(input []*yaml.RNode, selectors, exclusions []kptfilev1.Selector
172172
return filteredInput, nil
173173
}
174174

175-
// isMatch returns true if the resource matches input selection criteria
176-
func isMatch(node *yaml.RNode, selector kptfilev1.Selector) bool {
175+
// IsMatch returns true if the resource matches input selection criteria
176+
func IsMatch(node *yaml.RNode, selector kptfilev1.Selector) bool {
177177
// keep expanding with new selectors
178178
return nameMatch(node, selector) && namespaceMatch(node, selector) &&
179179
kindMatch(node, selector) && apiVersionMatch(node, selector) &&

internal/fnruntime/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ spec:
135135
t.Run(tc.name, func(t *testing.T) {
136136
node, err := yaml.Parse(tc.input)
137137
assert.NoError(t, err)
138-
actual := isMatch(node, tc.selector)
138+
actual := IsMatch(node, tc.selector)
139139
assert.Equal(t, tc.expected, actual)
140140
})
141141
}

porch/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TEST_GIT_SERVER_IMAGE ?= test-git-server
4949
# Only enable a subset of reconcilers in porch controllers by default. Use the RECONCILERS
5050
# env variable to specify a specific list of reconcilers or use
5151
# RECONCILERS=* to enable all known reconcilers.
52-
ALL_RECONCILERS="rootsyncsets,remoterootsyncsets,workloadidentitybindings,rootsyncdeployments,functiondiscovery,packagevariants,rootsyncrollouts"
52+
ALL_RECONCILERS="rootsyncsets,remoterootsyncsets,workloadidentitybindings,rootsyncdeployments,functiondiscovery,packagevariants,packagevariantsets,rootsyncrollouts"
5353
ifndef RECONCILERS
5454
ENABLED_RECONCILERS="rootsyncsets,remoterootsyncsets,workloadidentitybindings,functiondiscovery"
5555
else
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
# Copyright 2023 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+
---
16+
apiVersion: apiextensions.k8s.io/v1
17+
kind: CustomResourceDefinition
18+
metadata:
19+
annotations:
20+
controller-gen.kubebuilder.io/version: v0.8.0
21+
creationTimestamp: null
22+
name: packagevariantsets.config.porch.kpt.dev
23+
spec:
24+
group: config.porch.kpt.dev
25+
names:
26+
kind: PackageVariantSet
27+
listKind: PackageVariantSetList
28+
plural: packagevariantsets
29+
singular: packagevariantset
30+
scope: Namespaced
31+
versions:
32+
- name: v1alpha1
33+
schema:
34+
openAPIV3Schema:
35+
description: PackageVariantSet represents an upstream package revision and
36+
a way to target specific downstream repositories where a variant of the
37+
upstream package should be created.
38+
properties:
39+
apiVersion:
40+
description: 'APIVersion defines the versioned schema of this representation
41+
of an object. Servers should convert recognized schemas to the latest
42+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
43+
type: string
44+
kind:
45+
description: 'Kind is a string value representing the REST resource this
46+
object represents. Servers may infer this from the endpoint the client
47+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
48+
type: string
49+
metadata:
50+
type: object
51+
spec:
52+
description: PackageVariantSetSpec defines the desired state of PackageVariantSet
53+
properties:
54+
adoptionPolicy:
55+
type: string
56+
deletionPolicy:
57+
type: string
58+
targets:
59+
items:
60+
properties:
61+
objects:
62+
description: 'option 3: a selector against a set of arbitrary
63+
objects'
64+
properties:
65+
repoName:
66+
properties:
67+
fromField:
68+
type: string
69+
value:
70+
type: string
71+
type: object
72+
selectors:
73+
items:
74+
properties:
75+
annotations:
76+
additionalProperties:
77+
type: string
78+
description: Annotations on the target resources
79+
type: object
80+
apiVersion:
81+
description: APIVersion of the target resources
82+
type: string
83+
kind:
84+
description: Kind of the target resources
85+
type: string
86+
labelSelector:
87+
description: Labels on the target resources
88+
properties:
89+
matchExpressions:
90+
description: matchExpressions is a list of label
91+
selector requirements. The requirements are
92+
ANDed.
93+
items:
94+
description: A label selector requirement is
95+
a selector that contains values, a key, and
96+
an operator that relates the key and values.
97+
properties:
98+
key:
99+
description: key is the label key that the
100+
selector applies to.
101+
type: string
102+
operator:
103+
description: operator represents a key's
104+
relationship to a set of values. Valid
105+
operators are In, NotIn, Exists and DoesNotExist.
106+
type: string
107+
values:
108+
description: values is an array of string
109+
values. If the operator is In or NotIn,
110+
the values array must be non-empty. If
111+
the operator is Exists or DoesNotExist,
112+
the values array must be empty. This array
113+
is replaced during a strategic merge patch.
114+
items:
115+
type: string
116+
type: array
117+
required:
118+
- key
119+
- operator
120+
type: object
121+
type: array
122+
matchLabels:
123+
additionalProperties:
124+
type: string
125+
description: matchLabels is a map of {key,value}
126+
pairs. A single {key,value} in the matchLabels
127+
map is equivalent to an element of matchExpressions,
128+
whose key field is "key", the operator is "In",
129+
and the values array contains only "value".
130+
The requirements are ANDed.
131+
type: object
132+
type: object
133+
name:
134+
description: Name of the target resources
135+
type: string
136+
namespace:
137+
description: Namespace of the target resources
138+
type: string
139+
type: object
140+
type: array
141+
type: object
142+
package:
143+
description: 'option 1: an explicit repo/package name pair'
144+
properties:
145+
name:
146+
type: string
147+
repo:
148+
type: string
149+
type: object
150+
packageName:
151+
description: For options 2 and 3, PackageName specifies how
152+
to create the name of the package variant
153+
properties:
154+
baseName:
155+
properties:
156+
fromField:
157+
type: string
158+
value:
159+
type: string
160+
type: object
161+
namePrefix:
162+
properties:
163+
fromField:
164+
type: string
165+
value:
166+
type: string
167+
type: object
168+
nameSuffix:
169+
properties:
170+
fromField:
171+
type: string
172+
value:
173+
type: string
174+
type: object
175+
type: object
176+
repositories:
177+
description: 'option 2: a label selector against a set of repositories'
178+
properties:
179+
matchExpressions:
180+
description: matchExpressions is a list of label selector
181+
requirements. The requirements are ANDed.
182+
items:
183+
description: A label selector requirement is a selector
184+
that contains values, a key, and an operator that relates
185+
the key and values.
186+
properties:
187+
key:
188+
description: key is the label key that the selector
189+
applies to.
190+
type: string
191+
operator:
192+
description: operator represents a key's relationship
193+
to a set of values. Valid operators are In, NotIn,
194+
Exists and DoesNotExist.
195+
type: string
196+
values:
197+
description: values is an array of string values.
198+
If the operator is In or NotIn, the values array
199+
must be non-empty. If the operator is Exists or
200+
DoesNotExist, the values array must be empty. This
201+
array is replaced during a strategic merge patch.
202+
items:
203+
type: string
204+
type: array
205+
required:
206+
- key
207+
- operator
208+
type: object
209+
type: array
210+
matchLabels:
211+
additionalProperties:
212+
type: string
213+
description: matchLabels is a map of {key,value} pairs.
214+
A single {key,value} in the matchLabels map is equivalent
215+
to an element of matchExpressions, whose key field is
216+
"key", the operator is "In", and the values array contains
217+
only "value". The requirements are ANDed.
218+
type: object
219+
type: object
220+
type: object
221+
type: array
222+
upstream:
223+
properties:
224+
package:
225+
properties:
226+
name:
227+
type: string
228+
repo:
229+
type: string
230+
type: object
231+
ref:
232+
type: string
233+
revision:
234+
type: string
235+
type: object
236+
type: object
237+
status:
238+
description: PackageVariantSetStatus defines the observed state of PackageVariantSet
239+
properties:
240+
validationErrors:
241+
description: 'TODO: Move this to conditions.'
242+
items:
243+
type: string
244+
type: array
245+
type: object
246+
type: object
247+
served: true
248+
storage: true
249+
subresources:
250+
status: {}
251+
status:
252+
acceptedNames:
253+
kind: ""
254+
plural: ""
255+
conditions: []
256+
storedVersions: []

porch/controllers/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/GoogleContainerTools/kpt/porch/controllers/functiondiscovery"
4343
"github.com/GoogleContainerTools/kpt/porch/controllers/klippy/pkg/controllers/klippy"
4444
"github.com/GoogleContainerTools/kpt/porch/controllers/packagevariants/pkg/controllers/packagevariant"
45+
"github.com/GoogleContainerTools/kpt/porch/controllers/packagevariantsets/pkg/controllers/packagevariantset"
4546
"github.com/GoogleContainerTools/kpt/porch/controllers/remoterootsyncsets/pkg/controllers/remoterootsyncset"
4647
"github.com/GoogleContainerTools/kpt/porch/controllers/rootsyncdeployments/pkg/controllers/rootsyncdeployment"
4748
"github.com/GoogleContainerTools/kpt/porch/controllers/rootsyncrollouts/pkg/controllers/rootsyncrollout"
@@ -54,6 +55,7 @@ import (
5455
var (
5556
reconcilers = map[string]Reconciler{
5657
"packagevariants": &packagevariant.PackageVariantReconciler{},
58+
"packagevariantsets": &packagevariantset.PackageVariantSetReconciler{},
5759
"rootsyncsets": &rootsyncset.RootSyncSetReconciler{},
5860
"remoterootsyncsets": &remoterootsyncset.RemoteRootSyncSetReconciler{},
5961
"workloadidentitybindings": &workloadidentitybinding.WorkloadIdentityBindingReconciler{},

porch/controllers/packagevariants/api/v1alpha1/packagevariant_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const (
4848

4949
DeletionPolicyDelete DeletionPolicy = "delete"
5050
DeletionPolicyOrphan DeletionPolicy = "orphan"
51+
52+
Finalizer = "config.porch.kpt.dev/packagevariants"
5153
)
5254

5355
// PackageVariantSpec defines the desired state of PackageVariant
@@ -72,6 +74,7 @@ type Downstream struct {
7274

7375
// PackageVariantStatus defines the observed state of PackageVariant
7476
type PackageVariantStatus struct {
77+
// TODO: Move this to conditions.
7578
ValidationErrors []string `json:"validationErrors,omitempty"`
7679
}
7780

0 commit comments

Comments
 (0)