Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Create HierarchicalNamespace CRD
Browse files Browse the repository at this point in the history
This CRD is created as the UX of the HNC self-service namespace. See
design at http://bit.ly/hnc-self-serve-ux.

Tested on a GKE cluster by "kubectl apply -f" the generated CRD yaml
file. The CRD was created with success.
  • Loading branch information
yiqigao217 committed Feb 25, 2020
1 parent 95218a0 commit 253fb42
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 0 deletions.
78 changes: 78 additions & 0 deletions incubator/hnc/api/v1alpha1/hierarchical_namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// HNSState describes the state of a hierarchical namespace. The state could be
// "missing", "ok" or "conflict". The definitions will be described below.
type HNSState string

// HNSStates, which are documented in the comment to HierarchicalNamespaceStatus.State.
const (
// Missing means the child namespace has not been created yet. This should be the default
// state when the HNS is just created.
Missing HNSState = "missing"

// Ok means the child namespace exists.
Ok HNSState = "ok"

// Conflict means a namespace of the same name already exists.
Conflict HNSState = "conflict"
)

// HierarchicalNamespaceStatus defines the observed state of HierarchicalNamespace.
type HierarchicalNamespaceStatus struct {
// Describes the state of a hierarchical namespace.
//
// Currently, the supported values are:
//
// - "missing": the child namespace has not been created yet. This should be the default
// state when the HNS is just created.
//
// - "ok": the child namespace exists.
//
// - "conflict": a namespace of the same name already exists. If the validation webhook
// works properly, this should never happen since the HNS won't be created at the first place.
State HNSState `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=hierarchicalnamespaces,shortName=hns,scope=Namespaced

// HierarchicalNamespace is the Schema for the self-service namespace API.
// See details at http://bit.ly/hnc-self-serve-ux.
type HierarchicalNamespace struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status HierarchicalNamespaceStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// HierarchicalNamespaceList contains a list of HierarchicalNamespace.
type HierarchicalNamespaceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []HierarchicalNamespace `json:"items"`
}

func init() {
SchemeBuilder.Register(&HierarchicalNamespace{}, &HierarchicalNamespaceList{})
}
73 changes: 73 additions & 0 deletions incubator/hnc/api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
creationTimestamp: null
name: hierarchicalnamespaces.hnc.x-k8s.io
spec:
group: hnc.x-k8s.io
names:
kind: HierarchicalNamespace
listKind: HierarchicalNamespaceList
plural: hierarchicalnamespaces
shortNames:
- hns
singular: hierarchicalnamespace
scope: Namespaced
validation:
openAPIV3Schema:
description: HierarchicalNamespace is the Schema for the self-service namespace
API. See details at http://bit.ly/hnc-self-serve-ux.
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.io/community/contributors/devel/api-conventions.md#resources'
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.io/community/contributors/devel/api-conventions.md#types-kinds'
type: string
metadata:
type: object
status:
description: HierarchicalNamespaceStatus defines the observed state of HierarchicalNamespace.
properties:
status:
description: "Describes the state of a hierarchical namespace. \n Currently,
the supported values are: \n - \"missing\": the child namespace has
not been created yet. This should be the default state when the HNS
is just created. \n - \"ok\": the child namespace exists. \n - \"conflict\":
a namespace of the same name already exists. If the validation webhook
works properly, this should never happen since the HNS won't be created
at the first place."
type: string
type: object
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

0 comments on commit 253fb42

Please sign in to comment.