Skip to content

Commit 3247e55

Browse files
authored
CRD Breakout (#55)
* Can now build Isolated network with extra CRDs. * Such awesome, much wow * Saving progress and switching gears. * Abstractions gallore. * Further abstraction of the controller as an idea. Compiles and almost works. * More generalized than before. * More abstraction still. * Made things work. * Made things work. * Zones firing. * Machines work via new style now. * Slight cleanup. * Iso net with load balancer rules working now. * Set nginx to use default ports. * Isolated networks create and delete with load balancer and fill endpoint hosts now. * Builds a cluster. * Added Affinity group crd. * Added machine health checker. * Afinity groups are a go. * Update partially to main. * Some cleanup. More to come. * Fixup missing dispose iso net call. * Removed machine health checker crd. * Removed machine health checker crd. * Passes webhook and controller tests. Passes lint. * Unit tests fixed up. * Mild cleanup. * Updated per PR comments. * Fixup tests. * Fixup again. * Readd non-root. * Fix isolated network deletion. * pr review comments addressed. * Fix tests. * Fixup finalizer.
1 parent 8c4fa8c commit 3247e55

File tree

68 files changed

+3416
-1199
lines changed

Some content is hidden

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

68 files changed

+3416
-1199
lines changed

PROJECT

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
domain: cluster.x-k8s.io
2-
layout:
3-
- go.kubebuilder.io/v3
42
projectName: cluster-api-provider-capc
53
repo: github.com/aws/cluster-api-provider-cloudstack
64
resources:
@@ -43,4 +41,31 @@ resources:
4341
defaulting: true
4442
validation: true
4543
webhookVersion: v1
46-
version: "0.4"
44+
- api:
45+
crdVersion: v1
46+
namespaced: true
47+
controller: true
48+
domain: cluster.x-k8s.io
49+
group: infrastructure
50+
kind: CloudStackIsolatedNetwork
51+
path: github.com/aws/cluster-api-provider-cloudstack/api/v1beta1
52+
version: v1beta1
53+
- api:
54+
crdVersion: v1
55+
namespaced: true
56+
controller: true
57+
domain: cluster.x-k8s.io
58+
group: infrastructure
59+
kind: CloudStackZone
60+
path: github.com/aws/cluster-api-provider-cloudstack/api/v1beta1
61+
version: v1beta1
62+
- api:
63+
crdVersion: v1
64+
namespaced: true
65+
controller: true
66+
domain: cluster.x-k8s.io
67+
group: infrastructure
68+
kind: CloudStackAffinityGroup
69+
path: github.com/aws/cluster-api-provider-cloudstack/api/v1beta1
70+
version: v1beta1
71+
version: "3"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2022 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 v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
const (
24+
AffinityGroupFinalizer = "affinitygroup.infrastructure.cluster.x-k8s.io"
25+
)
26+
27+
// CloudStackAffinityGroupSpec defines the desired state of CloudStackAffinityGroup
28+
type CloudStackAffinityGroupSpec struct {
29+
// Mutually exclusive parameter with AffinityGroupIDs.
30+
// Can be "host affinity" or "host anti-affinity". Will create an affinity group per machine set.
31+
Type string `json:"type,omitempty"`
32+
33+
// Name.
34+
Name string `json:"name,omitempty"`
35+
36+
// ID.
37+
//+optional
38+
ID string `json:"id,omitempty"`
39+
}
40+
41+
// CloudStackAffinityGroupStatus defines the observed state of CloudStackAffinityGroup
42+
type CloudStackAffinityGroupStatus struct {
43+
// Reflects the readiness of the CS Affinity Group.
44+
Ready bool `json:"ready"`
45+
}
46+
47+
//+kubebuilder:object:root=true
48+
//+kubebuilder:subresource:status
49+
50+
// CloudStackAffinityGroup is the Schema for the cloudstackaffinitygroups API
51+
type CloudStackAffinityGroup struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ObjectMeta `json:"metadata,omitempty"`
54+
55+
Spec CloudStackAffinityGroupSpec `json:"spec,omitempty"`
56+
Status CloudStackAffinityGroupStatus `json:"status,omitempty"`
57+
}
58+
59+
//+kubebuilder:object:root=true
60+
61+
// CloudStackAffinityGroupList contains a list of CloudStackAffinityGroup
62+
type CloudStackAffinityGroupList struct {
63+
metav1.TypeMeta `json:",inline"`
64+
metav1.ListMeta `json:"metadata,omitempty"`
65+
Items []CloudStackAffinityGroup `json:"items"`
66+
}
67+
68+
func init() {
69+
SchemeBuilder.Register(&CloudStackAffinityGroup{}, &CloudStackAffinityGroupList{})
70+
}

api/v1beta1/cloudstackcluster_types.go

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"strings"
21+
2022
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2123
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2224
)
2325

2426
const (
25-
// The presence of a finalizer prevents CAPI from deleting the corresponding CAPI data.
26-
ClusterFinalizer = "cloudstackcluster.infrastructure.cluster.x-k8s.io"
27-
defaultIdentityRefKind = "Secret"
27+
ClusterFinalizer = "cloudstackcluster.infrastructure.cluster.x-k8s.io"
28+
defaultIdentityRefKind = "Secret"
29+
CloudStackClusterLabelName = "cloudstackcluster.infrastructure.cluster.x-k8s.io/name"
30+
NetworkTypeIsolated = "Isolated"
31+
NetworkTypeShared = "Shared"
2832
)
2933

3034
// CloudStackIdentityReference is a reference to an infrastructure
@@ -55,39 +59,29 @@ type Network struct {
5559

5660
type ZoneStatusMap map[string]Zone
5761

58-
// GetOne just returns a Zone from the map of zone statuses
59-
// Needed as there's no short way to do this.
60-
func (zones ZoneStatusMap) GetOne() *Zone {
61-
for _, zone := range zones {
62-
return &zone
63-
}
64-
return nil
65-
}
66-
67-
// GetByName fetches a zone by name if present in the map of zone statuses.
68-
// Needed as there's no short way to do this.
69-
func (zones ZoneStatusMap) GetByName(name string) *Zone {
70-
for _, zone := range zones {
71-
if zone.Name == name {
72-
return &zone
73-
}
74-
}
75-
return nil
76-
}
77-
7862
type Zone struct {
79-
// The Zone name.
80-
// + optional
63+
// Name.
64+
//+optional
8165
Name string `json:"name,omitempty"`
8266

83-
// The CS zone ID the cluster is built in.
84-
// + optional
67+
// ID.
68+
//+optional
8569
ID string `json:"id,omitempty"`
8670

8771
// The network within the Zone to use.
8872
Network Network `json:"network"`
8973
}
9074

75+
// MetaName returns a lower cased name to be used in a k8s object meta.
76+
// It prefers the zone's name, but will use the ID if that's the only present identifier.
77+
func (z *Zone) MetaName() string {
78+
s := z.Name
79+
if s == "" {
80+
s = z.ID
81+
}
82+
return strings.ToLower(s)
83+
}
84+
9185
// CloudStackClusterSpec defines the desired state of CloudStackCluster.
9286
type CloudStackClusterSpec struct {
9387
Zones []Zone `json:"zones"`

api/v1beta1/cloudstackcluster_types_test.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

api/v1beta1/cloudstackcluster_webhook_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ var _ = Describe("CloudStackCluster webhooks", func() {
4343
})
4444

4545
It("Should reject a CloudStackCluster with missing Zones.Network attribute", func() {
46-
dummies.CSCluster.Spec.Zones = []infrav1.Zone{{Name: "ZoneWNoNetwork"}}
46+
dummies.CSCluster.Spec.Zones = []infrav1.Zone{{}}
47+
dummies.CSCluster.Spec.Zones[0].Name = "ZoneWNoNetwork"
4748
Ω(k8sClient.Create(ctx, dummies.CSCluster)).Should(
4849
MatchError(MatchRegexp(requiredRegex, "each Zone requires a Network specification")))
4950
})
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
Copyright 2022 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 v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
22+
)
23+
24+
const (
25+
// The presence of a finalizer prevents CAPI from deleting the corresponding CAPI data.
26+
IsolatedNetworkFinalizer = "cloudstackisolatednetwork.infrastructure.cluster.x-k8s.io"
27+
)
28+
29+
// CloudStackIsolatedNetworkSpec defines the desired state of CloudStackIsolatedNetwork
30+
type CloudStackIsolatedNetworkSpec struct {
31+
// Name.
32+
//+optional
33+
Name string `json:"name,omitempty"`
34+
35+
// ID.
36+
//+optional
37+
ID string `json:"id,omitempty"`
38+
39+
// The kubernetes control plane endpoint.
40+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
41+
}
42+
43+
// CloudStackIsolatedNetworkStatus defines the observed state of CloudStackIsolatedNetwork
44+
type CloudStackIsolatedNetworkStatus struct {
45+
// The CS public IP ID to use for the k8s endpoint.
46+
PublicIPID string `json:"publicIPID,omitempty"`
47+
48+
// The ID of the lb rule used to assign VMs to the lb.
49+
LBRuleID string `json:"loadBalancerRuleID,omitempty"`
50+
51+
// Ready indicates the readiness of this provider resource.
52+
Ready bool `json:"ready"`
53+
}
54+
55+
func (n *CloudStackIsolatedNetwork) Network() *Network {
56+
return &Network{
57+
Name: n.Spec.Name,
58+
Type: "IsolatedNetwork",
59+
ID: n.Spec.ID}
60+
}
61+
62+
//+kubebuilder:object:root=true
63+
//+kubebuilder:subresource:status
64+
65+
// CloudStackIsolatedNetwork is the Schema for the cloudstackisolatednetworks API
66+
type CloudStackIsolatedNetwork struct {
67+
metav1.TypeMeta `json:",inline"`
68+
metav1.ObjectMeta `json:"metadata,omitempty"`
69+
70+
Spec CloudStackIsolatedNetworkSpec `json:"spec,omitempty"`
71+
Status CloudStackIsolatedNetworkStatus `json:"status,omitempty"`
72+
}
73+
74+
//+kubebuilder:object:root=true
75+
76+
// CloudStackIsolatedNetworkList contains a list of CloudStackIsolatedNetwork
77+
type CloudStackIsolatedNetworkList struct {
78+
metav1.TypeMeta `json:",inline"`
79+
metav1.ListMeta `json:"metadata,omitempty"`
80+
Items []CloudStackIsolatedNetwork `json:"items"`
81+
}
82+
83+
func init() {
84+
SchemeBuilder.Register(&CloudStackIsolatedNetwork{}, &CloudStackIsolatedNetworkList{})
85+
}

0 commit comments

Comments
 (0)