Skip to content

Commit

Permalink
Refactor test only CreateCellInternalSecret
Browse files Browse the repository at this point in the history
Not all services need same internal secret
now in tests we can create minimal secret
  • Loading branch information
mrkisaolamb authored and openshift-merge-bot[bot] committed Feb 9, 2024
1 parent 0610489 commit 4555397
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 39 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240201121152-3dcb5d5b24f7
github.com/openstack-k8s-operators/nova-operator/api v0.0.0-20221209164002-f9e6b9363961
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.26.13
k8s.io/apimachinery v0.26.13
Expand Down Expand Up @@ -60,7 +61,6 @@ require (
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
Expand Down
31 changes: 23 additions & 8 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/go-logr/logr"
. "github.com/onsi/gomega"
"golang.org/x/exp/maps"
corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -877,19 +878,33 @@ func GetDefaultNovaNoVNCProxySpec(cell CellNames) map[string]interface{} {
}
}

func CreateCellInternalSecret(cell CellNames) *corev1.Secret {
func CreateCellInternalSecret(cell CellNames, additionalValues map[string][]byte) *corev1.Secret {

secretMap := map[string][]byte{
"ServicePassword": []byte("service-password"),
"CellDatabasePassword": []byte("cell-database-password"),
"transport_url": []byte(fmt.Sprintf("rabbit://%s/fake", cell.CellName)),
}
// (ksambor) this can be replaced with maps.Copy directly from maps
// not experimental package when we move to go 1.21
maps.Copy(secretMap, additionalValues)
return th.CreateSecret(
cell.InternalCellSecretName,
map[string][]byte{
"ServicePassword": []byte("service-password"),
"CellDatabasePassword": []byte("cell-database-password"),
// TODO(gibi): we only need this for cells with metadata
"MetadataSecret": []byte("metadata-secret"),
"transport_url": []byte(fmt.Sprintf("rabbit://%s/fake", cell.CellName)),
},
secretMap,
)
}

func CreateMetadataCellInternalSecret(cell CellNames) *corev1.Secret {
metadataSecret := map[string][]byte{
"MetadataSecret": []byte("metadata-secret"),
}
return CreateCellInternalSecret(cell, metadataSecret)
}

func CreateDefaultCellInternalSecret(cell CellNames) *corev1.Secret {
return CreateCellInternalSecret(cell, map[string][]byte{})
}

func AssertNoVNCProxyDoesNotExist(name types.NamespacedName) {
instance := &novav1.NovaNoVNCProxy{}
Eventually(func(g Gomega) {
Expand Down
14 changes: 7 additions & 7 deletions test/functional/nova_compute_ironic_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var _ = Describe("NovaCompute controller", func() {
When("the Secret is created with all the expected fields", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))
})

It("reports that input is ready", func() {
Expand Down Expand Up @@ -174,7 +174,7 @@ var _ = Describe("NovaCompute controller", func() {
When("NovaCompute is created with a proper Secret", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))
})

It(" reports input ready", func() {
Expand Down Expand Up @@ -263,15 +263,15 @@ var _ = Describe("NovaCompute with ironic diver controller", func() {
DeferCleanup(
k8sClient.Delete,
ctx,
CreateCellInternalSecret(cell1),
CreateDefaultCellInternalSecret(cell1),
)
})
})

When("NovaCompute is created with networkAttachments", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))

spec := GetDefaultNovaComputeSpec(cell1)
spec["networkAttachments"] = []string{"internalapi"}
Expand Down Expand Up @@ -399,7 +399,7 @@ var _ = Describe("NovaCompute with ironic diver controller", func() {
When("NovaCompute with ironic diver is reconfigured", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))

novaCompute := CreateNovaCompute(cell1.NovaComputeName, GetDefaultNovaComputeSpec(cell1))
DeferCleanup(th.DeleteInstance, novaCompute)
Expand Down Expand Up @@ -497,7 +497,7 @@ var _ = Describe("NovaCompute with ironic diver controller", func() {
When("starts zero replicas", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))

spec := GetDefaultNovaComputeSpec(cell1)
spec["replicas"] = 0
Expand Down Expand Up @@ -543,7 +543,7 @@ var _ = Describe("NovaCompute with ironic diver controller", func() {
DeferCleanup(
k8sClient.Delete,
ctx,
CreateCellInternalSecret(cell1),
CreateDefaultCellInternalSecret(cell1),
)
})

Expand Down
2 changes: 1 addition & 1 deletion test/functional/nova_metadata_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ var _ = Describe("NovaMetadata controller", func() {
metadata := CreateNovaMetadata(cell1.MetadataName, spec)
DeferCleanup(th.DeleteInstance, metadata)
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateMetadataCellInternalSecret(cell1))
})
It("generated config with correct local_metadata_per_cell", func() {
th.ExpectCondition(
Expand Down
16 changes: 8 additions & 8 deletions test/functional/nova_novncproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var _ = Describe("NovaNoVNCProxy controller", func() {
When("the Secret is created with all the expected fields", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))
})

It("reports that input is ready", func() {
Expand Down Expand Up @@ -183,7 +183,7 @@ var _ = Describe("NovaNoVNCProxy controller", func() {
When("NoVNCProxy is created with a proper Secret", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))
})

It(" reports input ready", func() {
Expand Down Expand Up @@ -296,7 +296,7 @@ var _ = Describe("NovaNoVNCProxy controller", func() {
spec["networkAttachments"] = []string{"internalapi"}
DeferCleanup(th.DeleteInstance, CreateNovaNoVNCProxy(cell1.NoVNCProxyName, spec))
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))
})

It("reports that the definition is missing", func() {
Expand Down Expand Up @@ -421,7 +421,7 @@ var _ = Describe("NovaNoVNCProxy controller", func() {

BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))

spec := GetDefaultNovaNoVNCProxySpec(cell1)
serviceOverride := map[string]interface{}{
Expand Down Expand Up @@ -466,7 +466,7 @@ var _ = Describe("NovaNoVNCProxy controller", func() {

BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))

spec := GetDefaultNovaNoVNCProxySpec(cell1)
serviceOverride := map[string]interface{}{
Expand Down Expand Up @@ -526,7 +526,7 @@ var _ = Describe("NovaNoVNCProxy controller", func() {
When("NovaNoVNCProxy is reconfigured", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))

noVNCProxy := CreateNovaNoVNCProxy(cell1.NoVNCProxyName, GetDefaultNovaNoVNCProxySpec(cell1))
DeferCleanup(th.DeleteInstance, noVNCProxy)
Expand Down Expand Up @@ -624,7 +624,7 @@ var _ = Describe("NovaNoVNCProxy controller", func() {
When("starts zero replicas", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))

spec := GetDefaultNovaNoVNCProxySpec(cell1)
spec["replicas"] = 0
Expand Down Expand Up @@ -655,7 +655,7 @@ var _ = Describe("NovaNoVNCProxy controller", func() {
}
DeferCleanup(th.DeleteInstance, CreateNovaNoVNCProxy(cell1.NoVNCProxyName, spec))
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell1))
})

It("reports that the CA secret is missing", func() {
Expand Down
12 changes: 6 additions & 6 deletions test/functional/novacell_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var _ = Describe("NovaCell controller", func() {

When("A NovaCell/cell0 CR instance is created", func() {
BeforeEach(func() {
DeferCleanup(k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
DeferCleanup(k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))
DeferCleanup(th.DeleteInstance, CreateNovaCell(cell0.CellCRName, GetDefaultNovaCellSpec(cell0)))
})

Expand Down Expand Up @@ -144,7 +144,7 @@ var _ = Describe("NovaCell controller", func() {
DeferCleanup(
k8sClient.Delete,
ctx,
CreateCellInternalSecret(cell1),
CreateMetadataCellInternalSecret(cell1),
)
spec := GetDefaultNovaCellSpec(cell1)
spec["metadataServiceTemplate"] = map[string]interface{}{
Expand Down Expand Up @@ -467,7 +467,7 @@ var _ = Describe("NovaCell controller", func() {
DeferCleanup(
k8sClient.Delete,
ctx,
CreateCellInternalSecret(cell2),
CreateMetadataCellInternalSecret(cell2),
)
spec := GetDefaultNovaCellSpec(cell2)
spec["noVNCProxyServiceTemplate"] = map[string]interface{}{
Expand Down Expand Up @@ -815,7 +815,7 @@ var _ = Describe("NovaCell controller", func() {
})
When("NovaCell/cell0 is reconfigured", func() {
BeforeEach(func() {
DeferCleanup(k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
DeferCleanup(k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))
DeferCleanup(th.DeleteInstance, CreateNovaCell(cell0.CellCRName, GetDefaultNovaCellSpec(cell0)))
th.SimulateJobSuccess(cell0.DBSyncJobName)

Expand Down Expand Up @@ -903,7 +903,7 @@ var _ = Describe("NovaCell controller", func() {

When("NovaCell/cell1 with metadata is reconfigured", func() {
BeforeEach(func() {
DeferCleanup(k8sClient.Delete, ctx, CreateCellInternalSecret(cell1))
DeferCleanup(k8sClient.Delete, ctx, CreateMetadataCellInternalSecret(cell1))

spec := GetDefaultNovaCellSpec(cell1)
spec["metadataServiceTemplate"] = map[string]interface{}{
Expand Down Expand Up @@ -999,7 +999,7 @@ var _ = Describe("NovaCell controller", func() {
var _ = Describe("NovaCell controller webhook", func() {
It("name is too long", func() {
cell := GetCellNames(novaNames.NovaName, uuid.New().String())
DeferCleanup(k8sClient.Delete, ctx, CreateCellInternalSecret(cell))
DeferCleanup(k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell))

spec := GetDefaultNovaCellSpec(cell)
rawObj := map[string]interface{}{
Expand Down
16 changes: 8 additions & 8 deletions test/functional/novaconductor_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ var _ = Describe("NovaConductor controller", func() {
DeferCleanup(
k8sClient.Delete,
ctx,
CreateCellInternalSecret(cell0),
CreateDefaultCellInternalSecret(cell0),
)
})

Expand Down Expand Up @@ -197,7 +197,7 @@ var _ = Describe("NovaConductor controller", func() {
When("NovConductor is created with a proper Secret", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))

spec := GetDefaultNovaConductorSpec(cell0)
DeferCleanup(th.DeleteInstance, CreateNovaConductor(cell0.ConductorName, spec))
Expand Down Expand Up @@ -320,7 +320,7 @@ var _ = Describe("NovaConductor controller", func() {
When("NovaConductor is configured to preserve jobs", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))

spec := GetDefaultNovaConductorSpec(cell0)
spec["preserveJobs"] = true
Expand Down Expand Up @@ -364,7 +364,7 @@ var _ = Describe("NovaConductor controller", func() {
When("PreserveJobs changed from true to false", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))

spec := GetDefaultNovaConductorSpec(cell0)
spec["preserveJobs"] = true
Expand Down Expand Up @@ -402,7 +402,7 @@ var _ = Describe("NovaConductor controller", func() {
When("NovaConductor is created with networkAttachments", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))

spec := GetDefaultNovaConductorSpec(cell0)
spec["networkAttachments"] = []string{"internalapi"}
Expand Down Expand Up @@ -528,7 +528,7 @@ var _ = Describe("NovaConductor controller", func() {
When("NovaConductor is reconfigured", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))
DeferCleanup(th.DeleteInstance, CreateNovaConductor(cell0.ConductorName, GetDefaultNovaConductorSpec(cell0)))

th.ExpectCondition(
Expand Down Expand Up @@ -663,7 +663,7 @@ var _ = Describe("NovaConductor controller cleaning", func() {
spec["keystoneAuthURL"] = f.Endpoint()
DeferCleanup(th.DeleteInstance, CreateNovaConductor(cell0.ConductorName, spec))
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))
th.SimulateJobSuccess(cell0.DBSyncJobName)
th.SimulateStatefulSetReplicaReady(cell0.ConductorStatefulSetName)
})
Expand All @@ -686,7 +686,7 @@ var _ = Describe("NovaConductor controller", func() {
When("NovaConductor is created with TLS CA cert secret", func() {
BeforeEach(func() {
DeferCleanup(
k8sClient.Delete, ctx, CreateCellInternalSecret(cell0))
k8sClient.Delete, ctx, CreateDefaultCellInternalSecret(cell0))

spec := GetDefaultNovaConductorSpec(cell0)
spec["tls"] = map[string]interface{}{
Expand Down

0 comments on commit 4555397

Please sign in to comment.