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 v1alpha8 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 Feb 28, 2024
1 parent 5cfeccc commit 65a96b7
Show file tree
Hide file tree
Showing 31 changed files with 1,209 additions and 14 deletions.
9 changes: 6 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@ resources:
kind: OpenStackClusterTemplate
version: v1alpha7
- group: infrastructure
version: v1alpha8
kind: OpenStackCluster
- group: infrastructure
version: v1alpha8
kind: OpenStackMachine
- group: infrastructure
kind: OpenStackMachine
version: v1alpha8
- group: infrastructure
kind: OpenStackMachineTemplate
version: v1alpha8
- group: infrastructure
kind: OpenStackClusterTemplate
version: v1alpha8
- group: infrastructure
kind: OpenStackFloatingIPPool
version: v1alpha1
- group: infrastructure
kind: OpenstackServerGroup
version: v1alpha8
version: "2"
1 change: 1 addition & 0 deletions api/v1alpha5/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/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/v1alpha8/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ type OpenStackMachineSpec struct {
// +optional
ServerGroup *ServerGroupFilter `json:"serverGroup,omitempty"`

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

// IdentityRef is a reference to a identity to be used when reconciling this cluster
// +optional
IdentityRef *OpenStackIdentityReference `json:"identityRef,omitempty"`
Expand Down
76 changes: 76 additions & 0 deletions api/v1alpha8/openstackservergroup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
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 v1alpha8

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 {
// The name of the cloud to use from the clouds secret
// +optional
CloudName string `json:"cloudName"`

// 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"`
}

func init() {
objectTypes = append(objectTypes, &OpenStackServerGroup{}, &OpenStackServerGroupList{})
}
8 changes: 7 additions & 1 deletion api/v1alpha8/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ type ServerGroupFilter struct {
Name string `json:"name,omitempty"`
}

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 @@ -489,7 +495,7 @@ type APIServerLoadBalancer struct {

// ReferencedMachineResources contains resolved references to resources required by the machine.
type ReferencedMachineResources 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 or ServerGroupRef.
// +optional
ServerGroupID string `json:"serverGroupID,omitempty"`

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -5268,6 +5268,17 @@ spec:
name:
type: string
type: object
serverGroupRef:
description: The server group ref to assign the machine to.
properties:
name:
description: |-
Name of the OpenStackServerGroup resource to be used.
Must be in the same namespace as the resource(s) being provisioned.
type: string
required:
- name
type: object
serverMetadata:
description: Metadata mapping. Allows you to create a map
of key value pairs to add to the server instance.
Expand Down Expand Up @@ -5713,7 +5724,8 @@ spec:
type: string
serverGroupID:
description: ServerGroupID is the ID of the server group the
machine should be added to and is calculated based on ServerGroupFilter.
machine should be added to and is calculated based on ServerGroupFilter
or ServerGroupRef.
type: string
type: object
sshKeyName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2701,6 +2701,18 @@ spec:
name:
type: string
type: object
serverGroupRef:
description: The server group ref to assign the machine
to.
properties:
name:
description: |-
Name of the OpenStackServerGroup resource to be used.
Must be in the same namespace as the resource(s) being provisioned.
type: string
required:
- name
type: object
serverMetadata:
description: Metadata mapping. Allows you to create
a map of key value pairs to add to the server instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,17 @@ spec:
name:
type: string
type: object
serverGroupRef:
description: The server group ref to assign the machine to.
properties:
name:
description: |-
Name of the OpenStackServerGroup resource to be used.
Must be in the same namespace as the resource(s) being provisioned.
type: string
required:
- name
type: object
serverMetadata:
description: Metadata mapping. Allows you to create a map of key value
pairs to add to the server instance.
Expand Down Expand Up @@ -2214,7 +2225,8 @@ spec:
type: string
serverGroupID:
description: ServerGroupID is the ID of the server group the machine
should be added to and is calculated based on ServerGroupFilter.
should be added to and is calculated based on ServerGroupFilter
or ServerGroupRef.
type: string
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,17 @@ spec:
name:
type: string
type: object
serverGroupRef:
description: The server group ref to assign the machine to.
properties:
name:
description: |-
Name of the OpenStackServerGroup resource to be used.
Must be in the same namespace as the resource(s) being provisioned.
type: string
required:
- name
type: object
serverMetadata:
description: Metadata mapping. Allows you to create a map
of key value pairs to add to the server instance.
Expand Down
Loading

0 comments on commit 65a96b7

Please sign in to comment.