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

Commit 3a53ec2

Browse files
authored
Merge pull request #43 from christopherhein/feature/ncp-controller
NestedControlPlane & NestedCluster Controllers
2 parents 163817c + 5257ffb commit 3a53ec2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2157
-245
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN go mod download
1313
COPY main.go main.go
1414
COPY apis/ apis/
1515
COPY controllers/ controllers/
16+
COPY certificate/ certificate/
1617

1718
# Build
1819
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go

PROJECT

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
domain: cluster.x-k8s.io
2-
layout: go.kubebuilder.io/v3
2+
layout:
3+
- go.kubebuilder.io/v3
34
multigroup: true
45
projectName: cluster-api-provider-nested
56
repo: sigs.k8s.io/cluster-api-provider-nested
@@ -22,4 +23,13 @@ resources:
2223
group: controlplane
2324
kind: NestedControllerManager
2425
version: v1alpha4
25-
version: 3-alpha
26+
- api:
27+
crdVersion: v1
28+
namespaced: true
29+
controller: true
30+
domain: cluster.x-k8s.io
31+
group: infrastructure
32+
kind: NestedCluster
33+
path: sigs.k8s.io/cluster-api-provider-nested/apis/infrastructure/v1alpha4
34+
version: v1alpha4
35+
version: "3"

apis/controlplane/v1alpha4/nestedapiserver_types.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ type NestedAPIServerStatus struct {
4141
}
4242

4343
//+kubebuilder:object:root=true
44-
//+kubebuilder:resource:scope=Namespaced,path=nestedapiservers,shortName=nkas
45-
//+kubebuilder:categories=capi,capn
44+
//+kubebuilder:resource:scope=Namespaced,shortName=nkas,categories=capi;capn
4645
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
4746
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4847
//+kubebuilder:subresource:status
@@ -68,3 +67,35 @@ type NestedAPIServerList struct {
6867
func init() {
6968
SchemeBuilder.Register(&NestedAPIServer{}, &NestedAPIServerList{})
7069
}
70+
71+
var _ addonv1alpha1.CommonObject = &NestedAPIServer{}
72+
var _ addonv1alpha1.Patchable = &NestedAPIServer{}
73+
74+
// ComponentName returns the name of the component for use with
75+
// addonv1alpha1.CommonObject
76+
func (c *NestedAPIServer) ComponentName() string {
77+
return string(APIServer)
78+
}
79+
80+
// CommonSpec returns the addons spec of the object allowing common funcs like
81+
// Channel & Version to be usable
82+
func (c *NestedAPIServer) CommonSpec() addonv1alpha1.CommonSpec {
83+
return c.Spec.CommonSpec
84+
}
85+
86+
// GetCommonStatus will return the common status for checking is a component
87+
// was successfully deployed
88+
func (c *NestedAPIServer) GetCommonStatus() addonv1alpha1.CommonStatus {
89+
return c.Status.CommonStatus
90+
}
91+
92+
// SetCommonStatus will set the status so that abstract representations can set
93+
// Ready and Phases
94+
func (c *NestedAPIServer) SetCommonStatus(s addonv1alpha1.CommonStatus) {
95+
c.Status.CommonStatus = s
96+
}
97+
98+
// PatchSpec returns the patches to be applied
99+
func (c *NestedAPIServer) PatchSpec() addonv1alpha1.PatchSpec {
100+
return c.Spec.PatchSpec
101+
}

apis/controlplane/v1alpha4/nestedcontrollermanager_types.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ type NestedControllerManagerStatus struct {
3636
}
3737

3838
//+kubebuilder:object:root=true
39-
//+kubebuilder:resource:scope=Namespaced,path=nestedcontrollermanager,shortName=nkcm
40-
//+kubebuilder:categories=capi,capn
39+
//+kubebuilder:resource:scope=Namespaced,shortName=nkcm,categories=capi;capn
4140
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
4241
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4342
//+kubebuilder:subresource:status
@@ -63,3 +62,35 @@ type NestedControllerManagerList struct {
6362
func init() {
6463
SchemeBuilder.Register(&NestedControllerManager{}, &NestedControllerManagerList{})
6564
}
65+
66+
var _ addonv1alpha1.CommonObject = &NestedControllerManager{}
67+
var _ addonv1alpha1.Patchable = &NestedControllerManager{}
68+
69+
// ComponentName returns the name of the component for use with
70+
// addonv1alpha1.CommonObject
71+
func (c *NestedControllerManager) ComponentName() string {
72+
return string(ControllerManager)
73+
}
74+
75+
// CommonSpec returns the addons spec of the object allowing common funcs like
76+
// Channel & Version to be usable
77+
func (c *NestedControllerManager) CommonSpec() addonv1alpha1.CommonSpec {
78+
return c.Spec.CommonSpec
79+
}
80+
81+
// GetCommonStatus will return the common status for checking is a component
82+
// was successfully deployed
83+
func (c *NestedControllerManager) GetCommonStatus() addonv1alpha1.CommonStatus {
84+
return c.Status.CommonStatus
85+
}
86+
87+
// SetCommonStatus will set the status so that abstract representations can set
88+
// Ready and Phases
89+
func (c *NestedControllerManager) SetCommonStatus(s addonv1alpha1.CommonStatus) {
90+
c.Status.CommonStatus = s
91+
}
92+
93+
// PatchSpec returns the patches to be applied
94+
func (c *NestedControllerManager) PatchSpec() addonv1alpha1.PatchSpec {
95+
return c.Spec.PatchSpec
96+
}

apis/controlplane/v1alpha4/nestedcontrolplane_types.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@ limitations under the License.
1717
package v1alpha4
1818

1919
import (
20+
"context"
21+
2022
corev1 "k8s.io/api/core/v1"
2123
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
25+
"sigs.k8s.io/cluster-api/util"
26+
"sigs.k8s.io/controller-runtime/pkg/client"
27+
)
28+
29+
const (
30+
// NestedControlPlaneFinalizer is added to the NestedControlPlane to allow
31+
// nested deletions to happen before the object is cleaned up
32+
NestedControlPlaneFinalizer = "nested.controlplane.cluster.x-k8s.io"
2333
)
2434

2535
// NestedControlPlaneSpec defines the desired state of NestedControlPlane
2636
type NestedControlPlaneSpec struct {
27-
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
28-
// +optional
29-
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
30-
3137
// EtcdRef is the reference to the NestedEtcd
3238
EtcdRef *corev1.ObjectReference `json:"etcd,omitempty"`
3339

@@ -87,10 +93,9 @@ type NestedControlPlaneStatusAPIServer struct {
8793
ServiceCIDR string `json:"serviceCidr,omitempty"`
8894
}
8995

90-
// +kubebuilder:object:root=true
91-
//+kubebuilder:resource:scope=Namespaced,shortName=ncp
92-
//+kubebuilder:categories=capi,capn
93-
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.rady"
96+
//+kubebuilder:object:root=true
97+
//+kubebuilder:resource:scope=Namespaced,shortName=ncp,categories=capi;capn
98+
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
9499
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
95100
//+kubebuilder:subresource:status
96101

@@ -115,3 +120,16 @@ type NestedControlPlaneList struct {
115120
func init() {
116121
SchemeBuilder.Register(&NestedControlPlane{}, &NestedControlPlaneList{})
117122
}
123+
124+
// GetOwnerCluster is a utility to return the owning clusterv1.Cluster
125+
func (r *NestedControlPlane) GetOwnerCluster(ctx context.Context, cli client.Client) (cluster *clusterv1.Cluster, err error) {
126+
return util.GetOwnerCluster(ctx, cli, r.ObjectMeta)
127+
}
128+
129+
func (in *NestedControlPlane) GetConditions() clusterv1.Conditions {
130+
return in.Status.Conditions
131+
}
132+
133+
func (in *NestedControlPlane) SetConditions(conditions clusterv1.Conditions) {
134+
in.Status.Conditions = conditions
135+
}

apis/controlplane/v1alpha4/nestedetcd_types.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ type NestedEtcdAddress struct {
5353
}
5454

5555
//+kubebuilder:object:root=true
56-
//+kubebuilder:resource:scope=Namespaced,path=nestedetcds,shortName=netcd
57-
//+kubebuilder:categories=capi,capn
56+
//+kubebuilder:resource:scope=Namespaced,shortName=netcd,categories=capi;capn
5857
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
5958
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
6059
//+kubebuilder:subresource:status
@@ -80,3 +79,35 @@ type NestedEtcdList struct {
8079
func init() {
8180
SchemeBuilder.Register(&NestedEtcd{}, &NestedEtcdList{})
8281
}
82+
83+
var _ addonv1alpha1.CommonObject = &NestedEtcd{}
84+
var _ addonv1alpha1.Patchable = &NestedEtcd{}
85+
86+
// ComponentName returns the name of the component for use with
87+
// addonv1alpha1.CommonObjec
88+
func (c *NestedEtcd) ComponentName() string {
89+
return string(Etcd)
90+
}
91+
92+
// CommonSpec returns the addons spec of the object allowing common funcs like
93+
// Channel & Version to be usabl
94+
func (c *NestedEtcd) CommonSpec() addonv1alpha1.CommonSpec {
95+
return c.Spec.CommonSpec
96+
}
97+
98+
// GetCommonStatus will return the common status for checking is a component
99+
// was successfully deployed
100+
func (c *NestedEtcd) GetCommonStatus() addonv1alpha1.CommonStatus {
101+
return c.Status.CommonStatus
102+
}
103+
104+
// SetCommonStatus will set the status so that abstract representations can set
105+
// Ready and Phases
106+
func (c *NestedEtcd) SetCommonStatus(s addonv1alpha1.CommonStatus) {
107+
c.Status.CommonStatus = s
108+
}
109+
110+
// PatchSpec returns the patches to be applie
111+
func (c *NestedEtcd) PatchSpec() addonv1alpha1.PatchSpec {
112+
return c.Spec.PatchSpec
113+
}

apis/controlplane/v1alpha4/zz_generated.deepcopy.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha4 contains API Schema definitions for the infrastructure v1alpha4 API group
18+
//+kubebuilder:object:generate=true
19+
//+groupName=infrastructure.cluster.x-k8s.io
20+
package v1alpha4
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1alpha4"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha4
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
22+
)
23+
24+
// NestedClusterSpec defines the desired state of NestedCluster
25+
type NestedClusterSpec struct {
26+
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
27+
// +optional
28+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
29+
}
30+
31+
// NestedClusterStatus defines the observed state of NestedCluster
32+
type NestedClusterStatus struct {
33+
// Ready is when the NestedControlPlane has a API server URL.
34+
// +optional
35+
Ready bool `json:"ready,omitempty"`
36+
}
37+
38+
//+kubebuilder:object:root=true
39+
//+kubebuilder:resource:scope=Namespaced,shortName=nc,categories=capi;capn
40+
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
41+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
42+
//+kubebuilder:subresource:status
43+
44+
// NestedCluster is the Schema for the nestedclusters API
45+
type NestedCluster struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec NestedClusterSpec `json:"spec,omitempty"`
50+
Status NestedClusterStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// NestedClusterList contains a list of NestedCluster
56+
type NestedClusterList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []NestedCluster `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&NestedCluster{}, &NestedClusterList{})
64+
}

0 commit comments

Comments
 (0)