Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #28 from charleszheng44/feature/nestedetcd
Browse files Browse the repository at this point in the history
Add the scaffolding code for NestedEtcd
  • Loading branch information
k8s-ci-robot authored Jan 22, 2021
2 parents 864ee02 + 83f008b commit f22df4e
Show file tree
Hide file tree
Showing 18 changed files with 720 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ generate-go: ## Runs Go related generate targets
go generate ./...
$(CONTROLLER_GEN) \
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
paths=./api/...
paths=./apis/...

.PHONY: generate-manifests
generate-manifests: ## Generate manifests e.g. CRD, RBAC etc.
$(CONTROLLER_GEN) \
paths=./api/... \
paths=./apis/... \
paths=./controllers/... \
crd:crdVersions=v1 \
rbac:roleName=manager-role \
Expand Down
7 changes: 6 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
domain: cluster.x-k8s.io
layout: go.kubebuilder.io/v3
projectName: cluster-api-provider-nested
multigroup: true
projectName: cluster-api-provider-nested
repo: sigs.k8s.io/cluster-api-provider-nested
resources:
- group: controlplane
kind: NestedControlPlane
version: v1alpha4
- api:
crdVersion: v1
group: controlplane
kind: NestedEtcd
version: v1alpha4
version: 3-alpha
40 changes: 40 additions & 0 deletions apis/controlplane/v1alpha4/nestedcomponentspec_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2021 The Kubernetes Authors.
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 v1alpha4

import (
corev1 "k8s.io/api/core/v1"
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
)

type NestedComponentSpec struct {
// NestedComponentSpec defines the common information for creating the component
// +optional
addonv1alpha1.CommonSpec `json:",inline"`

// PatchSpecs includes the user specifed settings
// +optional
addonv1alpha1.PatchSpec `json:",inline"`

// Resources defines the amount of computing resources that will be used by this component
// +optional
Resources corev1.ResourceRequirements `json:"resources",omitempty`

// Replicas defines the number of replicas in the component's workload
// +optional
Replicas int32 `json:"replicas",omitempty`
}
81 changes: 81 additions & 0 deletions apis/controlplane/v1alpha4/nestedetcd_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright 2021 The Kubernetes Authors.
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 v1alpha4

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
)

// NestedEtcdSpec defines the desired state of NestedEtcd
type NestedEtcdSpec struct {
// NestedComponentSpec contains the common and user-specified information that are
// required for creating the component
// +optional
NestedComponentSpec `json:",inline"`
}

// NestedEtcdStatus defines the observed state of NestedEtcd
type NestedEtcdStatus struct {
// Ready is set if all resources have been created
Ready bool `json:"ready,omitempty"`

// EtcdDomain defines how to address the etcd instance
Addresses []NestedEtcdAddress `json:"addresses,omitempty"`

// CommonStatus allows addons status monitoring
addonv1alpha1.CommonStatus `json:",inline"`
}

// EtcdAddress defines the observed addresses for etcd
type NestedEtcdAddress struct {
// IP Address of the etcd instance.
// +optional
IP string `json:"ip,omitempty"`

// Hostname of the etcd instance
Hostname string `json:"hostname,omitempty"`

// Port of the etcd instance
// +optional
Port int32 `json:"port"`
}

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

// NestedEtcd is the Schema for the nestedetcds API
type NestedEtcd struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NestedEtcdSpec `json:"spec,omitempty"`
Status NestedEtcdStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&NestedEtcd{}, &NestedEtcdList{})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1-0.20201002000720-57250aac17f6
creationTimestamp: null
name: nestedcontrolplanes.controlplane.cluster.x-k8s.io
spec:
group: controlplane.cluster.x-k8s.io
names:
kind: NestedControlPlane
listKind: NestedControlPlaneList
plural: nestedcontrolplanes
singular: nestedcontrolplane
scope: Namespaced
versions:
- name: v1alpha4
schema:
openAPIV3Schema:
description: NestedControlPlane is the Schema for the nestedcontrolplanes 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.io/community/contributors/devel/sig-architecture/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/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: NestedControlPlaneSpec defines the desired state of NestedControlPlane
properties:
foo:
description: Foo is an example field of NestedControlPlane. Edit NestedControlPlane_types.go to remove/update
type: string
type: object
status:
description: NestedControlPlaneStatus defines the observed state of NestedControlPlane
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
116 changes: 116 additions & 0 deletions config/crd/bases/controlplane.cluster.x-k8s.io_nestedetcds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1-0.20201002000720-57250aac17f6
creationTimestamp: null
name: nestedetcds.controlplane.cluster.x-k8s.io
spec:
group: controlplane.cluster.x-k8s.io
names:
kind: NestedEtcd
listKind: NestedEtcdList
plural: nestedetcds
singular: nestedetcd
scope: Namespaced
versions:
- name: v1alpha4
schema:
openAPIV3Schema:
description: NestedEtcd is the Schema for the nestedetcds 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.io/community/contributors/devel/sig-architecture/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/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: NestedEtcdSpec defines the desired state of NestedEtcd
properties:
channel:
description: 'Channel specifies a channel that can be used to resolve a specific addon, eg: stable It will be ignored if Version is specified'
type: string
patches:
items:
type: object
type: array
replicas:
description: Replicas defines the number of replicas in the component's workload
format: int32
type: integer
resources:
description: Resources defines the amount of computing resources that will be used by this component
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
version:
description: Version specifies the exact addon version to be deployed, eg 1.2.3 It should not be specified if Channel is specified
type: string
type: object
status:
description: NestedEtcdStatus defines the observed state of NestedEtcd
properties:
addresses:
description: EtcdDomain defines how to address the etcd instance
items:
description: EtcdAddress defines the observed addresses for etcd
properties:
hostname:
description: Hostname of the etcd instance
type: string
ip:
description: IP Address of the etcd instance.
type: string
port:
description: Port of the etcd instance
format: int32
type: integer
type: object
type: array
errors:
items:
type: string
type: array
healthy:
type: boolean
phase:
type: string
ready:
description: Ready is set if all resources have been created
type: boolean
required:
- healthy
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
# It should be run by config/default
resources:
- bases/controlplane.cluster.x-k8s.io_nestedcontrolplanes.yaml
- bases/controlplane.cluster.x-k8s.io_nestedetcds.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_nestedcontrolplanes.yaml
#- patches/webhook_in_nestedetcds.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_nestedcontrolplanes.yaml
#- patches/cainjection_in_nestedetcds.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_nestedetcds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: nestedetcds.controlplane.cluster.x-k8s.io
14 changes: 14 additions & 0 deletions config/crd/patches/webhook_in_nestedetcds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: nestedetcds.controlplane.cluster.x-k8s.io
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
24 changes: 24 additions & 0 deletions config/rbac/nestedetcd_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# permissions for end users to edit nestedetcds.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: nestedetcd-editor-role
rules:
- apiGroups:
- controlplane.cluster.x-k8s.io
resources:
- nestedetcds
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- controlplane.cluster.x-k8s.io
resources:
- nestedetcds/status
verbs:
- get
Loading

0 comments on commit f22df4e

Please sign in to comment.