Skip to content

Commit

Permalink
Merge pull request openstack-k8s-operators#293 from gibizer/compute-ctor
Browse files Browse the repository at this point in the history
[Compute] Add NewNovaExternalComputeSpec default ctor
  • Loading branch information
openshift-merge-robot authored Mar 20, 2023
2 parents c3b5b02 + 4d0ff5f commit f81236c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/v1beta1/novaexternalcompute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,21 @@ func (c NovaExternalCompute) IsReady() bool {
readyCond := c.Status.Conditions.Get(condition.ReadyCondition)
return readyCond != nil && readyCond.Status == corev1.ConditionTrue
}

// NewNovaExternalComputeSpec returns a NovaExternalComputeSpec where the fields are defaulted according
// to the CRD definition
func NewNovaExternalComputeSpec(inventoryConfigMapName string, sshKeySecretName string) NovaExternalComputeSpec {
return NovaExternalComputeSpec{
NovaInstance: "nova",
CellName: "cell1",
CustomServiceConfig: "",
DefaultConfigOverwrite: nil,
InventoryConfigMapName: inventoryConfigMapName,
SSHKeySecretName: sshKeySecretName,
Deploy: true,
NovaComputeContainerImage: "quay.io/tripleozedcentos9/openstack-nova-compute:current-tripleo",
NovaLibvirtContainerImage: "quay.io/tripleozedcentos9/openstack-nova-libvirt:current-tripleo",
AnsibleEEContainerImage: "quay.io/openstack-k8s-operators/openstack-ansibleee-runner:latest",
NetworkAttachments: nil,
}
}
29 changes: 29 additions & 0 deletions test/functional/novaexternalcompute_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
. "github.com/openstack-k8s-operators/lib-common/modules/test/helpers"
corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

novav1 "github.com/openstack-k8s-operators/nova-operator/api/v1beta1"
Expand Down Expand Up @@ -377,4 +378,32 @@ var _ = Describe("NovaExternalCompute", func() {
)
})
})
When("created as unstructured and created from golang", func() {
It("has the same defaults", func() {
computeNameUnstructured := types.NamespacedName{Namespace: computeName.Namespace, Name: "compute-default-unstructured"}
computeNameGolang := types.NamespacedName{Namespace: computeName.Namespace, Name: "compute-default-golang"}
CreateNovaExternalCompute(
computeNameUnstructured,
map[string]interface{}{
"inventoryConfigMapName": "foo-inventory-configmap",
"sshKeySecretName": "foo-ssh-key-secret",
})
computeFromUnstructured := GetNovaExternalCompute(computeNameUnstructured)
DeferCleanup(DeleteInstance, computeFromUnstructured)

spec := novav1.NewNovaExternalComputeSpec("foo-inventory-configmap", "foo-ssh-key-secret")
err := k8sClient.Create(ctx, &novav1.NovaExternalCompute{
ObjectMeta: metav1.ObjectMeta{
Name: computeNameGolang.Name,
Namespace: computeNameGolang.Namespace,
},
Spec: spec,
})
Expect(err).ShouldNot(HaveOccurred())
computeFromGolang := GetNovaExternalCompute(computeNameGolang)
DeferCleanup(DeleteInstance, computeFromGolang)

Expect(computeFromUnstructured.Spec).To(Equal(computeFromGolang.Spec))
})
})
})

0 comments on commit f81236c

Please sign in to comment.