Skip to content

Commit

Permalink
Add OpenStackServerGroup CRD and Controller
Browse files Browse the repository at this point in the history
Implements new CRD for OpenstackServerGroup in v1beta1 to allow managed
Server Groups with standard policies, and adds ServerGroupRef to OpenstackMachine
that references the new CRD and uses it for VM creation.

Closes: kubernetes-sigs#1256
  • Loading branch information
dalees committed Jul 8, 2024
1 parent 20e8bac commit db35504
Show file tree
Hide file tree
Showing 29 changed files with 1,434 additions and 59 deletions.
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ resources:
- group: infrastructure
kind: OpenStackFloatingIPPool
version: v1alpha1
- group: infrastructure
kind: OpenstackServerGroup
version: v1beta1
version: "2"
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.

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.

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.

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

Loading

0 comments on commit db35504

Please sign in to comment.