Skip to content

Commit

Permalink
CAPD: add DockerClusterTemplate type
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuvaraj Kakaraparthi committed Jul 9, 2021
1 parent 37c862b commit 3b95493
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/infrastructure/docker/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ resources:
- group: infrastructure
version: v1alpha4
kind: DockerMachinePool
- group: infrastructure
kind: DockerClusterTemplate
version: v1alpha4
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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"
)

// DockerClusterTemplateSpec defines the desired state of DockerClusterTemplate.
type DockerClusterTemplateSpec struct {
Template DockerClusterTemplateResource `json:"template"`
}

//+kubebuilder:object:root=true

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

Spec DockerClusterTemplateSpec `json:"spec,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:resource:path=dockerclustertemplates,scope=Namespaced,categories=cluster-api

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

func init() {
SchemeBuilder.Register(&DockerClusterTemplate{}, &DockerClusterTemplateList{})
}

// DockerClusterTemplateResource describes the data needed to create a DockerCluster from a template.
type DockerClusterTemplateResource struct {
Spec DockerClusterSpec `json:"spec"`
}
90 changes: 90 additions & 0 deletions test/infrastructure/docker/api/v1alpha4/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,103 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
creationTimestamp: null
name: dockerclustertemplates.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
names:
kind: DockerClusterTemplate
listKind: DockerClusterTemplateList
plural: dockerclustertemplates
singular: dockerclustertemplate
scope: Namespaced
versions:
- name: v1alpha4
schema:
openAPIV3Schema:
description: DockerClusterTemplate is the Schema for the dockerclustertemplates
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: DockerClusterTemplateSpec defines the desired state of DockerClusterTemplate.
properties:
template:
description: DockerClusterTemplateResource describes the data needed
to create a DockerCluster from a template.
properties:
spec:
description: DockerClusterSpec defines the desired state of DockerCluster.
properties:
controlPlaneEndpoint:
description: ControlPlaneEndpoint represents the endpoint
used to communicate with the control plane.
properties:
host:
description: Host is the hostname on which the API server
is serving.
type: string
port:
description: Port is the port on which the API server
is serving.
type: integer
required:
- host
- port
type: object
failureDomains:
additionalProperties:
description: FailureDomainSpec is the Schema for Cluster
API failure domains. It allows controllers to understand
how many failure domains a cluster can optionally span
across.
properties:
attributes:
additionalProperties:
type: string
description: Attributes is a free form map of attributes
an infrastructure provider might use or require.
type: object
controlPlane:
description: ControlPlane determines if this failure
domain is suitable for use by control plane machines.
type: boolean
type: object
description: FailureDomains are not usulaly defined on the
spec. The docker provider is special since failure domains
don't mean anything in a local docker environment. Instead,
the docker cluster controller will simply copy these into
the Status and allow the Cluster API controllers to do what
they will with the defined failure domains.
type: object
type: object
required:
- spec
type: object
required:
- template
type: object
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
3 changes: 3 additions & 0 deletions test/infrastructure/docker/config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ resources:
- bases/infrastructure.cluster.x-k8s.io_dockerclusters.yaml
- bases/infrastructure.cluster.x-k8s.io_dockermachinetemplates.yaml
- bases/infrastructure.cluster.x-k8s.io_dockermachinepools.yaml
- bases/infrastructure.cluster.x-k8s.io_dockerclustertemplates.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_dockermachines.yaml
#- patches/webhook_in_dockerclusters.yaml
#- patches/webhook_in_dockerclustertemplates.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_dockermachines.yaml
#- patches/cainjection_in_dockerclusters.yaml
#- patches/cainjection_in_dockerclustertemplates.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: dockerclustertemplates.infrastructure.cluster.x-k8s.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: dockerclustertemplates.infrastructure.cluster.x-k8s.io
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert

0 comments on commit 3b95493

Please sign in to comment.