Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Drop OpenStackDataPlaneService.Spec.Label field
Browse files Browse the repository at this point in the history
The field was proving to be redundant, since it always matched the name
of the Service. It was only really being used to enforce a length, that
logic is moved to a function to just use the first 53 chars of the name,
then the field can be dropped.

Signed-off-by: James Slagle <[email protected]>
  • Loading branch information
slagle committed Feb 14, 2024
1 parent 798e16b commit e7ff71d
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ spec:
items:
type: string
type: array
label:
maxLength: 53
pattern: '[a-z]([-a-z0-9]*[a-z0-9])'
type: string
openStackAnsibleEERunnerImage:
type: string
play:
Expand Down
9 changes: 0 additions & 9 deletions api/v1beta1/openstackdataplaneservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ type OpenstackDataPlaneServiceCert struct {

// OpenStackDataPlaneServiceSpec defines the desired state of OpenStackDataPlaneService
type OpenStackDataPlaneServiceSpec struct {
// Label to use for service.
// Must follow DNS952 subdomain conventions.
// Since we are using it to generate the pod name,
// we need to keep it short.
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Pattern="[a-z]([-a-z0-9]*[a-z0-9])"
// +kubebuilder:validation:MaxLength=53
Label string `json:"label,omitempty"`

// Play is an inline playbook contents that ansible will run on execution.
Play string `json:"play,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ spec:
items:
type: string
type: array
label:
maxLength: 53
pattern: '[a-z]([-a-z0-9]*[a-z0-9])'
type: string
openStackAnsibleEERunnerImage:
type: string
play:
Expand Down
5 changes: 0 additions & 5 deletions docs/assemblies/custom_resources.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,6 @@ OpenStackDataPlaneServiceSpec defines the desired state of OpenStackDataPlaneSer
|===
| Field | Description | Scheme | Required
| label
| Label to use for service. Must follow DNS952 subdomain conventions. Since we are using it to generate the pod name, we need to keep it short.
| string
| false
| play
| Play is an inline playbook contents that ansible will run on execution.
| string
Expand Down
6 changes: 1 addition & 5 deletions pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func (d *Deployer) Deploy(services []string) (*ctrl.Result, error) {
var readyWaitingMessage string
var readyErrorMessage string
var deployName string
var deployLabel string

// Save a copy of the original ExtraMounts so it can be reset after each
// service deployment
Expand All @@ -71,7 +70,6 @@ func (d *Deployer) Deploy(services []string) (*ctrl.Result, error) {
return &ctrl.Result{}, err
}
deployName = foundService.Name
deployLabel = foundService.Spec.Label
readyCondition = condition.Type(fmt.Sprintf(dataplanev1.NodeSetServiceDeploymentReadyCondition, service))
readyWaitingMessage = fmt.Sprintf(dataplanev1.NodeSetServiceDeploymentReadyWaitingMessage, deployName)
readyMessage = fmt.Sprintf(dataplanev1.NodeSetServiceDeploymentReadyMessage, deployName)
Expand Down Expand Up @@ -103,7 +101,6 @@ func (d *Deployer) Deploy(services []string) (*ctrl.Result, error) {
readyWaitingMessage,
readyErrorMessage,
deployName,
deployLabel,
foundService,
)

Expand All @@ -127,7 +124,6 @@ func (d *Deployer) ConditionalDeploy(
readyWaitingMessage string,
readyErrorMessage string,
deployName string,
deployLabel string,
foundService dataplanev1.OpenStackDataPlaneService,
) error {
var err error
Expand All @@ -151,7 +147,7 @@ func (d *Deployer) ConditionalDeploy(
}

if nsConditions.IsFalse(readyCondition) {
ansibleEE, err := dataplaneutil.GetAnsibleExecution(d.Ctx, d.Helper, d.Deployment, deployLabel)
ansibleEE, err := dataplaneutil.GetAnsibleExecution(d.Ctx, d.Helper, d.Deployment, foundService.Name)
if err != nil {
// Return nil if we don't have AnsibleEE available yet
if k8s_errors.IsNotFound(err) {
Expand Down
25 changes: 16 additions & 9 deletions pkg/util/ansible_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,20 @@ func AnsibleExecution(
var err error
var cmdLineArguments strings.Builder

ansibleEE, err := GetAnsibleExecution(ctx, helper, obj, service.Spec.Label)
ansibleEE, err := GetAnsibleExecution(ctx, helper, obj, service.Name)
if err != nil && !k8serrors.IsNotFound(err) {
return err
}
if ansibleEE == nil {
var executionName string
if len(service.Spec.Label) > 0 {
executionName = fmt.Sprintf("%s-%s", service.Spec.Label, obj.GetName())
} else {
executionName = obj.GetName()
}

executionName := fmt.Sprintf("%s-%s", GetAnsibleExecutionNamePrefix(service), obj.GetName())
ansibleEE = &ansibleeev1.OpenStackAnsibleEE{
ObjectMeta: metav1.ObjectMeta{
Name: executionName,
Namespace: obj.GetNamespace(),
Labels: map[string]string{
service.Spec.Label: string(obj.GetUID()),
"osdpd": obj.GetName(),
service.Name: string(obj.GetUID()),
"osdpd": obj.GetName(),
},
},
}
Expand Down Expand Up @@ -197,3 +193,14 @@ func GetAnsibleExecution(ctx context.Context, helper *helper.Helper, obj client.

return ansibleEE, nil
}

// GetAnsibleExecutionNamePrefix compute the name of the AnsibleEE
func GetAnsibleExecutionNamePrefix(service *dataplanev1.OpenStackDataPlaneService) string {
var executionNamePrefix string
if len(service.Name) > AnsibleExecutionServiceNameLen {
executionNamePrefix = service.Name[:AnsibleExecutionServiceNameLen]
} else {
executionNamePrefix = service.Name
}
return executionNamePrefix
}
22 changes: 22 additions & 0 deletions pkg/util/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
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 util

const (
// AnsibleExecutionServiceNameLen max length for the ansibleEE service name prefix
AnsibleExecutionServiceNameLen = 53
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
dataplanev1 "github.com/openstack-k8s-operators/dataplane-operator/api/v1beta1"
dataplaneutil "github.com/openstack-k8s-operators/dataplane-operator/pkg/util"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
ansibleeev1 "github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
Expand Down Expand Up @@ -144,11 +145,12 @@ var _ = Describe("Dataplane Deployment Test", func() {
Namespace: namespace,
}
service := GetService(dataplaneServiceName)
executionName := dataplaneutil.GetAnsibleExecutionNamePrefix(service)
//Retrieve service AnsibleEE and set JobStatus to Successful
Eventually(func(g Gomega) {
// Make an AnsibleEE name for each service
ansibleeeName := types.NamespacedName{
Name: fmt.Sprintf("%s-%s", service.Spec.Label, dataplaneDeploymentName.Name),
Name: fmt.Sprintf("%s-%s", executionName, dataplaneDeploymentName.Name),
Namespace: dataplaneDeploymentName.Namespace,
}
ansibleEE := &ansibleeev1.OpenStackAnsibleEE{
Expand Down
1 change: 0 additions & 1 deletion tests/kuttl/tests/dataplane-service-config/00-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ kind: OpenStackDataPlaneService
metadata:
name: kuttl-service
spec:
label: kuttl-service
play: |
- hosts: localhost
gather_facts: no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ status:
apiVersion: ansibleee.openstack.org/v1beta1
kind: OpenStackAnsibleEE
metadata:
name: dp-custom-image-service-edpm-compute-no-nodes
name: custom-image-service-edpm-compute-no-nodes
namespace: openstack
ownerReferences:
- apiVersion: dataplane.openstack.org/v1beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: OpenStackDataPlaneService
metadata:
name: custom-image-service
spec:
label: dp-custom-image-service
openStackAnsibleEERunnerImage: example.com/repo/runner-image:latest
role:
name: "test role"
Expand Down

0 comments on commit e7ff71d

Please sign in to comment.