Skip to content

Commit 9276c82

Browse files
authored
feat: add observedgeneration to status object of all crds (#1041)
* feat: add observedgeneration to status object of all crds Signed-off-by: sandert-k8s <sandert98@gmail.com> * fix: use same reconcile logic as capsule controller Signed-off-by: sandert-k8s <sandert98@gmail.com> * feat: add conditionlist Signed-off-by: sandert-k8s <sandert98@gmail.com> --------- Signed-off-by: sandert-k8s <sandert98@gmail.com>
1 parent 56f67e0 commit 9276c82

11 files changed

Lines changed: 717 additions & 9 deletions

api/v1beta1/globalproxysettings_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package v1beta1
55

66
import (
7+
capmeta "github.com/projectcapsule/capsule/pkg/api/meta"
78
capsulerbac "github.com/projectcapsule/capsule/pkg/api/rbac"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
)
@@ -33,16 +34,31 @@ type GlobalSubject struct {
3334
Name string `json:"name"`
3435
}
3536

37+
// GlobalProxySettingsStatus defines the observed state of GlobalProxySettings.
38+
type GlobalProxySettingsStatus struct {
39+
// ObservedGeneration is the most recent generation observed by the controller.
40+
// +optional
41+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
42+
43+
// Conditions contains the reconciliation conditions for this GlobalProxySettings.
44+
// +optional
45+
Conditions capmeta.ConditionList `json:"conditions,omitempty"`
46+
}
47+
3648
//+kubebuilder:object:root=true
3749
//+kubebuilder:subresource:status
3850
//+kubebuilder:resource:scope=Cluster
51+
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description="Reconcile status of this GlobalProxySettings"
52+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
3953

4054
// GlobalProxySettings is the Schema for the globalproxysettings API.
4155
type GlobalProxySettings struct {
4256
metav1.TypeMeta `json:",inline"`
4357
metav1.ObjectMeta `json:"metadata,omitempty"`
4458

4559
Spec GlobalProxySettingsSpec `json:"spec,omitempty"`
60+
// +optional
61+
Status GlobalProxySettingsStatus `json:"status,omitempty"`
4662
}
4763

4864
//+kubebuilder:object:root=true

api/v1beta1/proxysettings_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package v1beta1
55

66
import (
7+
capmeta "github.com/projectcapsule/capsule/pkg/api/meta"
78
capsulerbac "github.com/projectcapsule/capsule/pkg/api/rbac"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
)
@@ -29,14 +30,30 @@ type ProxySettingSpec struct {
2930
Subjects []OwnerSpec `json:"subjects"`
3031
}
3132

33+
// ProxySettingStatus defines the observed state of ProxySetting.
34+
type ProxySettingStatus struct {
35+
// ObservedGeneration is the most recent generation observed by the controller.
36+
// +optional
37+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
38+
39+
// Conditions contains the reconciliation conditions for this ProxySetting.
40+
// +optional
41+
Conditions capmeta.ConditionList `json:"conditions,omitempty"`
42+
}
43+
3244
//+kubebuilder:object:root=true
45+
//+kubebuilder:subresource:status
46+
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description="Reconcile status of this ProxySetting"
47+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
3348

3449
// ProxySetting is the Schema for the proxysettings API.
3550
type ProxySetting struct {
3651
metav1.TypeMeta `json:",inline"`
3752
metav1.ObjectMeta `json:"metadata,omitempty"`
3853

3954
Spec ProxySettingSpec `json:"spec,omitempty"`
55+
// +optional
56+
Status ProxySettingStatus `json:"status,omitempty"`
4057
}
4158

4259
//+kubebuilder:object:root=true

api/v1beta1/zz_generated.deepcopy.go

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

charts/capsule-proxy/crds/capsule.clastix.io_globalproxysettings.yaml

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ spec:
1414
singular: globalproxysettings
1515
scope: Cluster
1616
versions:
17-
- name: v1beta1
17+
- additionalPrinterColumns:
18+
- description: Reconcile status of this GlobalProxySettings
19+
jsonPath: .status.conditions[?(@.type=="Ready")].status
20+
name: Ready
21+
type: string
22+
- description: Age
23+
jsonPath: .metadata.creationTimestamp
24+
name: Age
25+
type: date
26+
name: v1beta1
1827
schema:
1928
openAPIV3Schema:
2029
description: GlobalProxySettings is the Schema for the globalproxysettings
@@ -166,6 +175,73 @@ spec:
166175
required:
167176
- rules
168177
type: object
178+
status:
179+
description: GlobalProxySettingsStatus defines the observed state of GlobalProxySettings.
180+
properties:
181+
conditions:
182+
description: Conditions contains the reconciliation conditions for
183+
this GlobalProxySettings.
184+
items:
185+
description: Condition contains details for one aspect of the current
186+
state of this API Resource.
187+
properties:
188+
lastTransitionTime:
189+
description: |-
190+
lastTransitionTime is the last time the condition transitioned from one status to another.
191+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
192+
format: date-time
193+
type: string
194+
message:
195+
description: |-
196+
message is a human readable message indicating details about the transition.
197+
This may be an empty string.
198+
maxLength: 32768
199+
type: string
200+
observedGeneration:
201+
description: |-
202+
observedGeneration represents the .metadata.generation that the condition was set based upon.
203+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
204+
with respect to the current state of the instance.
205+
format: int64
206+
minimum: 0
207+
type: integer
208+
reason:
209+
description: |-
210+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
211+
Producers of specific condition types may define expected values and meanings for this field,
212+
and whether the values are considered a guaranteed API.
213+
The value should be a CamelCase string.
214+
This field may not be empty.
215+
maxLength: 1024
216+
minLength: 1
217+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
218+
type: string
219+
status:
220+
description: status of the condition, one of True, False, Unknown.
221+
enum:
222+
- "True"
223+
- "False"
224+
- Unknown
225+
type: string
226+
type:
227+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
228+
maxLength: 316
229+
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])$
230+
type: string
231+
required:
232+
- lastTransitionTime
233+
- message
234+
- reason
235+
- status
236+
- type
237+
type: object
238+
type: array
239+
observedGeneration:
240+
description: ObservedGeneration is the most recent generation observed
241+
by the controller.
242+
format: int64
243+
type: integer
244+
type: object
169245
type: object
170246
served: true
171247
storage: true

charts/capsule-proxy/crds/capsule.clastix.io_proxysettings.yaml

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ spec:
1414
singular: proxysetting
1515
scope: Namespaced
1616
versions:
17-
- name: v1beta1
17+
- additionalPrinterColumns:
18+
- description: Reconcile status of this ProxySetting
19+
jsonPath: .status.conditions[?(@.type=="Ready")].status
20+
name: Ready
21+
type: string
22+
- description: Age
23+
jsonPath: .metadata.creationTimestamp
24+
name: Age
25+
type: date
26+
name: v1beta1
1827
schema:
1928
openAPIV3Schema:
2029
description: ProxySetting is the Schema for the proxysettings API.
@@ -182,6 +191,75 @@ spec:
182191
required:
183192
- subjects
184193
type: object
194+
status:
195+
description: ProxySettingStatus defines the observed state of ProxySetting.
196+
properties:
197+
conditions:
198+
description: Conditions contains the reconciliation conditions for
199+
this ProxySetting.
200+
items:
201+
description: Condition contains details for one aspect of the current
202+
state of this API Resource.
203+
properties:
204+
lastTransitionTime:
205+
description: |-
206+
lastTransitionTime is the last time the condition transitioned from one status to another.
207+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
208+
format: date-time
209+
type: string
210+
message:
211+
description: |-
212+
message is a human readable message indicating details about the transition.
213+
This may be an empty string.
214+
maxLength: 32768
215+
type: string
216+
observedGeneration:
217+
description: |-
218+
observedGeneration represents the .metadata.generation that the condition was set based upon.
219+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
220+
with respect to the current state of the instance.
221+
format: int64
222+
minimum: 0
223+
type: integer
224+
reason:
225+
description: |-
226+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
227+
Producers of specific condition types may define expected values and meanings for this field,
228+
and whether the values are considered a guaranteed API.
229+
The value should be a CamelCase string.
230+
This field may not be empty.
231+
maxLength: 1024
232+
minLength: 1
233+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
234+
type: string
235+
status:
236+
description: status of the condition, one of True, False, Unknown.
237+
enum:
238+
- "True"
239+
- "False"
240+
- Unknown
241+
type: string
242+
type:
243+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
244+
maxLength: 316
245+
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])$
246+
type: string
247+
required:
248+
- lastTransitionTime
249+
- message
250+
- reason
251+
- status
252+
- type
253+
type: object
254+
type: array
255+
observedGeneration:
256+
description: ObservedGeneration is the most recent generation observed
257+
by the controller.
258+
format: int64
259+
type: integer
260+
type: object
185261
type: object
186262
served: true
187263
storage: true
264+
subresources:
265+
status: {}

charts/capsule-proxy/templates/rbac.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ rules:
101101
- apiGroups: ["authorization.k8s.io"]
102102
resources: ["subjectaccessreviews"]
103103
verbs: ["create"]
104+
105+
# Allow updating status subresources for observedGeneration tracking
106+
- apiGroups: ["capsule.clastix.io"]
107+
resources:
108+
- proxysettings/status
109+
- globalproxysettings/status
110+
verbs: ["update", "patch"]
104111
---
105112
apiVersion: rbac.authorization.k8s.io/v1
106113
kind: ClusterRoleBinding

0 commit comments

Comments
 (0)