Skip to content

Commit d09668c

Browse files
committed
Fixup
1 parent f4362e5 commit d09668c

File tree

7 files changed

+227
-8
lines changed

7 files changed

+227
-8
lines changed

api/v1/clusterextensionrevision_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type ClusterExtensionRevisionSpec struct {
3838
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="phases is immutable"
3939
Phases []ClusterExtensionRevisionPhase `json:"phases"`
4040
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="previous is immutable"
41-
Previous []ClusterExtensionRevisionPrevious `json:"previous"`
41+
Previous []ClusterExtensionRevisionPrevious `json:"previous,omitempty"`
4242
}
4343

4444
// ClusterExtensionRevisionLifecycleState specifies the lifecycle state of the ClusterExtensionRevision.

cmd/operator-controller/main.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,18 @@ func run() error {
473473
return err
474474
}
475475
mapFunc := func(ctx context.Context, ce *ocv1.ClusterExtension, c *rest.Config, o crcache.Options) (*rest.Config, crcache.Options, error) {
476-
// TODO: Rest Config Mapping / change ServiceAccount
476+
saKey := client.ObjectKey{
477+
Name: ce.Spec.ServiceAccount.Name,
478+
Namespace: ce.Spec.Namespace,
479+
}
480+
saConfig := rest.AnonymousClientConfig(c)
481+
saConfig.Wrap(func(rt http.RoundTripper) http.RoundTripper {
482+
return &authentication.TokenInjectingRoundTripper{
483+
Tripper: rt,
484+
TokenGetter: tokenGetter,
485+
Key: saKey,
486+
}
487+
})
477488

478489
// Cache scoping
479490
req1, err := labels.NewRequirement(
@@ -483,12 +494,17 @@ func run() error {
483494
}
484495
o.DefaultLabelSelector = labels.NewSelector().Add(*req1)
485496

486-
return c, o, nil
497+
return saConfig, o, nil
487498
}
488-
accessManager := managedcache.NewObjectBoundAccessManager[*ocv1.ClusterExtension](
499+
500+
accessManager := managedcache.NewObjectBoundAccessManager(
489501
ctrl.Log.WithName("accessmanager"), mapFunc, restConfig, crcache.Options{
490502
Scheme: mgr.GetScheme(), Mapper: mgr.GetRESTMapper(),
491503
})
504+
if err := mgr.Add(accessManager); err != nil {
505+
setupLog.Error(err, "unable to register AccessManager")
506+
return err
507+
}
492508
// Boxcutter
493509

494510
if err = (&controllers.ClusterExtensionReconciler{
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.17.3
7+
name: clusterextensionrevisions.olm.operatorframework.io
8+
spec:
9+
group: olm.operatorframework.io
10+
names:
11+
kind: ClusterExtensionRevision
12+
listKind: ClusterExtensionRevisionList
13+
plural: clusterextensionrevisions
14+
singular: clusterextensionrevision
15+
scope: Cluster
16+
versions:
17+
- name: v1
18+
schema:
19+
openAPIV3Schema:
20+
description: ClusterExtensionRevision is the Schema for the clusterextensionrevisions
21+
API
22+
properties:
23+
apiVersion:
24+
description: |-
25+
APIVersion defines the versioned schema of this representation of an object.
26+
Servers should convert recognized schemas to the latest internal value, and
27+
may reject unrecognized values.
28+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
29+
type: string
30+
kind:
31+
description: |-
32+
Kind is a string value representing the REST resource this object represents.
33+
Servers may infer this from the endpoint the client submits requests to.
34+
Cannot be updated.
35+
In CamelCase.
36+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
37+
type: string
38+
metadata:
39+
type: object
40+
spec:
41+
description: spec is an optional field that defines the desired state
42+
of the ClusterExtension.
43+
properties:
44+
lifecycleState:
45+
default: Active
46+
description: Specifies the lifecycle state of the ClusterExtensionRevision.
47+
enum:
48+
- Active
49+
- Paused
50+
- Archived
51+
type: string
52+
x-kubernetes-validations:
53+
- message: can not un-archive
54+
rule: oldSelf == 'Active' || oldSelf == 'Paused' || oldSelf == 'Archived'
55+
&& oldSelf == self
56+
phases:
57+
items:
58+
properties:
59+
name:
60+
type: string
61+
objects:
62+
items:
63+
properties:
64+
object:
65+
type: object
66+
x-kubernetes-embedded-resource: true
67+
x-kubernetes-preserve-unknown-fields: true
68+
required:
69+
- object
70+
type: object
71+
type: array
72+
required:
73+
- name
74+
- objects
75+
type: object
76+
type: array
77+
x-kubernetes-validations:
78+
- message: phases is immutable
79+
rule: self == oldSelf
80+
previous:
81+
items:
82+
properties:
83+
name:
84+
type: string
85+
uid:
86+
description: |-
87+
UID is a type that holds unique ID values, including UUIDs. Because we
88+
don't ONLY use UUIDs, this is an alias to string. Being a type captures
89+
intent and helps make sure that UIDs and names do not get conflated.
90+
type: string
91+
required:
92+
- name
93+
- uid
94+
type: object
95+
type: array
96+
x-kubernetes-validations:
97+
- message: previous is immutable
98+
rule: self == oldSelf
99+
revision:
100+
format: int64
101+
type: integer
102+
x-kubernetes-validations:
103+
- message: revision is immutable
104+
rule: self == oldSelf
105+
required:
106+
- phases
107+
- revision
108+
type: object
109+
status:
110+
description: status is an optional field that defines the observed state
111+
of the ClusterExtension.
112+
properties:
113+
conditions:
114+
items:
115+
description: Condition contains details for one aspect of the current
116+
state of this API Resource.
117+
properties:
118+
lastTransitionTime:
119+
description: |-
120+
lastTransitionTime is the last time the condition transitioned from one status to another.
121+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
122+
format: date-time
123+
type: string
124+
message:
125+
description: |-
126+
message is a human readable message indicating details about the transition.
127+
This may be an empty string.
128+
maxLength: 32768
129+
type: string
130+
observedGeneration:
131+
description: |-
132+
observedGeneration represents the .metadata.generation that the condition was set based upon.
133+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
134+
with respect to the current state of the instance.
135+
format: int64
136+
minimum: 0
137+
type: integer
138+
reason:
139+
description: |-
140+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
141+
Producers of specific condition types may define expected values and meanings for this field,
142+
and whether the values are considered a guaranteed API.
143+
The value should be a CamelCase string.
144+
This field may not be empty.
145+
maxLength: 1024
146+
minLength: 1
147+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
148+
type: string
149+
status:
150+
description: status of the condition, one of True, False, Unknown.
151+
enum:
152+
- "True"
153+
- "False"
154+
- Unknown
155+
type: string
156+
type:
157+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
158+
maxLength: 316
159+
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])$
160+
type: string
161+
required:
162+
- lastTransitionTime
163+
- message
164+
- reason
165+
- status
166+
- type
167+
type: object
168+
type: array
169+
x-kubernetes-list-map-keys:
170+
- type
171+
x-kubernetes-list-type: map
172+
type: object
173+
type: object
174+
served: true
175+
storage: true
176+
subresources:
177+
status: {}

config/base/operator-controller/rbac/role.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ rules:
2828
- olm.operatorframework.io
2929
resources:
3030
- clusterextensionrevisions
31-
- clusterextensions
3231
verbs:
32+
- create
33+
- delete
3334
- get
3435
- list
3536
- patch
@@ -50,6 +51,16 @@ rules:
5051
verbs:
5152
- patch
5253
- update
54+
- apiGroups:
55+
- olm.operatorframework.io
56+
resources:
57+
- clusterextensions
58+
verbs:
59+
- get
60+
- list
61+
- patch
62+
- update
63+
- watch
5364
- apiGroups:
5465
- rbac.authorization.k8s.io
5566
resources:

internal/operator-controller/applier/boxcutter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func (bc *Boxcutter) apply(
105105
// Build desired revision
106106
desiredRevision := &ocv1.ClusterExtensionRevision{
107107
ObjectMeta: metav1.ObjectMeta{
108+
Annotations: map[string]string{},
108109
Labels: map[string]string{
109110
controllers.ClusterExtensionRevisionOwnerLabel: ext.Name,
110111
},
@@ -146,8 +147,9 @@ func (bc *Boxcutter) apply(
146147
revisionNumber++
147148

148149
newRevision := desiredRevision
150+
newRevision.Name = fmt.Sprintf("%s-%d", ext.Name, revisionNumber)
151+
newRevision.Annotations[revisionHashAnnotation] = desiredHash
149152
newRevision.Spec.Revision = revisionNumber
150-
// newRevision.Spec.Previous
151153
for _, prevRevision := range prevRevisions {
152154
newRevision.Spec.Previous = append(newRevision.Spec.Previous, ocv1.ClusterExtensionRevisionPrevious{
153155
Name: prevRevision.Name,

internal/operator-controller/controllers/clusterextension_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error {
418418
controller, err := ctrl.NewControllerManagedBy(mgr).
419419
For(&ocv1.ClusterExtension{}).
420420
Named("controller-operator-cluster-extension-controller").
421+
Owns(&ocv1.ClusterExtensionRevision{}).
421422
Watches(&ocv1.ClusterCatalog{},
422423
crhandler.EnqueueRequestsFromMapFunc(clusterExtensionRequestsForCatalog(mgr.GetClient(), mgr.GetLogger())),
423424
builder.WithPredicates(predicate.Funcs{

internal/operator-controller/controllers/clusterextensionrevision_controller.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type accessManager interface {
5959
Source(handler.EventHandler, ...predicate.Predicate) source.Source
6060
}
6161

62-
//+kubebuilder:rbac:groups=olm.operatorframework.io,resources=clusterextensionrevisions,verbs=get;list;watch;update;patch
62+
//+kubebuilder:rbac:groups=olm.operatorframework.io,resources=clusterextensionrevisions,verbs=get;list;watch;update;patch;create;delete
6363
//+kubebuilder:rbac:groups=olm.operatorframework.io,resources=clusterextensionrevisions/status,verbs=update;patch
6464
//+kubebuilder:rbac:groups=olm.operatorframework.io,resources=clusterextensionrevisions/finalizers,verbs=update
6565

@@ -118,6 +118,18 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(
118118
objects = append(objects, &pobj)
119119
}
120120
}
121+
122+
// THIS IS STUPID, PLEASE FIX!
123+
// Revisions need individual finalizers on the ClusterExtension to prevent it's premature deletion.
124+
if rev.DeletionTimestamp.IsZero() &&
125+
rev.Spec.LifecycleState != ocv1.ClusterExtensionRevisionLifecycleStateArchived {
126+
// We can't lookup the complete ClusterExtension when it's already deleted.
127+
// This only works when the controller-manager is not restarted during teardown.
128+
if err := c.Client.Get(ctx, client.ObjectKeyFromObject(ce), ce); err != nil {
129+
return res, err
130+
}
131+
}
132+
121133
accessor, err := c.AccessManager.GetWithUser(ctx, ce, rev, objects)
122134
if err != nil {
123135
return res, fmt.Errorf("get cache: %w", err)
@@ -280,7 +292,7 @@ func (c *ClusterExtensionRevisionReconciler) SetupWithManager(mgr ctrl.Manager)
280292
).
281293
WatchesRawSource(
282294
c.AccessManager.Source(
283-
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &ocv1.ClusterExtension{}),
295+
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &ocv1.ClusterExtensionRevision{}),
284296
predicate.ResourceVersionChangedPredicate{},
285297
),
286298
).

0 commit comments

Comments
 (0)