From 6d4b47ef2b6fa600205fb13a65313a065d04ba3b Mon Sep 17 00:00:00 2001 From: Erik Godding Boye Date: Sat, 14 Oct 2023 15:17:43 +0200 Subject: [PATCH] feat: make SubNamespace compatible with kstatus --- api/v1/subnamespace_types.go | 1 + api/v2alpha1/groupversion_info.go | 20 +++ api/v2alpha1/subnamespace_types.go | 64 +++++++++ api/v2alpha1/zz_generated.deepcopy.go | 121 ++++++++++++++++++ .../accurate.cybozu.com_subnamespaces.yaml | 87 +++++++++++++ .../accurate.cybozu.com_subnamespaces.yaml | 104 +++++++++++++++ 6 files changed, 397 insertions(+) create mode 100644 api/v2alpha1/groupversion_info.go create mode 100644 api/v2alpha1/subnamespace_types.go create mode 100644 api/v2alpha1/zz_generated.deepcopy.go diff --git a/api/v1/subnamespace_types.go b/api/v1/subnamespace_types.go index 0ef252f..ac083e7 100644 --- a/api/v1/subnamespace_types.go +++ b/api/v1/subnamespace_types.go @@ -28,6 +28,7 @@ type SubNamespaceSpec struct { } //+kubebuilder:object:root=true +//+kubebuilder:storageversion // SubNamespace is the Schema for the subnamespaces API type SubNamespace struct { diff --git a/api/v2alpha1/groupversion_info.go b/api/v2alpha1/groupversion_info.go new file mode 100644 index 0000000..7a34e5d --- /dev/null +++ b/api/v2alpha1/groupversion_info.go @@ -0,0 +1,20 @@ +// Package v2alpha1 contains API Schema definitions for the accurate v2alpha1 API group +// +kubebuilder:object:generate=true +// +groupName=accurate.cybozu.com +package v2alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "accurate.cybozu.com", Version: "v2alpha1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/api/v2alpha1/subnamespace_types.go b/api/v2alpha1/subnamespace_types.go new file mode 100644 index 0000000..e899a2e --- /dev/null +++ b/api/v2alpha1/subnamespace_types.go @@ -0,0 +1,64 @@ +package v2alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// SubNamespaceStatus defines the observed state of SubNamespace +type SubNamespaceStatus struct { + // The generation observed by the object controller. + // +optional + ObservedGeneration int64 `json:"observedGeneration,omitempty"` + + // Conditions represent the latest available observations of an object's state + // +listType=map + // +listMapKey=type + // +optional + Conditions []metav1.Condition `json:"conditions,omitempty"` +} + +// SubNamespaceSpec defines the desired state of SubNamespace +type SubNamespaceSpec struct { + // Labels are the labels to be propagated to the sub-namespace + // +optional + Labels map[string]string `json:"labels,omitempty"` + + // Annotations are the annotations to be propagated to the sub-namespace. + // +optional + Annotations map[string]string `json:"annotations,omitempty"` +} + +// Keeping this version un-served for now +//+kubebuilder:unservedversion +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// SubNamespace is the Schema for the subnamespaces API +type SubNamespace struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec is the spec of SubNamespace. + // +optional + Spec SubNamespaceSpec `json:"spec,omitempty"` + + // Status is the status of SubNamespace. + // +optional + Status SubNamespaceStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// SubNamespaceList contains a list of SubNamespace +type SubNamespaceList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []SubNamespace `json:"items"` +} + +func init() { + SchemeBuilder.Register(&SubNamespace{}, &SubNamespaceList{}) +} diff --git a/api/v2alpha1/zz_generated.deepcopy.go b/api/v2alpha1/zz_generated.deepcopy.go new file mode 100644 index 0000000..fa1b1cb --- /dev/null +++ b/api/v2alpha1/zz_generated.deepcopy.go @@ -0,0 +1,121 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package v2alpha1 + +import ( + "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubNamespace) DeepCopyInto(out *SubNamespace) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubNamespace. +func (in *SubNamespace) DeepCopy() *SubNamespace { + if in == nil { + return nil + } + out := new(SubNamespace) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SubNamespace) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubNamespaceList) DeepCopyInto(out *SubNamespaceList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]SubNamespace, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubNamespaceList. +func (in *SubNamespaceList) DeepCopy() *SubNamespaceList { + if in == nil { + return nil + } + out := new(SubNamespaceList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SubNamespaceList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubNamespaceSpec) DeepCopyInto(out *SubNamespaceSpec) { + *out = *in + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubNamespaceSpec. +func (in *SubNamespaceSpec) DeepCopy() *SubNamespaceSpec { + if in == nil { + return nil + } + out := new(SubNamespaceSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubNamespaceStatus) DeepCopyInto(out *SubNamespaceStatus) { + *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]v1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubNamespaceStatus. +func (in *SubNamespaceStatus) DeepCopy() *SubNamespaceStatus { + if in == nil { + return nil + } + out := new(SubNamespaceStatus) + in.DeepCopyInto(out) + return out +} diff --git a/charts/accurate/crds/accurate.cybozu.com_subnamespaces.yaml b/charts/accurate/crds/accurate.cybozu.com_subnamespaces.yaml index 42c1790..5a72b20 100644 --- a/charts/accurate/crds/accurate.cybozu.com_subnamespaces.yaml +++ b/charts/accurate/crds/accurate.cybozu.com_subnamespaces.yaml @@ -51,3 +51,90 @@ spec: type: object served: true storage: true + - name: v2alpha1 + schema: + openAPIV3Schema: + description: SubNamespace is the Schema for the subnamespaces API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.' + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.' + type: string + metadata: + type: object + spec: + description: Spec is the spec of SubNamespace. + properties: + annotations: + additionalProperties: + type: string + description: Annotations are the annotations to be propagated to the sub-namespace. + type: object + labels: + additionalProperties: + type: string + description: Labels are the labels to be propagated to the sub-namespace + type: object + type: object + status: + description: Status is the status of SubNamespace. + properties: + conditions: + description: Conditions represent the latest available observations of an object's state + items: + description: Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct use as an array at the field path .status.conditions. + properties: + lastTransitionTime: + description: lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. + format: date-time + type: string + message: + 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]. + format: int64 + minimum: 0 + type: integer + reason: + description: reason contains a programmatic identifier indicating the reason for the condition's last transition. + 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. + enum: + - "True" + - "False" + - Unknown + type: string + type: + 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. + 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 + x-kubernetes-list-map-keys: + - type + x-kubernetes-list-type: map + observedGeneration: + description: The generation observed by the object controller. + format: int64 + type: integer + type: object + type: object + served: false + storage: false + subresources: + status: {} diff --git a/config/crd/bases/accurate.cybozu.com_subnamespaces.yaml b/config/crd/bases/accurate.cybozu.com_subnamespaces.yaml index 02de17b..34dfb01 100644 --- a/config/crd/bases/accurate.cybozu.com_subnamespaces.yaml +++ b/config/crd/bases/accurate.cybozu.com_subnamespaces.yaml @@ -55,3 +55,107 @@ spec: type: object served: true storage: true + - name: v2alpha1 + schema: + openAPIV3Schema: + description: SubNamespace is the Schema for the subnamespaces API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.' + type: string + metadata: + type: object + spec: + description: Spec is the spec of SubNamespace. + properties: + annotations: + additionalProperties: + type: string + description: Annotations are the annotations to be propagated to the + sub-namespace. + type: object + labels: + additionalProperties: + type: string + description: Labels are the labels to be propagated to the sub-namespace + type: object + type: object + status: + description: Status is the status of SubNamespace. + properties: + conditions: + description: Conditions represent the latest available observations + of an object's state + items: + description: Condition contains details for one aspect of the current + state of this API Resource. --- This struct is intended for direct + use as an array at the field path .status.conditions. + properties: + lastTransitionTime: + description: lastTransitionTime is the last time the condition + transitioned from one status to another. This should be when + the underlying condition changed. + format: date-time + type: string + message: + 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]. + format: int64 + minimum: 0 + type: integer + reason: + description: reason contains a programmatic identifier indicating + the reason for the condition's last transition. + 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. + enum: + - "True" + - "False" + - Unknown + type: string + type: + 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. + 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 + x-kubernetes-list-map-keys: + - type + x-kubernetes-list-type: map + observedGeneration: + description: The generation observed by the object controller. + format: int64 + type: integer + type: object + type: object + served: false + storage: false + subresources: + status: {}