Skip to content

Commit

Permalink
feat: make SubNamespace compatible with kstatus
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Oct 14, 2023
1 parent 1cc371d commit 7828c33
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v1/subnamespace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type SubNamespaceSpec struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:storageversion

// SubNamespace is the Schema for the subnamespaces API
type SubNamespace struct {
Expand Down
20 changes: 20 additions & 0 deletions api/v2alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -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
)
64 changes: 64 additions & 0 deletions api/v2alpha1/subnamespace_types.go
Original file line number Diff line number Diff line change
@@ -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{})
}
97 changes: 97 additions & 0 deletions api/v2alpha1/zz_generated.deepcopy.go

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

87 changes: 87 additions & 0 deletions charts/accurate/crds/accurate.cybozu.com_subnamespaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
104 changes: 104 additions & 0 deletions config/crd/bases/accurate.cybozu.com_subnamespaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

0 comments on commit 7828c33

Please sign in to comment.