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

Commit

Permalink
adding NestedControlPlane & NestedCluster controllers
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Hein <[email protected]>
  • Loading branch information
christopherhein committed May 6, 2021
1 parent 163817c commit bd4ab69
Show file tree
Hide file tree
Showing 45 changed files with 2,149 additions and 245 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN go mod download
COPY main.go main.go
COPY apis/ apis/
COPY controllers/ controllers/
COPY certificate/ certificate/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
Expand Down
14 changes: 12 additions & 2 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
domain: cluster.x-k8s.io
layout: go.kubebuilder.io/v3
layout:
- go.kubebuilder.io/v3
multigroup: true
projectName: cluster-api-provider-nested
repo: sigs.k8s.io/cluster-api-provider-nested
Expand All @@ -22,4 +23,13 @@ resources:
group: controlplane
kind: NestedControllerManager
version: v1alpha4
version: 3-alpha
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cluster.x-k8s.io
group: infrastructure
kind: NestedCluster
path: sigs.k8s.io/cluster-api-provider-nested/apis/infrastructure/v1alpha4
version: v1alpha4
version: "3"
35 changes: 33 additions & 2 deletions apis/controlplane/v1alpha4/nestedapiserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ type NestedAPIServerStatus struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Namespaced,path=nestedapiservers,shortName=nkas
//+kubebuilder:categories=capi,capn
//+kubebuilder:resource:scope=Namespaced,shortName=nkas,categories=capi;capn
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:subresource:status
Expand All @@ -68,3 +67,35 @@ type NestedAPIServerList struct {
func init() {
SchemeBuilder.Register(&NestedAPIServer{}, &NestedAPIServerList{})
}

var _ addonv1alpha1.CommonObject = &NestedAPIServer{}
var _ addonv1alpha1.Patchable = &NestedAPIServer{}

// ComponentName returns the name of the component for use with
// addonv1alpha1.CommonObject
func (c *NestedAPIServer) ComponentName() string {
return string(APIServer)
}

// CommonSpec returns the addons spec of the object allowing common funcs like
// Channel & Version to be usable
func (c *NestedAPIServer) CommonSpec() addonv1alpha1.CommonSpec {
return c.Spec.CommonSpec
}

// GetCommonStatus will return the common status for checking is a component
// was successfully deployed
func (c *NestedAPIServer) GetCommonStatus() addonv1alpha1.CommonStatus {
return c.Status.CommonStatus
}

// SetCommonStatus will set the status so that abstract representations can set
// Ready and Phases
func (c *NestedAPIServer) SetCommonStatus(s addonv1alpha1.CommonStatus) {
c.Status.CommonStatus = s
}

// PatchSpec returns the patches to be applied
func (c *NestedAPIServer) PatchSpec() addonv1alpha1.PatchSpec {
return c.Spec.PatchSpec
}
35 changes: 33 additions & 2 deletions apis/controlplane/v1alpha4/nestedcontrollermanager_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ type NestedControllerManagerStatus struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Namespaced,path=nestedcontrollermanager,shortName=nkcm
//+kubebuilder:categories=capi,capn
//+kubebuilder:resource:scope=Namespaced,shortName=nkcm,categories=capi;capn
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:subresource:status
Expand All @@ -63,3 +62,35 @@ type NestedControllerManagerList struct {
func init() {
SchemeBuilder.Register(&NestedControllerManager{}, &NestedControllerManagerList{})
}

var _ addonv1alpha1.CommonObject = &NestedControllerManager{}
var _ addonv1alpha1.Patchable = &NestedControllerManager{}

// ComponentName returns the name of the component for use with
// addonv1alpha1.CommonObject
func (c *NestedControllerManager) ComponentName() string {
return string(ControllerManager)
}

// CommonSpec returns the addons spec of the object allowing common funcs like
// Channel & Version to be usable
func (c *NestedControllerManager) CommonSpec() addonv1alpha1.CommonSpec {
return c.Spec.CommonSpec
}

// GetCommonStatus will return the common status for checking is a component
// was successfully deployed
func (c *NestedControllerManager) GetCommonStatus() addonv1alpha1.CommonStatus {
return c.Status.CommonStatus
}

// SetCommonStatus will set the status so that abstract representations can set
// Ready and Phases
func (c *NestedControllerManager) SetCommonStatus(s addonv1alpha1.CommonStatus) {
c.Status.CommonStatus = s
}

// PatchSpec returns the patches to be applied
func (c *NestedControllerManager) PatchSpec() addonv1alpha1.PatchSpec {
return c.Spec.PatchSpec
}
34 changes: 26 additions & 8 deletions apis/controlplane/v1alpha4/nestedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,23 @@ limitations under the License.
package v1alpha4

import (
"context"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
// NestedControlPlaneFinalizer is added to the NestedControlPlane to allow
// nested deletions to happen before the object is cleaned up
NestedControlPlaneFinalizer = "nested.controlplane.cluster.x-k8s.io"
)

// NestedControlPlaneSpec defines the desired state of NestedControlPlane
type NestedControlPlaneSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`

// EtcdRef is the reference to the NestedEtcd
EtcdRef *corev1.ObjectReference `json:"etcd,omitempty"`

Expand Down Expand Up @@ -87,10 +93,9 @@ type NestedControlPlaneStatusAPIServer struct {
ServiceCIDR string `json:"serviceCidr,omitempty"`
}

// +kubebuilder:object:root=true
//+kubebuilder:resource:scope=Namespaced,shortName=ncp
//+kubebuilder:categories=capi,capn
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.rady"
//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Namespaced,shortName=ncp,categories=capi;capn
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:subresource:status

Expand All @@ -115,3 +120,16 @@ type NestedControlPlaneList struct {
func init() {
SchemeBuilder.Register(&NestedControlPlane{}, &NestedControlPlaneList{})
}

// GetOwnerCluster is a utility to return the owning clusterv1.Cluster
func (r *NestedControlPlane) GetOwnerCluster(ctx context.Context, cli client.Client) (cluster *clusterv1.Cluster, err error) {
return util.GetOwnerCluster(ctx, cli, r.ObjectMeta)
}

func (in *NestedControlPlane) GetConditions() clusterv1.Conditions {
return in.Status.Conditions
}

func (in *NestedControlPlane) SetConditions(conditions clusterv1.Conditions) {
in.Status.Conditions = conditions
}
35 changes: 33 additions & 2 deletions apis/controlplane/v1alpha4/nestedetcd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ type NestedEtcdAddress struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Namespaced,path=nestedetcds,shortName=netcd
//+kubebuilder:categories=capi,capn
//+kubebuilder:resource:scope=Namespaced,shortName=netcd,categories=capi;capn
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:subresource:status
Expand All @@ -80,3 +79,35 @@ type NestedEtcdList struct {
func init() {
SchemeBuilder.Register(&NestedEtcd{}, &NestedEtcdList{})
}

var _ addonv1alpha1.CommonObject = &NestedEtcd{}
var _ addonv1alpha1.Patchable = &NestedEtcd{}

// ComponentName returns the name of the component for use with
// addonv1alpha1.CommonObjec
func (c *NestedEtcd) ComponentName() string {
return string(Etcd)
}

// CommonSpec returns the addons spec of the object allowing common funcs like
// Channel & Version to be usabl
func (c *NestedEtcd) CommonSpec() addonv1alpha1.CommonSpec {
return c.Spec.CommonSpec
}

// GetCommonStatus will return the common status for checking is a component
// was successfully deployed
func (c *NestedEtcd) GetCommonStatus() addonv1alpha1.CommonStatus {
return c.Status.CommonStatus
}

// SetCommonStatus will set the status so that abstract representations can set
// Ready and Phases
func (c *NestedEtcd) SetCommonStatus(s addonv1alpha1.CommonStatus) {
c.Status.CommonStatus = s
}

// PatchSpec returns the patches to be applie
func (c *NestedEtcd) PatchSpec() addonv1alpha1.PatchSpec {
return c.Spec.PatchSpec
}
1 change: 0 additions & 1 deletion apis/controlplane/v1alpha4/zz_generated.deepcopy.go

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

36 changes: 36 additions & 0 deletions apis/infrastructure/v1alpha4/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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 contains API Schema definitions for the infrastructure v1alpha4 API group
//+kubebuilder:object:generate=true
//+groupName=infrastructure.cluster.x-k8s.io
package v1alpha4

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: "infrastructure.cluster.x-k8s.io", Version: "v1alpha4"}

// 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 apis/infrastructure/v1alpha4/nestedcluster_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
)

// NestedClusterSpec defines the desired state of NestedCluster
type NestedClusterSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
}

// NestedClusterStatus defines the observed state of NestedCluster
type NestedClusterStatus struct {
// Ready is when the NestedControlPlane has a API server URL.
// +optional
Ready bool `json:"ready,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Namespaced,shortName=nc,categories=capi;capn
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:subresource:status

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

Spec NestedClusterSpec `json:"spec,omitempty"`
Status NestedClusterStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&NestedCluster{}, &NestedClusterList{})
}
Loading

0 comments on commit bd4ab69

Please sign in to comment.