Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add OpenStackServerGroup CRD and Controller #1912

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ resources:
- group: infrastructure
kind: OpenStackServer
version: v1alpha1
- group: infrastructure
kind: OpenstackServerGroup
version: v1beta1
version: "2"
4 changes: 4 additions & 0 deletions api/v1alpha1/openstackserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ type OpenStackServerSpec struct {
// +optional
ServerGroup *infrav1.ServerGroupParam `json:"serverGroup,omitempty"`

// The server group ref to assign the server instance to.
// +optional
ServerGroupRef *infrav1.ServerGroupRef `json:"serverGroupRef,omitempty"`

// ServerMetadata is a map of key value pairs to add to the server instance.
// +listType=map
// +listMapKey=key
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions api/v1alpha6/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ func restorev1beta1MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infr
dst.Image = previous.Image
dst.FloatingIPPoolRef = previous.FloatingIPPoolRef

// ServerGroupRef was added in v1beta1, so there is no equivalent in v1alpha7. Restore previous value.
dst.ServerGroupRef = previous.ServerGroupRef

if len(dst.SecurityGroups) == len(previous.SecurityGroups) {
for i := range dst.SecurityGroups {
restorev1beta1SecurityGroupParam(&previous.SecurityGroups[i], &dst.SecurityGroups[i])
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha6/zz_generated.conversion.go

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

3 changes: 3 additions & 0 deletions api/v1alpha7/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ func restorev1beta1MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infr
dst.ServerGroup = previous.ServerGroup
dst.Image = previous.Image

// ServerGroupRef was added in v1beta1, so there is no equivalent in v1alpha7. Restore previous value.
dst.ServerGroupRef = previous.ServerGroupRef

if len(dst.SecurityGroups) == len(previous.SecurityGroups) {
for i := range dst.SecurityGroups {
restorev1beta1SecurityGroupParam(&previous.SecurityGroups[i], &dst.SecurityGroups[i])
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha7/zz_generated.conversion.go

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

4 changes: 4 additions & 0 deletions api/v1beta1/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ type OpenStackMachineSpec struct {
// +optional
ServerGroup *ServerGroupParam `json:"serverGroup,omitempty"`

// The server group ref to assign the machine to.
// +optional
ServerGroupRef *ServerGroupRef `json:"serverGroupRef,omitempty"`

// IdentityRef is a reference to a secret holding OpenStack credentials
// to be used when reconciling this machine. If not specified, the
// credentials specified in the cluster will be used.
Expand Down
80 changes: 80 additions & 0 deletions api/v1beta1/openstackservergroup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2019 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 (
// ServerGroupFinalizer allows ReconcileOpenStackServerGroup to clean up OpenStack resources associated with OpenStackServerGroup before
// removing it from the apiserver.
ServerGroupFinalizer = "openstackservergroup.infrastructure.cluster.x-k8s.io"
)

// OpenStackServerGroupSpec defines the desired state of OpenStackServerGroup.
type OpenStackServerGroupSpec struct {
// Policy is a string with some valid values; affinity, anti-affinity, soft-affinity, soft-anti-affinity.
Policy string `json:"policy"`

// IdentityRef is a reference to a identity to be used when reconciling this resource
// +optional
IdentityRef *OpenStackIdentityReference `json:"identityRef,omitempty"`
}

// OpenStackServerGroupStatus defines the observed state of OpenStackServerGroup.
type OpenStackServerGroupStatus struct {
// Ready is true when the resource is created.
// +optional
Ready bool `json:"ready"`

// UUID of provisioned ServerGroup
ID string `json:"uuid"`
}

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

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

Spec OpenStackServerGroupSpec `json:"spec,omitempty"`
Status OpenStackServerGroupStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

// GetIdentifyRef returns the object's namespace and IdentityRef if it has an IdentityRef, or nulls if it does not.
func (r *OpenStackServerGroup) GetIdentityRef() (*string, *OpenStackIdentityReference) {
if r.Spec.IdentityRef != nil {
return &r.Namespace, r.Spec.IdentityRef
}
return nil, nil
}

func init() {
objectTypes = append(objectTypes, &OpenStackServerGroup{}, &OpenStackServerGroupList{})
}
8 changes: 7 additions & 1 deletion api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,12 @@ func (f *ServerGroupFilter) IsZero() bool {
return f.Name == nil
}

type ServerGroupRef struct {
// Name of the OpenStackServerGroup resource to be used.
// Must be in the same namespace as the resource(s) being provisioned.
Name string `json:"name"`
}

// BlockDeviceType defines the type of block device to create.
type BlockDeviceType string

Expand Down Expand Up @@ -881,7 +887,7 @@ func (s *APIServerLoadBalancer) IsEnabled() bool {

// ResolvedMachineSpec contains resolved references to resources required by the machine.
type ResolvedMachineSpec struct {
// ServerGroupID is the ID of the server group the machine should be added to and is calculated based on ServerGroupFilter.
// ServerGroupID is the ID of the server group the machine should be added to and is calculated based on ServerGroupFilter and ServerGroupRef.
// +optional
ServerGroupID string `json:"serverGroupID,omitempty"`

Expand Down
114 changes: 114 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions api_violations.report
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ API rule violation: names_match,sigs.k8s.io/cluster-api-provider-openstack/api/v
API rule violation: names_match,sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7,SubnetFilter,IPv6AddressMode
API rule violation: names_match,sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7,SubnetFilter,IPv6RAMode
API rule violation: names_match,sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7,SubnetFilter,ProjectID
API rule violation: names_match,sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1,OpenStackServerGroupStatus,ID
API rule violation: names_match,sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1,ResolvedFixedIP,SubnetID
API rule violation: names_match,sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1,Router,IPs
API rule violation: names_match,sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1,SubnetFilter,IPv6AddressMode
Expand Down

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

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

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

Loading