Skip to content

Commit

Permalink
using awslab package to manage conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
haouc committed Jan 26, 2024
1 parent 63d44d0 commit d24d234
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 47 deletions.
198 changes: 177 additions & 21 deletions api/v1alpha1/policyendpoint_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ limitations under the License.
package v1alpha1

import (
"github.com/awslabs/operatorpkg/status"
corev1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
)

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

// +optional
Conditions []PolicyEndpointCondition `json:"conditions,omitempty"`
Conditions []status.Condition `json:"conditions,omitempty"`
}

// DeepCopyObject implements status.Object.
func (*PolicyEndpointStatus) DeepCopyObject() runtime.Object {
panic("unimplemented")
}

// GetAnnotations implements status.Object.
func (*PolicyEndpointStatus) GetAnnotations() map[string]string {
panic("unimplemented")
}

// GetCreationTimestamp implements status.Object.
func (*PolicyEndpointStatus) GetCreationTimestamp() metav1.Time {
panic("unimplemented")
}

// GetDeletionGracePeriodSeconds implements status.Object.
func (*PolicyEndpointStatus) GetDeletionGracePeriodSeconds() *int64 {
panic("unimplemented")
}

// GetDeletionTimestamp implements status.Object.
func (*PolicyEndpointStatus) GetDeletionTimestamp() *metav1.Time {
panic("unimplemented")
}

// GetFinalizers implements status.Object.
func (*PolicyEndpointStatus) GetFinalizers() []string {
panic("unimplemented")
}

// GetGenerateName implements status.Object.
func (*PolicyEndpointStatus) GetGenerateName() string {
panic("unimplemented")
}

// GetGeneration implements status.Object.
func (*PolicyEndpointStatus) GetGeneration() int64 {
panic("unimplemented")
}

// GetLabels implements status.Object.
func (*PolicyEndpointStatus) GetLabels() map[string]string {
panic("unimplemented")
}

// GetManagedFields implements status.Object.
func (*PolicyEndpointStatus) GetManagedFields() []metav1.ManagedFieldsEntry {
panic("unimplemented")
}

// GetName implements status.Object.
func (*PolicyEndpointStatus) GetName() string {
panic("unimplemented")
}

// GetNamespace implements status.Object.
func (*PolicyEndpointStatus) GetNamespace() string {
panic("unimplemented")
}

// GetObjectKind implements status.Object.
func (*PolicyEndpointStatus) GetObjectKind() schema.ObjectKind {
panic("unimplemented")
}

// GetOwnerReferences implements status.Object.
func (*PolicyEndpointStatus) GetOwnerReferences() []metav1.OwnerReference {
panic("unimplemented")
}

// GetResourceVersion implements status.Object.
func (*PolicyEndpointStatus) GetResourceVersion() string {
panic("unimplemented")
}

// GetSelfLink implements status.Object.
func (*PolicyEndpointStatus) GetSelfLink() string {
panic("unimplemented")
}

// GetUID implements status.Object.
func (*PolicyEndpointStatus) GetUID() types.UID {
panic("unimplemented")
}

// SetAnnotations implements status.Object.
func (*PolicyEndpointStatus) SetAnnotations(annotations map[string]string) {
panic("unimplemented")
}

// SetCreationTimestamp implements status.Object.
func (*PolicyEndpointStatus) SetCreationTimestamp(timestamp metav1.Time) {
panic("unimplemented")
}

// SetDeletionGracePeriodSeconds implements status.Object.
func (*PolicyEndpointStatus) SetDeletionGracePeriodSeconds(*int64) {
panic("unimplemented")
}

// SetDeletionTimestamp implements status.Object.
func (*PolicyEndpointStatus) SetDeletionTimestamp(timestamp *metav1.Time) {
panic("unimplemented")
}

// SetFinalizers implements status.Object.
func (*PolicyEndpointStatus) SetFinalizers(finalizers []string) {
panic("unimplemented")
}

// SetGenerateName implements status.Object.
func (*PolicyEndpointStatus) SetGenerateName(name string) {
panic("unimplemented")
}

// SetGeneration implements status.Object.
func (*PolicyEndpointStatus) SetGeneration(generation int64) {
panic("unimplemented")
}

// SetLabels implements status.Object.
func (*PolicyEndpointStatus) SetLabels(labels map[string]string) {
panic("unimplemented")
}

// SetManagedFields implements status.Object.
func (*PolicyEndpointStatus) SetManagedFields(managedFields []metav1.ManagedFieldsEntry) {
panic("unimplemented")
}

// SetName implements status.Object.
func (*PolicyEndpointStatus) SetName(name string) {
panic("unimplemented")
}

// SetNamespace implements status.Object.
func (*PolicyEndpointStatus) SetNamespace(namespace string) {
panic("unimplemented")
}

// SetOwnerReferences implements status.Object.
func (*PolicyEndpointStatus) SetOwnerReferences([]metav1.OwnerReference) {
panic("unimplemented")
}

// SetResourceVersion implements status.Object.
func (*PolicyEndpointStatus) SetResourceVersion(version string) {
panic("unimplemented")
}

// SetSelfLink implements status.Object.
func (*PolicyEndpointStatus) SetSelfLink(selfLink string) {
panic("unimplemented")
}

// SetUID implements status.Object.
func (*PolicyEndpointStatus) SetUID(uid types.UID) {
panic("unimplemented")
}

type PolicyEndpointConditionType string
Expand All @@ -115,26 +279,6 @@ const (
Updated PolicyEndpointConditionType = "PatchedPolicyEndpoint"
)

// PolicyEndpointCondition describes the state of a PolicyEndpoint at a certain point.
// For example, binpacking PE slices should be updated as a condition change
type PolicyEndpointCondition struct {
// Type of PolicyEndpoint condition.
// +optional
Type PolicyEndpointConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
// +optional
Status corev1.ConditionStatus `json:"status"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand All @@ -159,3 +303,15 @@ type PolicyEndpointList struct {
func init() {
SchemeBuilder.Register(&PolicyEndpoint{}, &PolicyEndpointList{})
}

func (s *PolicyEndpoint) GetConditions() []status.Condition {
return []status.Condition(s.Status.Conditions)
}

func (s *PolicyEndpoint) SetConditions(conds []status.Condition) {
s.Status.Conditions = conds
}

func (s *PolicyEndpoint) StatusConditions() status.ConditionSet {
return status.NewReadyConditions().For(s)
}
14 changes: 11 additions & 3 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func main() {
os.Exit(1)
}

policyEndpointsManager := policyendpoints.NewPolicyEndpointsManager(mgr.GetClient(),
policyEndpointsManager := policyendpoints.NewPolicyEndpointsManager(ctx, mgr.GetClient(),
controllerCFG.EndpointChunkSize, ctrl.Log.WithName("endpoints-manager"))
finalizerManager := k8s.NewDefaultFinalizerManager(mgr.GetClient(), ctrl.Log.WithName("finalizer-manager"))
policyController := controllers.NewPolicyReconciler(mgr.GetClient(), policyEndpointsManager,
Expand Down
55 changes: 45 additions & 10 deletions config/crd/bases/networking.k8s.aws_policyendpoints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,63 @@ spec:
properties:
conditions:
items:
description: PolicyEndpointCondition describes the state of a PolicyEndpoint
at a certain point. For example, binpacking PE slices should be
updated as a condition change
description: Condition aliases the upstream type and adds additional
helper methods
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
description: lastTransitionTime is the last time the condition
transitioned from one status to another. This should be when
the underlying condition changed. If that is not known, then
using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
description: message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation
that the condition was set based upon. For instance, if .metadata.generation
is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current
state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: The reason for the condition's last transition.
description: reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values and
meanings for this field, and whether the values are considered
a guaranteed API. The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: Status of the condition, one of True, False, Unknown.
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: Type of PolicyEndpoint condition.
description: type of condition in CamelCase or in foo.example.com/CamelCase.
--- Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
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])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
type: object
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
)

require (
github.com/awslabs/operatorpkg v0.0.0-20231211224023-fce5f0fa8592
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/awslabs/operatorpkg v0.0.0-20231211224023-fce5f0fa8592 h1:LSaLHzJ4IMZZLgVIx/2YIcvUCIAaE5OqLhjWzdwF060=
github.com/awslabs/operatorpkg v0.0.0-20231211224023-fce5f0fa8592/go.mod h1:kqgbtyanB/ObfvsSUdGZOk1f3K807kvoibKoKX0wMK4=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
Loading

0 comments on commit d24d234

Please sign in to comment.