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 4, 2021
1 parent 163817c commit ce2e83d
Show file tree
Hide file tree
Showing 36 changed files with 1,804 additions and 234 deletions.
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"
26 changes: 24 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,26 @@ type NestedAPIServerList struct {
func init() {
SchemeBuilder.Register(&NestedAPIServer{}, &NestedAPIServerList{})
}

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

func (c *NestedAPIServer) ComponentName() string {
return string(APIServer)
}

func (c *NestedAPIServer) CommonSpec() addonv1alpha1.CommonSpec {
return c.Spec.CommonSpec
}

func (c *NestedAPIServer) GetCommonStatus() addonv1alpha1.CommonStatus {
return c.Status.CommonStatus
}

func (c *NestedAPIServer) SetCommonStatus(s addonv1alpha1.CommonStatus) {
c.Status.CommonStatus = s
}

func (c *NestedAPIServer) PatchSpec() addonv1alpha1.PatchSpec {
return c.Spec.PatchSpec
}
26 changes: 24 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,26 @@ type NestedControllerManagerList struct {
func init() {
SchemeBuilder.Register(&NestedControllerManager{}, &NestedControllerManagerList{})
}

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

func (c *NestedControllerManager) ComponentName() string {
return string(ControllerManager)
}

func (c *NestedControllerManager) CommonSpec() addonv1alpha1.CommonSpec {
return c.Spec.CommonSpec
}

func (c *NestedControllerManager) GetCommonStatus() addonv1alpha1.CommonStatus {
return c.Status.CommonStatus
}

func (c *NestedControllerManager) SetCommonStatus(s addonv1alpha1.CommonStatus) {
c.Status.CommonStatus = s
}

func (c *NestedControllerManager) PatchSpec() addonv1alpha1.PatchSpec {
return c.Spec.PatchSpec
}
23 changes: 15 additions & 8 deletions apis/controlplane/v1alpha4/nestedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ 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 = "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 +91,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 +118,7 @@ type NestedControlPlaneList struct {
func init() {
SchemeBuilder.Register(&NestedControlPlane{}, &NestedControlPlaneList{})
}

func (r *NestedControlPlane) GetOwnerCluster(ctx context.Context, cli client.Client) (cluster *clusterv1.Cluster, err error) {
return util.GetOwnerCluster(ctx, cli, r.ObjectMeta)
}
26 changes: 24 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,26 @@ type NestedEtcdList struct {
func init() {
SchemeBuilder.Register(&NestedEtcd{}, &NestedEtcdList{})
}

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

func (c *NestedEtcd) ComponentName() string {
return string(Etcd)
}

func (c *NestedEtcd) CommonSpec() addonv1alpha1.CommonSpec {
return c.Spec.CommonSpec
}

func (c *NestedEtcd) GetCommonStatus() addonv1alpha1.CommonStatus {
return c.Status.CommonStatus
}

func (c *NestedEtcd) SetCommonStatus(s addonv1alpha1.CommonStatus) {
c.Status.CommonStatus = s
}

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 2020 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 2020 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 ce2e83d

Please sign in to comment.