Skip to content

Commit 8ef992d

Browse files
committed
fix(operators): add missing v1alpha2 types and update crds
Add v1alpha2 types for OperatorGroup to fix a bad schemapatch on its CRD spec. Regenerate CRDs, deepcopy, etc.
1 parent 4193f31 commit 8ef992d

File tree

10 files changed

+458
-11
lines changed

10 files changed

+458
-11
lines changed

crds/operators.coreos.com_operatorgroups.yaml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ spec:
9292
type: array
9393
items:
9494
type: string
95+
x-kubernetes-list-type: set
9596
status:
9697
description: OperatorGroupStatus is the status for an OperatorGroupResource.
9798
type: object
@@ -108,6 +109,7 @@ spec:
108109
type: array
109110
items:
110111
type: string
112+
x-kubernetes-list-type: set
111113
serviceAccountRef:
112114
description: ServiceAccountRef references the service account object
113115
specified.
@@ -148,6 +150,142 @@ spec:
148150
- name: v1alpha2
149151
served: true
150152
storage: false
153+
"schema":
154+
"openAPIV3Schema":
155+
description: OperatorGroup is the unit of multitenancy for OLM managed operators.
156+
It constrains the installation of operators in its namespace to a specified
157+
set of target namespaces.
158+
type: object
159+
required:
160+
- metadata
161+
properties:
162+
apiVersion:
163+
description: 'APIVersion defines the versioned schema of this representation
164+
of an object. Servers should convert recognized schemas to the latest
165+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
166+
type: string
167+
kind:
168+
description: 'Kind is a string value representing the REST resource this
169+
object represents. Servers may infer this from the endpoint the client
170+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
171+
type: string
172+
metadata:
173+
type: object
174+
spec:
175+
description: OperatorGroupSpec is the spec for an OperatorGroup resource.
176+
type: object
177+
properties:
178+
selector:
179+
description: Selector selects the OperatorGroup's target namespaces.
180+
type: object
181+
properties:
182+
matchExpressions:
183+
description: matchExpressions is a list of label selector requirements.
184+
The requirements are ANDed.
185+
type: array
186+
items:
187+
description: A label selector requirement is a selector that
188+
contains values, a key, and an operator that relates the key
189+
and values.
190+
type: object
191+
required:
192+
- key
193+
- operator
194+
properties:
195+
key:
196+
description: key is the label key that the selector applies
197+
to.
198+
type: string
199+
operator:
200+
description: operator represents a key's relationship to
201+
a set of values. Valid operators are In, NotIn, Exists
202+
and DoesNotExist.
203+
type: string
204+
values:
205+
description: values is an array of string values. If the
206+
operator is In or NotIn, the values array must be non-empty.
207+
If the operator is Exists or DoesNotExist, the values
208+
array must be empty. This array is replaced during a strategic
209+
merge patch.
210+
type: array
211+
items:
212+
type: string
213+
matchLabels:
214+
description: matchLabels is a map of {key,value} pairs. A single
215+
{key,value} in the matchLabels map is equivalent to an element
216+
of matchExpressions, whose key field is "key", the operator
217+
is "In", and the values array contains only "value". The requirements
218+
are ANDed.
219+
type: object
220+
additionalProperties:
221+
type: string
222+
serviceAccountName:
223+
description: ServiceAccountName is the admin specified service account
224+
which will be used to deploy operator(s) in this operator group.
225+
type: string
226+
staticProvidedAPIs:
227+
description: Static tells OLM not to update the OperatorGroup's providedAPIs
228+
annotation
229+
type: boolean
230+
targetNamespaces:
231+
description: TargetNamespaces is an explicit set of namespaces to
232+
target. If it is set, Selector is ignored.
233+
type: array
234+
items:
235+
type: string
236+
status:
237+
description: OperatorGroupStatus is the status for an OperatorGroupResource.
238+
type: object
239+
required:
240+
- lastUpdated
241+
properties:
242+
lastUpdated:
243+
description: LastUpdated is a timestamp of the last time the OperatorGroup's
244+
status was Updated.
245+
type: string
246+
format: date-time
247+
namespaces:
248+
description: Namespaces is the set of target namespaces for the OperatorGroup.
249+
type: array
250+
items:
251+
type: string
252+
serviceAccountRef:
253+
description: ServiceAccountRef references the service account object
254+
specified.
255+
type: object
256+
properties:
257+
apiVersion:
258+
description: API version of the referent.
259+
type: string
260+
fieldPath:
261+
description: 'If referring to a piece of an object instead of
262+
an entire object, this string should contain a valid JSON/Go
263+
field access statement, such as desiredState.manifest.containers[2].
264+
For example, if the object reference is to a container within
265+
a pod, this would take on a value like: "spec.containers{name}"
266+
(where "name" refers to the name of the container that triggered
267+
the event) or if no container name is specified "spec.containers[2]"
268+
(container with index 2 in this pod). This syntax is chosen
269+
only to have some well-defined way of referencing a part of
270+
an object. TODO: this design is not final and this field is
271+
subject to change in the future.'
272+
type: string
273+
kind:
274+
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
275+
type: string
276+
name:
277+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
278+
type: string
279+
namespace:
280+
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
281+
type: string
282+
resourceVersion:
283+
description: 'Specific resourceVersion to which this reference
284+
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
285+
type: string
286+
uid:
287+
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
288+
type: string
151289
names:
152290
plural: operatorgroups
153291
singular: operatorgroup

crds/zz_defs.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/operators/install/install.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ import (
77
"github.com/operator-framework/api/pkg/operators"
88
v1 "github.com/operator-framework/api/pkg/operators/v1"
99
"github.com/operator-framework/api/pkg/operators/v1alpha1"
10+
"github.com/operator-framework/api/pkg/operators/v1alpha2"
11+
"github.com/operator-framework/api/pkg/operators/v2alpha1"
1012
)
1113

1214
// Install registers the API group and adds all of its types to the given scheme.
1315
func Install(scheme *runtime.Scheme) {
1416
utilruntime.Must(operators.AddToScheme(scheme))
1517
utilruntime.Must(v1alpha1.AddToScheme(scheme))
18+
utilruntime.Must(v1alpha2.AddToScheme(scheme))
1619
utilruntime.Must(v1.AddToScheme(scheme))
17-
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v1alpha1.SchemeGroupVersion))
20+
utilruntime.Must(v2alpha1.AddToScheme(scheme))
21+
utilruntime.Must(scheme.SetVersionPriority(v2alpha1.GroupVersion, v1.SchemeGroupVersion, v1alpha2.GroupVersion, v1alpha1.SchemeGroupVersion))
1822
}

pkg/operators/v1/operatorgroup_types.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1
22

33
import (
4+
"fmt"
45
"sort"
56
"strings"
67

@@ -15,6 +16,9 @@ const (
1516
OperatorGroupProvidedAPIsAnnotationKey = "olm.providedAPIs"
1617

1718
OperatorGroupKind = "OperatorGroup"
19+
20+
OperatorGroupLabelPrefix = "olm.operatorgroup/"
21+
OperatorGroupLabelTemplate = OperatorGroupLabelPrefix + "%s.%s"
1822
)
1923

2024
// OperatorGroupSpec is the spec for an OperatorGroup resource.
@@ -26,6 +30,7 @@ type OperatorGroupSpec struct {
2630
// TargetNamespaces is an explicit set of namespaces to target.
2731
// If it is set, Selector is ignored.
2832
// +optional
33+
// +listType=set
2934
TargetNamespaces []string `json:"targetNamespaces,omitempty"`
3035

3136
// ServiceAccountName is the admin specified service account which will be
@@ -40,6 +45,7 @@ type OperatorGroupSpec struct {
4045
// OperatorGroupStatus is the status for an OperatorGroupResource.
4146
type OperatorGroupStatus struct {
4247
// Namespaces is the set of target namespaces for the OperatorGroup.
48+
// +listType=set
4349
Namespaces []string `json:"namespaces,omitempty"`
4450

4551
// ServiceAccountRef references the service account object specified.
@@ -69,13 +75,16 @@ type OperatorGroup struct {
6975
type OperatorGroupList struct {
7076
metav1.TypeMeta `json:",inline"`
7177
metav1.ListMeta `json:"metadata"`
72-
78+
// +listType=set
7379
Items []OperatorGroup `json:"items"`
7480
}
7581

82+
// BuildTargetNamespaces returns the set of target namespaces as a sorted, comma-delimited string
7683
func (o *OperatorGroup) BuildTargetNamespaces() string {
77-
sort.Strings(o.Status.Namespaces)
78-
return strings.Join(o.Status.Namespaces, ",")
84+
ns := make([]string, len(o.Status.Namespaces))
85+
copy(ns, o.Status.Namespaces)
86+
sort.Strings(ns)
87+
return strings.Join(ns, ",")
7988
}
8089

8190
// IsServiceAccountSpecified returns true if the spec has a service account name specified.
@@ -95,3 +104,14 @@ func (o *OperatorGroup) HasServiceAccountSynced() bool {
95104

96105
return false
97106
}
107+
108+
// GetLabel returns a label that is applied to Namespaces to signify that the
109+
// namespace is a part of the OperatorGroup using selectors.
110+
func (o *OperatorGroup) GetLabel() string {
111+
return fmt.Sprintf(OperatorGroupLabelTemplate, o.GetNamespace(), o.GetName())
112+
}
113+
114+
// IsOperatorGroupLabel returns true if the label is an OperatorGroup label.
115+
func IsOperatorGroupLabel(label string) bool {
116+
return strings.HasPrefix(label, OperatorGroupLabelPrefix)
117+
}

pkg/operators/v1alpha2/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// +k8s:deepcopy-gen=package
2+
// +k8s:conversion-gen=github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators
3+
// +groupName=operators.coreos.com
4+
5+
// Package v1alpha2 contains resources types for version v1alpha2 of the operators.coreos.com API group.
6+
package v1alpha2
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
// Package v1alpha2 contains API Schema definitions for the discovery v1alpha2 API group.
16+
// +kubebuilder:object:generate=true
17+
// +groupName=operators.coreos.com
18+
package v1alpha2
19+
20+
import (
21+
"k8s.io/apimachinery/pkg/runtime/schema"
22+
"sigs.k8s.io/controller-runtime/pkg/scheme"
23+
)
24+
25+
var (
26+
// GroupVersion is group version used to register these objects.
27+
GroupVersion = schema.GroupVersion{Group: "operators.coreos.com", Version: "v1alpha2"}
28+
29+
// SchemeGroupVersion is required for compatibility with client generation.
30+
SchemeGroupVersion = GroupVersion
31+
32+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
33+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
34+
35+
// AddToScheme adds the types in this group-version to the given scheme.
36+
AddToScheme = SchemeBuilder.AddToScheme
37+
)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package v1alpha2
2+
3+
import (
4+
"sort"
5+
"strings"
6+
7+
corev1 "k8s.io/api/core/v1"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
)
10+
11+
const (
12+
OperatorGroupAnnotationKey = "olm.operatorGroup"
13+
OperatorGroupNamespaceAnnotationKey = "olm.operatorNamespace"
14+
OperatorGroupTargetsAnnotationKey = "olm.targetNamespaces"
15+
OperatorGroupProvidedAPIsAnnotationKey = "olm.providedAPIs"
16+
17+
OperatorGroupKind = "OperatorGroup"
18+
)
19+
20+
// OperatorGroupSpec is the spec for an OperatorGroup resource.
21+
type OperatorGroupSpec struct {
22+
// Selector selects the OperatorGroup's target namespaces.
23+
// +optional
24+
Selector *metav1.LabelSelector `json:"selector,omitempty"`
25+
26+
// TargetNamespaces is an explicit set of namespaces to target.
27+
// If it is set, Selector is ignored.
28+
// +optional
29+
TargetNamespaces []string `json:"targetNamespaces,omitempty"`
30+
31+
// ServiceAccountName is the admin specified service account which will be
32+
// used to deploy operator(s) in this operator group.
33+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
34+
35+
// Static tells OLM not to update the OperatorGroup's providedAPIs annotation
36+
// +optional
37+
StaticProvidedAPIs bool `json:"staticProvidedAPIs,omitempty"`
38+
}
39+
40+
// OperatorGroupStatus is the status for an OperatorGroupResource.
41+
type OperatorGroupStatus struct {
42+
// Namespaces is the set of target namespaces for the OperatorGroup.
43+
Namespaces []string `json:"namespaces,omitempty"`
44+
45+
// ServiceAccountRef references the service account object specified.
46+
ServiceAccountRef *corev1.ObjectReference `json:"serviceAccountRef,omitempty"`
47+
48+
// LastUpdated is a timestamp of the last time the OperatorGroup's status was Updated.
49+
LastUpdated *metav1.Time `json:"lastUpdated"`
50+
}
51+
52+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
53+
// +genclient
54+
55+
// OperatorGroup is the unit of multitenancy for OLM managed operators.
56+
// It constrains the installation of operators in its namespace to a specified set of target namespaces.
57+
type OperatorGroup struct {
58+
metav1.TypeMeta `json:",inline"`
59+
metav1.ObjectMeta `json:"metadata"`
60+
61+
// +optional
62+
Spec OperatorGroupSpec `json:"spec"`
63+
Status OperatorGroupStatus `json:"status,omitempty"`
64+
}
65+
66+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
67+
68+
// OperatorGroupList is a list of OperatorGroup resources.
69+
type OperatorGroupList struct {
70+
metav1.TypeMeta `json:",inline"`
71+
metav1.ListMeta `json:"metadata"`
72+
73+
Items []OperatorGroup `json:"items"`
74+
}
75+
76+
func (o *OperatorGroup) BuildTargetNamespaces() string {
77+
sort.Strings(o.Status.Namespaces)
78+
return strings.Join(o.Status.Namespaces, ",")
79+
}
80+
81+
// IsServiceAccountSpecified returns true if the spec has a service account name specified.
82+
func (o *OperatorGroup) IsServiceAccountSpecified() bool {
83+
if o.Spec.ServiceAccountName == "" {
84+
return false
85+
}
86+
87+
return true
88+
}
89+
90+
// HasServiceAccountSynced returns true if the service account specified has been synced.
91+
func (o *OperatorGroup) HasServiceAccountSynced() bool {
92+
if o.IsServiceAccountSpecified() && o.Status.ServiceAccountRef != nil {
93+
return true
94+
}
95+
96+
return false
97+
}

0 commit comments

Comments
 (0)