Skip to content

Commit d24d234

Browse files
committedJan 26, 2024
using awslab package to manage conditions
1 parent 63d44d0 commit d24d234

File tree

8 files changed

+315
-47
lines changed

8 files changed

+315
-47
lines changed
 

‎api/v1alpha1/policyendpoint_types.go

+177-21
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
"github.com/awslabs/operatorpkg/status"
2021
corev1 "k8s.io/api/core/v1"
2122
networking "k8s.io/api/networking/v1"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/runtime"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
26+
"k8s.io/apimachinery/pkg/types"
2327
)
2428

2529
// PolicyReference is the reference to the network policy resource
@@ -105,7 +109,167 @@ type PolicyEndpointStatus struct {
105109
// Important: Run "make" to regenerate code after modifying this file
106110

107111
// +optional
108-
Conditions []PolicyEndpointCondition `json:"conditions,omitempty"`
112+
Conditions []status.Condition `json:"conditions,omitempty"`
113+
}
114+
115+
// DeepCopyObject implements status.Object.
116+
func (*PolicyEndpointStatus) DeepCopyObject() runtime.Object {
117+
panic("unimplemented")
118+
}
119+
120+
// GetAnnotations implements status.Object.
121+
func (*PolicyEndpointStatus) GetAnnotations() map[string]string {
122+
panic("unimplemented")
123+
}
124+
125+
// GetCreationTimestamp implements status.Object.
126+
func (*PolicyEndpointStatus) GetCreationTimestamp() metav1.Time {
127+
panic("unimplemented")
128+
}
129+
130+
// GetDeletionGracePeriodSeconds implements status.Object.
131+
func (*PolicyEndpointStatus) GetDeletionGracePeriodSeconds() *int64 {
132+
panic("unimplemented")
133+
}
134+
135+
// GetDeletionTimestamp implements status.Object.
136+
func (*PolicyEndpointStatus) GetDeletionTimestamp() *metav1.Time {
137+
panic("unimplemented")
138+
}
139+
140+
// GetFinalizers implements status.Object.
141+
func (*PolicyEndpointStatus) GetFinalizers() []string {
142+
panic("unimplemented")
143+
}
144+
145+
// GetGenerateName implements status.Object.
146+
func (*PolicyEndpointStatus) GetGenerateName() string {
147+
panic("unimplemented")
148+
}
149+
150+
// GetGeneration implements status.Object.
151+
func (*PolicyEndpointStatus) GetGeneration() int64 {
152+
panic("unimplemented")
153+
}
154+
155+
// GetLabels implements status.Object.
156+
func (*PolicyEndpointStatus) GetLabels() map[string]string {
157+
panic("unimplemented")
158+
}
159+
160+
// GetManagedFields implements status.Object.
161+
func (*PolicyEndpointStatus) GetManagedFields() []metav1.ManagedFieldsEntry {
162+
panic("unimplemented")
163+
}
164+
165+
// GetName implements status.Object.
166+
func (*PolicyEndpointStatus) GetName() string {
167+
panic("unimplemented")
168+
}
169+
170+
// GetNamespace implements status.Object.
171+
func (*PolicyEndpointStatus) GetNamespace() string {
172+
panic("unimplemented")
173+
}
174+
175+
// GetObjectKind implements status.Object.
176+
func (*PolicyEndpointStatus) GetObjectKind() schema.ObjectKind {
177+
panic("unimplemented")
178+
}
179+
180+
// GetOwnerReferences implements status.Object.
181+
func (*PolicyEndpointStatus) GetOwnerReferences() []metav1.OwnerReference {
182+
panic("unimplemented")
183+
}
184+
185+
// GetResourceVersion implements status.Object.
186+
func (*PolicyEndpointStatus) GetResourceVersion() string {
187+
panic("unimplemented")
188+
}
189+
190+
// GetSelfLink implements status.Object.
191+
func (*PolicyEndpointStatus) GetSelfLink() string {
192+
panic("unimplemented")
193+
}
194+
195+
// GetUID implements status.Object.
196+
func (*PolicyEndpointStatus) GetUID() types.UID {
197+
panic("unimplemented")
198+
}
199+
200+
// SetAnnotations implements status.Object.
201+
func (*PolicyEndpointStatus) SetAnnotations(annotations map[string]string) {
202+
panic("unimplemented")
203+
}
204+
205+
// SetCreationTimestamp implements status.Object.
206+
func (*PolicyEndpointStatus) SetCreationTimestamp(timestamp metav1.Time) {
207+
panic("unimplemented")
208+
}
209+
210+
// SetDeletionGracePeriodSeconds implements status.Object.
211+
func (*PolicyEndpointStatus) SetDeletionGracePeriodSeconds(*int64) {
212+
panic("unimplemented")
213+
}
214+
215+
// SetDeletionTimestamp implements status.Object.
216+
func (*PolicyEndpointStatus) SetDeletionTimestamp(timestamp *metav1.Time) {
217+
panic("unimplemented")
218+
}
219+
220+
// SetFinalizers implements status.Object.
221+
func (*PolicyEndpointStatus) SetFinalizers(finalizers []string) {
222+
panic("unimplemented")
223+
}
224+
225+
// SetGenerateName implements status.Object.
226+
func (*PolicyEndpointStatus) SetGenerateName(name string) {
227+
panic("unimplemented")
228+
}
229+
230+
// SetGeneration implements status.Object.
231+
func (*PolicyEndpointStatus) SetGeneration(generation int64) {
232+
panic("unimplemented")
233+
}
234+
235+
// SetLabels implements status.Object.
236+
func (*PolicyEndpointStatus) SetLabels(labels map[string]string) {
237+
panic("unimplemented")
238+
}
239+
240+
// SetManagedFields implements status.Object.
241+
func (*PolicyEndpointStatus) SetManagedFields(managedFields []metav1.ManagedFieldsEntry) {
242+
panic("unimplemented")
243+
}
244+
245+
// SetName implements status.Object.
246+
func (*PolicyEndpointStatus) SetName(name string) {
247+
panic("unimplemented")
248+
}
249+
250+
// SetNamespace implements status.Object.
251+
func (*PolicyEndpointStatus) SetNamespace(namespace string) {
252+
panic("unimplemented")
253+
}
254+
255+
// SetOwnerReferences implements status.Object.
256+
func (*PolicyEndpointStatus) SetOwnerReferences([]metav1.OwnerReference) {
257+
panic("unimplemented")
258+
}
259+
260+
// SetResourceVersion implements status.Object.
261+
func (*PolicyEndpointStatus) SetResourceVersion(version string) {
262+
panic("unimplemented")
263+
}
264+
265+
// SetSelfLink implements status.Object.
266+
func (*PolicyEndpointStatus) SetSelfLink(selfLink string) {
267+
panic("unimplemented")
268+
}
269+
270+
// SetUID implements status.Object.
271+
func (*PolicyEndpointStatus) SetUID(uid types.UID) {
272+
panic("unimplemented")
109273
}
110274

111275
type PolicyEndpointConditionType string
@@ -115,26 +279,6 @@ const (
115279
Updated PolicyEndpointConditionType = "PatchedPolicyEndpoint"
116280
)
117281

118-
// PolicyEndpointCondition describes the state of a PolicyEndpoint at a certain point.
119-
// For example, binpacking PE slices should be updated as a condition change
120-
type PolicyEndpointCondition struct {
121-
// Type of PolicyEndpoint condition.
122-
// +optional
123-
Type PolicyEndpointConditionType `json:"type"`
124-
// Status of the condition, one of True, False, Unknown.
125-
// +optional
126-
Status corev1.ConditionStatus `json:"status"`
127-
// Last time the condition transitioned from one status to another.
128-
// +optional
129-
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
130-
// The reason for the condition's last transition.
131-
// +optional
132-
Reason string `json:"reason,omitempty"`
133-
// A human readable message indicating details about the transition.
134-
// +optional
135-
Message string `json:"message,omitempty"`
136-
}
137-
138282
//+kubebuilder:object:root=true
139283
//+kubebuilder:subresource:status
140284

@@ -159,3 +303,15 @@ type PolicyEndpointList struct {
159303
func init() {
160304
SchemeBuilder.Register(&PolicyEndpoint{}, &PolicyEndpointList{})
161305
}
306+
307+
func (s *PolicyEndpoint) GetConditions() []status.Condition {
308+
return []status.Condition(s.Status.Conditions)
309+
}
310+
311+
func (s *PolicyEndpoint) SetConditions(conds []status.Condition) {
312+
s.Status.Conditions = conds
313+
}
314+
315+
func (s *PolicyEndpoint) StatusConditions() status.ConditionSet {
316+
return status.NewReadyConditions().For(s)
317+
}

‎api/v1alpha1/zz_generated.deepcopy.go

+11-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎cmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func main() {
116116
os.Exit(1)
117117
}
118118

119-
policyEndpointsManager := policyendpoints.NewPolicyEndpointsManager(mgr.GetClient(),
119+
policyEndpointsManager := policyendpoints.NewPolicyEndpointsManager(ctx, mgr.GetClient(),
120120
controllerCFG.EndpointChunkSize, ctrl.Log.WithName("endpoints-manager"))
121121
finalizerManager := k8s.NewDefaultFinalizerManager(mgr.GetClient(), ctrl.Log.WithName("finalizer-manager"))
122122
policyController := controllers.NewPolicyReconciler(mgr.GetClient(), policyEndpointsManager,

‎config/crd/bases/networking.k8s.aws_policyendpoints.yaml

+45-10
Original file line numberDiff line numberDiff line change
@@ -232,28 +232,63 @@ spec:
232232
properties:
233233
conditions:
234234
items:
235-
description: PolicyEndpointCondition describes the state of a PolicyEndpoint
236-
at a certain point. For example, binpacking PE slices should be
237-
updated as a condition change
235+
description: Condition aliases the upstream type and adds additional
236+
helper methods
238237
properties:
239238
lastTransitionTime:
240-
description: Last time the condition transitioned from one status
241-
to another.
239+
description: lastTransitionTime is the last time the condition
240+
transitioned from one status to another. This should be when
241+
the underlying condition changed. If that is not known, then
242+
using the time when the API field changed is acceptable.
242243
format: date-time
243244
type: string
244245
message:
245-
description: A human readable message indicating details about
246-
the transition.
246+
description: message is a human readable message indicating
247+
details about the transition. This may be an empty string.
248+
maxLength: 32768
247249
type: string
250+
observedGeneration:
251+
description: observedGeneration represents the .metadata.generation
252+
that the condition was set based upon. For instance, if .metadata.generation
253+
is currently 12, but the .status.conditions[x].observedGeneration
254+
is 9, the condition is out of date with respect to the current
255+
state of the instance.
256+
format: int64
257+
minimum: 0
258+
type: integer
248259
reason:
249-
description: The reason for the condition's last transition.
260+
description: reason contains a programmatic identifier indicating
261+
the reason for the condition's last transition. Producers
262+
of specific condition types may define expected values and
263+
meanings for this field, and whether the values are considered
264+
a guaranteed API. The value should be a CamelCase string.
265+
This field may not be empty.
266+
maxLength: 1024
267+
minLength: 1
268+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
250269
type: string
251270
status:
252-
description: Status of the condition, one of True, False, Unknown.
271+
description: status of the condition, one of True, False, Unknown.
272+
enum:
273+
- "True"
274+
- "False"
275+
- Unknown
253276
type: string
254277
type:
255-
description: Type of PolicyEndpoint condition.
278+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
279+
--- Many .condition.type values are consistent across resources
280+
like Available, but because arbitrary conditions can be useful
281+
(see .node.status.conditions), the ability to deconflict is
282+
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
283+
maxLength: 316
284+
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])$
256285
type: string
286+
required:
287+
- lastTransitionTime
288+
- message
289+
- reason
290+
- status
291+
- type
257292
type: object
258293
type: array
259294
type: object

‎go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
)
2222

2323
require (
24+
github.com/awslabs/operatorpkg v0.0.0-20231211224023-fce5f0fa8592
2425
github.com/beorn7/perks v1.0.1 // indirect
2526
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2627
github.com/davecgh/go-spew v1.1.1 // indirect

‎go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/awslabs/operatorpkg v0.0.0-20231211224023-fce5f0fa8592 h1:LSaLHzJ4IMZZLgVIx/2YIcvUCIAaE5OqLhjWzdwF060=
2+
github.com/awslabs/operatorpkg v0.0.0-20231211224023-fce5f0fa8592/go.mod h1:kqgbtyanB/ObfvsSUdGZOk1f3K807kvoibKoKX0wMK4=
13
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
24
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
35
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=

0 commit comments

Comments
 (0)
Failed to load comments.