forked from kubernetes-retired/multi-tenancy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define HNCConfiguration CR and set up a reconciler for the CR.
This commit implements HNC type configuration by creating HNCConfiguration CR and setting up a corresponding reconciler for it. Specifically, it does the following: - Implements the Go structs for HNCConfiguration and generates corresponding yaml files by running "make manifests". - Creates a basic reconciler for HNCConfiguration and configures it in setup.go. The reconciler does the following: - Creates a default singleton if it does not exist. - Writes or updates the singleton on the apiserver. - Logs the Spec of the HNCConfiguration when a reconciliation happens. Tested: - Verified that the CRD were created correctly. - Created a sample HNCConfiguration and applied to KIND. - Verified the logs are expected on a GKE cluster during a reconciliation. Design doc: http://bit.ly/hnc-type-configuration Issue: kubernetes-retired#411
- Loading branch information
1 parent
fe9fd06
commit 7ab6c83
Showing
9 changed files
with
487 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
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" | ||
) | ||
|
||
// Constants for types and well-known names. | ||
const ( | ||
HNCConfigSingleton = "config" | ||
) | ||
|
||
// SynchronizationMode describes propogation mode of objects of the same kind. | ||
// The only three modes currently supported are "propagate", "ignore", and "remove". | ||
// See detailed definition below. An unsupported mode will be treated as "ignore". | ||
type SynchronizationMode string | ||
|
||
const ( | ||
// Propagate objects from ancestors to descendants and deletes obsolete descendants. | ||
Propagate SynchronizationMode = "propagate" | ||
|
||
// Ignore the modification of this type. New or changed objects will not be propagated, | ||
// and obsolete objects will not be deleted. The inheritedFrom label is not removed. | ||
// Any unknown mode is treated as ignore. | ||
Ignore SynchronizationMode = "ignore" | ||
|
||
// Remove all existing propagated copies. | ||
Remove SynchronizationMode = "remove" | ||
) | ||
|
||
// TypeSynchronizationSpec defines the desired synchronization state of a specific kind. | ||
type TypeSynchronizationSpec struct { | ||
// API version of the kind defined below. This is used to unambiguously identifies the kind. | ||
APIVersion string `json:"apiVersion,omitempty"` | ||
// Kind to be configured. | ||
Kind string `json:"kind,omitempty"` | ||
// Synchronization mode of the kind. | ||
// +optional | ||
Mode SynchronizationMode `json:"mode,omitempty"` | ||
} | ||
|
||
// TypeSynchronizationStatus defines the observed synchronization state of a specific kind. | ||
type TypeSynchronizationStatus struct { | ||
// API version of the kind defined below. This is used to unambiguously identifies the kind. | ||
APIVersion string `json:"apiVersion,omitempty"` | ||
// Kind to be configured. | ||
Kind string `json:"kind,omitempty"` | ||
|
||
// Tracks the number of original objects that are being propagated to descendant namespaces. | ||
// +kubebuilder:validation:Minimum=0 | ||
// +optional | ||
NumPropagated *int32 `json:"numPropagated,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:path=hncconfigurations,scope=Cluster | ||
|
||
// HNCConfiguration is a cluster-wide configuration for HNC as a whole. See details in http://bit.ly/hnc-type-configuration | ||
type HNCConfiguration struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec HNCConfigurationSpec `json:"spec,omitempty"` | ||
Status HNCConfigurationStatus `json:"status,omitempty"` | ||
} | ||
|
||
// HNCConfigurationSpec defines the desired state of HNC configuration. | ||
type HNCConfigurationSpec struct { | ||
// Types indicates the desired synchronization states of kinds, if any. | ||
Types []TypeSynchronizationSpec `json:"types,omitempty"` | ||
} | ||
|
||
// HNCConfigurationStatus defines the observed state of HNC configuration. | ||
type HNCConfigurationStatus struct { | ||
// Types indicates the observed synchronization states of kinds, if any. | ||
Types []TypeSynchronizationStatus `json:"types,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// HNCConfigurationList contains a list of HNCConfiguration. | ||
type HNCConfigurationList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []HNCConfiguration `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&HNCConfiguration{}, &HNCConfigurationList{}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
incubator/hnc/config/crd/bases/hnc.x-k8s.io_hncconfigurations.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
|
||
--- | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.2.4 | ||
creationTimestamp: null | ||
name: hncconfigurations.hnc.x-k8s.io | ||
spec: | ||
group: hnc.x-k8s.io | ||
names: | ||
kind: HNCConfiguration | ||
listKind: HNCConfigurationList | ||
plural: hncconfigurations | ||
singular: hncconfiguration | ||
scope: Cluster | ||
validation: | ||
openAPIV3Schema: | ||
description: HNCConfiguration is a cluster-wide configuration for HNC as a whole. | ||
See details in http://bit.ly/hnc-type-configuration | ||
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 | ||
spec: | ||
description: HNCConfigurationSpec defines the desired state of HNC configuration. | ||
properties: | ||
types: | ||
description: Types indicates the desired synchronization states of kinds, | ||
if any. | ||
items: | ||
description: TypeSynchronizationSpec defines the desired synchronization | ||
state of a specific kind. | ||
properties: | ||
apiVersion: | ||
description: API version of the kind defined below. This is used | ||
to unambiguously identifies the kind. | ||
type: string | ||
kind: | ||
description: Kind to be configured. | ||
type: string | ||
mode: | ||
description: Synchronization mode of the kind. | ||
type: string | ||
type: object | ||
type: array | ||
type: object | ||
status: | ||
description: HNCConfigurationStatus defines the observed state of HNC configuration. | ||
properties: | ||
types: | ||
description: Types indicates the observed synchronization states of | ||
kinds, if any. | ||
items: | ||
description: TypeSynchronizationStatus defines the observed synchronization | ||
state of a specific kind. | ||
properties: | ||
apiVersion: | ||
description: API version of the kind defined below. This is used | ||
to unambiguously identifies the kind. | ||
type: string | ||
kind: | ||
description: Kind to be configured. | ||
type: string | ||
numPropagated: | ||
description: Tracks the number of original objects that are being | ||
propagated to descendant namespaces. | ||
format: int32 | ||
minimum: 0 | ||
type: integer | ||
type: object | ||
type: array | ||
type: object | ||
type: object | ||
version: v1alpha1 | ||
versions: | ||
- name: v1alpha1 | ||
served: true | ||
storage: true | ||
status: | ||
acceptedNames: | ||
kind: "" | ||
plural: "" | ||
conditions: [] | ||
storedVersions: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: hnc.x-k8s.io/v1alpha1 | ||
kind: HNCConfiguration | ||
metadata: | ||
name: config | ||
spec: | ||
types: | ||
- apiVersion: v1 | ||
kind: Secret | ||
mode: propagate | ||
- apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
mode: ignore |
Oops, something went wrong.