Skip to content

Commit 7f0a4ca

Browse files
committed
feat: add observedgeneration to status object of all crds
Signed-off-by: sandert-k8s <sandert98@gmail.com>
1 parent a64380e commit 7f0a4ca

13 files changed

Lines changed: 504 additions & 7 deletions

api/v1beta1/globalproxysettings_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ type GlobalSubject struct {
3333
Name string `json:"name"`
3434
}
3535

36+
// GlobalProxySettingsStatus defines the observed state of GlobalProxySettings.
37+
type GlobalProxySettingsStatus struct {
38+
// ObservedGeneration is the most recent generation observed by the controller.
39+
// +optional
40+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
41+
}
42+
3643
//+kubebuilder:object:root=true
3744
//+kubebuilder:subresource:status
3845
//+kubebuilder:resource:scope=Cluster
@@ -43,6 +50,8 @@ type GlobalProxySettings struct {
4350
metav1.ObjectMeta `json:"metadata,omitempty"`
4451

4552
Spec GlobalProxySettingsSpec `json:"spec,omitempty"`
53+
// +optional
54+
Status GlobalProxySettingsStatus `json:"status,omitempty"`
4655
}
4756

4857
//+kubebuilder:object:root=true

api/v1beta1/proxysettings_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,24 @@ type ProxySettingSpec struct {
2929
Subjects []OwnerSpec `json:"subjects"`
3030
}
3131

32+
// ProxySettingStatus defines the observed state of ProxySetting.
33+
type ProxySettingStatus struct {
34+
// ObservedGeneration is the most recent generation observed by the controller.
35+
// +optional
36+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
37+
}
38+
3239
//+kubebuilder:object:root=true
40+
//+kubebuilder:subresource:status
3341

3442
// ProxySetting is the Schema for the proxysettings API.
3543
type ProxySetting struct {
3644
metav1.TypeMeta `json:",inline"`
3745
metav1.ObjectMeta `json:"metadata,omitempty"`
3846

3947
Spec ProxySettingSpec `json:"spec,omitempty"`
48+
// +optional
49+
Status ProxySettingStatus `json:"status,omitempty"`
4050
}
4151

4252
//+kubebuilder:object:root=true

api/v1beta1/zz_generated.deepcopy.go

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

capsule-proxy

44.2 MB
Binary file not shown.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ spec:
166166
required:
167167
- rules
168168
type: object
169+
status:
170+
description: GlobalProxySettingsStatus defines the observed state of GlobalProxySettings.
171+
properties:
172+
observedGeneration:
173+
description: ObservedGeneration is the most recent generation observed
174+
by the controller.
175+
format: int64
176+
type: integer
177+
type: object
169178
type: object
170179
served: true
171180
storage: true

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ spec:
182182
required:
183183
- subjects
184184
type: object
185+
status:
186+
description: ProxySettingStatus defines the observed state of ProxySetting.
187+
properties:
188+
observedGeneration:
189+
description: ObservedGeneration is the most recent generation observed
190+
by the controller.
191+
format: int64
192+
type: integer
193+
type: object
185194
type: object
186195
served: true
187196
storage: true
197+
subresources:
198+
status: {}

charts/capsule-proxy/templates/rbac.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ rules:
9191
- apiGroups: ["authorization.k8s.io"]
9292
resources: ["subjectaccessreviews"]
9393
verbs: ["create"]
94+
95+
# Allow updating status subresources for observedGeneration tracking
96+
- apiGroups: ["capsule.clastix.io"]
97+
resources:
98+
- proxysettings/status
99+
- globalproxysettings/status
100+
verbs: ["update", "patch"]
94101
---
95102
apiVersion: rbac.authorization.k8s.io/v1
96103
kind: ClusterRoleBinding

e2e/global_settings_test.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
. "github.com/onsi/gomega"
88
rbacv1 "k8s.io/api/rbac/v1"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"k8s.io/apimachinery/pkg/types"
1011
"k8s.io/client-go/kubernetes"
1112
"sigs.k8s.io/controller-runtime/pkg/client"
1213

@@ -68,14 +69,33 @@ var _ = Describe("GlobalProxySettings", func() {
6869
},
6970
}
7071

71-
for _, tran := range settings {
72+
for _, setting := range settings {
73+
s := setting
7274
Eventually(func() error {
73-
tran.ResourceVersion = ""
75+
s.ResourceVersion = ""
7476

75-
return k8sClient.Create(context.TODO(), tran)
77+
return k8sClient.Create(context.TODO(), s)
7678
}).Should(Succeed())
7779
}
7880

81+
// Verify observedGeneration is set after reconciliation for each created resource
82+
for _, setting := range settings {
83+
name := setting.GetName()
84+
85+
Eventually(func(g Gomega) {
86+
current := &v1beta1.GlobalProxySettings{}
87+
g.Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: name}, current)).To(Succeed())
88+
89+
g.Expect(current.Status.ObservedGeneration).To(
90+
Equal(current.GetGeneration()),
91+
"expected GlobalProxySettings %q status.observedGeneration (%d) to equal metadata.generation (%d)",
92+
name,
93+
current.Status.ObservedGeneration,
94+
current.GetGeneration(),
95+
)
96+
}, defaultTimeoutInterval, defaultPollInterval).Should(Succeed())
97+
}
98+
7999
// Load Alice's kubeconfig
80100
aliceClient, err = loadKubeConfig("alice")
81101
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)