Skip to content

Commit

Permalink
CRD Breakout (#55)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
rejoshed authored May 6, 2022
1 parent 8c4fa8c commit 3247e55
Show file tree
Hide file tree
Showing 68 changed files with 3,416 additions and 1,199 deletions.
31 changes: 28 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
domain: cluster.x-k8s.io
layout:
- go.kubebuilder.io/v3
projectName: cluster-api-provider-capc
repo: github.com/aws/cluster-api-provider-cloudstack
resources:
Expand Down Expand Up @@ -43,4 +41,31 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
version: "0.4"
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cluster.x-k8s.io
group: infrastructure
kind: CloudStackIsolatedNetwork
path: github.com/aws/cluster-api-provider-cloudstack/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cluster.x-k8s.io
group: infrastructure
kind: CloudStackZone
path: github.com/aws/cluster-api-provider-cloudstack/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cluster.x-k8s.io
group: infrastructure
kind: CloudStackAffinityGroup
path: github.com/aws/cluster-api-provider-cloudstack/api/v1beta1
version: v1beta1
version: "3"
70 changes: 70 additions & 0 deletions api/v1beta1/cloudstackaffinitygroup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright 2022 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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
AffinityGroupFinalizer = "affinitygroup.infrastructure.cluster.x-k8s.io"
)

// CloudStackAffinityGroupSpec defines the desired state of CloudStackAffinityGroup
type CloudStackAffinityGroupSpec struct {
// Mutually exclusive parameter with AffinityGroupIDs.
// Can be "host affinity" or "host anti-affinity". Will create an affinity group per machine set.
Type string `json:"type,omitempty"`

// Name.
Name string `json:"name,omitempty"`

// ID.
//+optional
ID string `json:"id,omitempty"`
}

// CloudStackAffinityGroupStatus defines the observed state of CloudStackAffinityGroup
type CloudStackAffinityGroupStatus struct {
// Reflects the readiness of the CS Affinity Group.
Ready bool `json:"ready"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

Spec CloudStackAffinityGroupSpec `json:"spec,omitempty"`
Status CloudStackAffinityGroupStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&CloudStackAffinityGroup{}, &CloudStackAffinityGroupList{})
}
48 changes: 21 additions & 27 deletions api/v1beta1/cloudstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ limitations under the License.
package v1beta1

import (
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
// The presence of a finalizer prevents CAPI from deleting the corresponding CAPI data.
ClusterFinalizer = "cloudstackcluster.infrastructure.cluster.x-k8s.io"
defaultIdentityRefKind = "Secret"
ClusterFinalizer = "cloudstackcluster.infrastructure.cluster.x-k8s.io"
defaultIdentityRefKind = "Secret"
CloudStackClusterLabelName = "cloudstackcluster.infrastructure.cluster.x-k8s.io/name"
NetworkTypeIsolated = "Isolated"
NetworkTypeShared = "Shared"
)

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

type ZoneStatusMap map[string]Zone

// GetOne just returns a Zone from the map of zone statuses
// Needed as there's no short way to do this.
func (zones ZoneStatusMap) GetOne() *Zone {
for _, zone := range zones {
return &zone
}
return nil
}

// GetByName fetches a zone by name if present in the map of zone statuses.
// Needed as there's no short way to do this.
func (zones ZoneStatusMap) GetByName(name string) *Zone {
for _, zone := range zones {
if zone.Name == name {
return &zone
}
}
return nil
}

type Zone struct {
// The Zone name.
// + optional
// Name.
//+optional
Name string `json:"name,omitempty"`

// The CS zone ID the cluster is built in.
// + optional
// ID.
//+optional
ID string `json:"id,omitempty"`

// The network within the Zone to use.
Network Network `json:"network"`
}

// MetaName returns a lower cased name to be used in a k8s object meta.
// It prefers the zone's name, but will use the ID if that's the only present identifier.
func (z *Zone) MetaName() string {
s := z.Name
if s == "" {
s = z.ID
}
return strings.ToLower(s)
}

// CloudStackClusterSpec defines the desired state of CloudStackCluster.
type CloudStackClusterSpec struct {
Zones []Zone `json:"zones"`
Expand Down
56 changes: 0 additions & 56 deletions api/v1beta1/cloudstackcluster_types_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion api/v1beta1/cloudstackcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ var _ = Describe("CloudStackCluster webhooks", func() {
})

It("Should reject a CloudStackCluster with missing Zones.Network attribute", func() {
dummies.CSCluster.Spec.Zones = []infrav1.Zone{{Name: "ZoneWNoNetwork"}}
dummies.CSCluster.Spec.Zones = []infrav1.Zone{{}}
dummies.CSCluster.Spec.Zones[0].Name = "ZoneWNoNetwork"
Ω(k8sClient.Create(ctx, dummies.CSCluster)).Should(
MatchError(MatchRegexp(requiredRegex, "each Zone requires a Network specification")))
})
Expand Down
85 changes: 85 additions & 0 deletions api/v1beta1/cloudstackisolatednetwork_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2022 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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
// The presence of a finalizer prevents CAPI from deleting the corresponding CAPI data.
IsolatedNetworkFinalizer = "cloudstackisolatednetwork.infrastructure.cluster.x-k8s.io"
)

// CloudStackIsolatedNetworkSpec defines the desired state of CloudStackIsolatedNetwork
type CloudStackIsolatedNetworkSpec struct {
// Name.
//+optional
Name string `json:"name,omitempty"`

// ID.
//+optional
ID string `json:"id,omitempty"`

// The kubernetes control plane endpoint.
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
}

// CloudStackIsolatedNetworkStatus defines the observed state of CloudStackIsolatedNetwork
type CloudStackIsolatedNetworkStatus struct {
// The CS public IP ID to use for the k8s endpoint.
PublicIPID string `json:"publicIPID,omitempty"`

// The ID of the lb rule used to assign VMs to the lb.
LBRuleID string `json:"loadBalancerRuleID,omitempty"`

// Ready indicates the readiness of this provider resource.
Ready bool `json:"ready"`
}

func (n *CloudStackIsolatedNetwork) Network() *Network {
return &Network{
Name: n.Spec.Name,
Type: "IsolatedNetwork",
ID: n.Spec.ID}
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

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

Spec CloudStackIsolatedNetworkSpec `json:"spec,omitempty"`
Status CloudStackIsolatedNetworkStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&CloudStackIsolatedNetwork{}, &CloudStackIsolatedNetworkList{})
}
Loading

0 comments on commit 3247e55

Please sign in to comment.