Skip to content

Commit

Permalink
Add OpenStackDataplaneDeployment CRD
Browse files Browse the repository at this point in the history
Adds a new OpenStackDataPlaneDeployment CRD, which will trigger the
ansible execution(s) for the given set of OpenStackDataPlaneNodeSets.

An OpenStackDataplaneDeployment can be thought of like a Kubernets Job.
Once it's successful, it's considered complete. The ansible executions
won't be retriggered by further reconciliations.

As part of this change, the following are implemented:

- The deployment logic and handling is removed from the
  OpenStackDataPlaneNodeSet controller and moved to the new
  OpenStackDataPlaneDeployment controller.

- The DeployStrategy section is dropped from OpenStackDataPlaneNodeSet and
  is no longer used. The ansible related fields (tags, skipTags, limit)
  are now set directly on OpenStackDataPlaneDeployment.

- dnsClusterAddresses and ctlplaneSearchDomain are now set as Status
  fields on OpenStackDataPlaneNodeSet so that the values can be retrieved
  when they are needed from the OpenStackDataPlaneDeployment controller.

Signed-off-by: James Slagle <[email protected]>
  • Loading branch information
slagle committed Sep 14, 2023
1 parent d984646 commit ff7bbd6
Show file tree
Hide file tree
Showing 42 changed files with 1,076 additions and 285 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ manifests: gowork controller-gen crd-to-markdown ## Generate WebhookConfiguratio
rm -f api/bases/* && cp -a config/crd/bases api/
$(CRD_MARKDOWN) -f api/v1beta1/common.go -f api/v1beta1/openstackdataplanenodeset_types.go -n OpenStackDataPlaneNodeSet > docs/openstack_dataplanenodeset.md
$(CRD_MARKDOWN) -f api/v1beta1/common.go -f api/v1beta1/openstackdataplaneservice_types.go -n OpenStackDataPlaneService > docs/openstack_dataplaneservice.md
$(CRD_MARKDOWN) -f api/v1beta1/common.go -f api/v1beta1/openstackdataplanedeployment_types.go -n OpenStackDataPlaneDeployment > docs/openstack_dataplanedeloyment.md

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ resources:
kind: OpenStackDataPlaneService
path: github.com/openstack-k8s-operators/dataplane-operator/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: openstack.org
group: dataplane
kind: OpenStackDataPlaneDeployment
path: github.com/openstack-k8s-operators/dataplane-operator/api/v1beta1
version: v1beta1
version: "3"
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
name: openstackdataplanedeployments.dataplane.openstack.org
spec:
group: dataplane.openstack.org
names:
kind: OpenStackDataPlaneDeployment
listKind: OpenStackDataPlaneDeploymentList
plural: openstackdataplanedeployments
shortNames:
- osdpd
- osdpdeployment
- osdpdeployments
singular: openstackdataplanedeployment
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: NodeSets
jsonPath: .spec.NodeSets
name: NodeSets
type: string
- description: Status
jsonPath: .status.conditions[0].status
name: Status
type: string
- description: Message
jsonPath: .status.conditions[0].message
name: Message
type: string
name: v1beta1
schema:
openAPIV3Schema:
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
properties:
ansibleLimit:
type: string
ansibleSkipTags:
type: string
ansibleTags:
type: string
nodeSets:
items:
type: string
type: array
required:
- nodeSets
type: object
status:
properties:
conditions:
items:
properties:
lastTransitionTime:
format: date-time
type: string
message:
type: string
reason:
type: string
severity:
type: string
status:
type: string
type:
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
deployed:
type: boolean
type: object
type: object
served: true
storage: true
subresources:
status: {}
20 changes: 6 additions & 14 deletions api/bases/dataplane.openstack.org_openstackdataplanenodesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,6 @@ spec:
- ctlplaneInterface
- deploymentSSHSecret
type: object
deployStrategy:
properties:
ansibleLimit:
type: string
ansibleSkipTags:
type: string
ansibleTags:
type: string
deploy:
default: true
type: boolean
required:
- deploy
type: object
env:
items:
properties:
Expand Down Expand Up @@ -1903,6 +1889,12 @@ spec:
type: object
status:
properties:
CtlplaneSearchDomain:
type: string
DNSClusterAddresses:
items:
type: string
type: array
conditions:
items:
properties:
Expand Down
20 changes: 0 additions & 20 deletions api/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,6 @@ type NodeTemplate struct {
NetworkData *corev1.SecretReference `json:"networkData,omitempty"`
}

// DeployStrategySection for fields controlling the deployment
type DeployStrategySection struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// Deploy boolean to trigger ansible execution
// +kubebuilder:default=true
Deploy bool `json:"deploy"`

// AnsibleTags for ansible execution
// +kubebuilder:validation:Optional
AnsibleTags string `json:"ansibleTags,omitempty"`

// AnsibleLimit for ansible execution
// +kubebuilder:validation:Optional
AnsibleLimit string `json:"ansibleLimit,omitempty"`

// AnsibleSkipTags for ansible execution
// +kubebuilder:validation:Optional
AnsibleSkipTags string `json:"ansibleSkipTags,omitempty"`
}

// NetworkConfigSection is a specification of the Network configuration details
type NetworkConfigSection struct {

Expand Down
26 changes: 26 additions & 0 deletions api/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,30 @@ const (

// InputReadyWaitingMessage not yet ready
InputReadyWaitingMessage = "Waiting for input %s, not yet ready"

// NodeSetDeploymentReadyCondition Status=True condition indicates if the
// NodeSet Deployment is finished and successful.
NodeSetDeploymentReadyCondition string = "%s Deployment ready"

// NodeSetDeploymentReadyMessage ready
NodeSetDeploymentReadyMessage = "%s Deployment ready"

// NodeSetDeploymentReadyWaitingMessage not yet ready
NodeSetDeploymentReadyWaitingMessage = "%s Deployment not yet ready"

// NodeSetDeploymentErrorMessage error
NodeSetDeploymentErrorMessage = "%s Deployment error occurred %s"

// NodeSetServiceDeploymentReadyCondition Status=True condition indicates if the
// NodeSet Deployment is finished and successful.
NodeSetServiceDeploymentReadyCondition string = "%s %s Deployment ready"

// NodeSetServiceDeploymentReadyMessage ready
NodeSetServiceDeploymentReadyMessage = "%s %s Deployment ready"

// NodeSetServiceDeploymentReadyWaitingMessage not yet ready
NodeSetServiceDeploymentReadyWaitingMessage = "%s %s Deployment not yet ready"

// NodeSetServiceDeploymentErrorMessage error
NodeSetServiceDeploymentErrorMessage = "%s %s Deployment error occurred"
)
110 changes: 110 additions & 0 deletions api/v1beta1/openstackdataplanedeployment_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright 2023.
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 (
"fmt"

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// OpenStackDataPlaneDeploymentSpec defines the desired state of OpenStackDataPlaneDeployment
type OpenStackDataPlaneDeploymentSpec struct {

// +kubebuilder:validation:Required
// NodeSets is the list of NodeSets deployed
NodeSets []string `json:"nodeSets"`

// AnsibleTags for ansible execution
// +kubebuilder:validation:Optional
AnsibleTags string `json:"ansibleTags,omitempty"`

// AnsibleLimit for ansible execution
// +kubebuilder:validation:Optional
AnsibleLimit string `json:"ansibleLimit,omitempty"`

// AnsibleSkipTags for ansible execution
// +kubebuilder:validation:Optional
AnsibleSkipTags string `json:"ansibleSkipTags,omitempty"`
}

// OpenStackDataPlaneDeploymentStatus defines the observed state of OpenStackDataPlaneDeployment
type OpenStackDataPlaneDeploymentStatus struct {
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:io.kubernetes.conditions"}
// Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`

// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// Deployed
Deployed bool `json:"deployed,omitempty" optional:"true"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+operator-sdk:csv:customresourcedefinitions:displayName="OpenStack Data Plane Deployments"
//+kubebuilder:resource:shortName=osdpd;osdpdeployment;osdpdeployments
//+kubebuilder:printcolumn:name="NodeSets",type="string",JSONPath=".spec.NodeSets",description="NodeSets"
//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[0].status",description="Status"
//+kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[0].message",description="Message"

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

Spec OpenStackDataPlaneDeploymentSpec `json:"spec,omitempty"`
Status OpenStackDataPlaneDeploymentStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&OpenStackDataPlaneDeployment{}, &OpenStackDataPlaneDeploymentList{})
}

// IsReady - returns true if the OpenStackDataPlaneDeployment is ready
func (instance OpenStackDataPlaneDeployment) IsReady() bool {
return instance.Status.Conditions.IsTrue(condition.ReadyCondition)
}

// InitConditions - Initializes Status Conditons
func (instance *OpenStackDataPlaneDeployment) InitConditions() {
instance.Status.Conditions = condition.Conditions{}

cl := condition.CreateList(
condition.UnknownCondition(condition.DeploymentReadyCondition, condition.InitReason, condition.InitReason),
condition.UnknownCondition(condition.InputReadyCondition, condition.InitReason, condition.InitReason),
)

if instance.Spec.NodeSets != nil {
for _, nodeSet := range instance.Spec.NodeSets {
readyCondition := condition.Type(fmt.Sprintf(NodeSetDeploymentReadyCondition, nodeSet))
cl = append(cl, *condition.UnknownCondition(readyCondition, condition.InitReason, condition.InitReason))
}
}

instance.Status.Conditions.Init(&cl)
instance.Status.Deployed = false
}
22 changes: 6 additions & 16 deletions api/v1beta1/openstackdataplanenodeset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package v1beta1

import (
"fmt"

condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -52,10 +50,6 @@ type OpenStackDataPlaneNodeSetSpec struct {
// Env is a list containing the environment variables to pass to the pod
Env []corev1.EnvVar `json:"env,omitempty"`

// +kubebuilder:validation:Optional
// DeployStrategy section to control how the node is deployed
DeployStrategy DeployStrategySection `json:"deployStrategy,omitempty"`

// +kubebuilder:validation:Optional
// NetworkAttachments is a list of NetworkAttachment resource names to pass to the ansibleee resource
// which allows to connect the ansibleee runner to the given network
Expand Down Expand Up @@ -92,6 +86,12 @@ type OpenStackDataPlaneNodeSetStatus struct {
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// Deployed
Deployed bool `json:"deployed,omitempty" optional:"true"`

// DNSClusterAddresses
DNSClusterAddresses []string `json:"DNSClusterAddresses,omitempty" optional:"true"`

// CtlplaneSearchDomain
CtlplaneSearchDomain string `json:"CtlplaneSearchDomain,omitempty" optional:"true"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -130,13 +130,6 @@ func (instance *OpenStackDataPlaneNodeSet) InitConditions() {
cl = append(cl, *condition.UnknownCondition(NodeSetBareMetalProvisionReadyCondition, condition.InitReason, condition.InitReason))
}

if instance.Spec.Services != nil && instance.Spec.DeployStrategy.Deploy {
for _, service := range instance.Spec.Services {
readyCondition := condition.Type(fmt.Sprintf(ServiceReadyCondition, service))
cl = append(cl, *condition.UnknownCondition(readyCondition, condition.InitReason, condition.InitReason))
}
}

instance.Status.Conditions.Init(&cl)
instance.Status.Deployed = false
}
Expand All @@ -145,9 +138,6 @@ func (instance *OpenStackDataPlaneNodeSet) InitConditions() {
func (instance OpenStackDataPlaneNodeSet) GetAnsibleEESpec() AnsibleEESpec {
return AnsibleEESpec{
NetworkAttachments: instance.Spec.NetworkAttachments,
AnsibleTags: instance.Spec.DeployStrategy.AnsibleTags,
AnsibleLimit: instance.Spec.DeployStrategy.AnsibleLimit,
AnsibleSkipTags: instance.Spec.DeployStrategy.AnsibleSkipTags,
ExtraMounts: instance.Spec.NodeTemplate.ExtraMounts,
Env: instance.Spec.Env,
}
Expand Down
Loading

0 comments on commit ff7bbd6

Please sign in to comment.