Skip to content

Commit

Permalink
[Test-operator] Add test-operator CM
Browse files Browse the repository at this point in the history
This patch adds the test-operator to the openstackcontroler reconcile
loop. The main purpose of this change is to ensure that during the
deployment of controlplane a config map with test-operator-config name
is created. The CM contains information about:

- which images should be used for testing
- name of secret containing clouds.yaml

Depends-On: openstack-k8s-operators/test-operator#105
  • Loading branch information
lpiwowar committed Jun 14, 2024
1 parent fb5ce90 commit 7349e25
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apis/bases/core.openstack.org_openstackcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17476,6 +17476,10 @@ spec:
type: string
telemetryNodeExporterImage:
type: string
testTempestImage:
type: string
testTobikoImage:
type: string
type: object
deployedOVNVersion:
type: string
Expand Down
12 changes: 12 additions & 0 deletions apis/bases/core.openstack.org_openstackversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ spec:
type: string
telemetryNodeExporterImage:
type: string
testTempestImage:
type: string
testTobikoImage:
type: string
type: object
targetVersion:
type: string
Expand Down Expand Up @@ -394,6 +398,10 @@ spec:
type: string
telemetryNodeExporterImage:
type: string
testTempestImage:
type: string
testTobikoImage:
type: string
type: object
type: object
containerImages:
Expand Down Expand Up @@ -560,6 +568,10 @@ spec:
type: string
telemetryNodeExporterImage:
type: string
testTempestImage:
type: string
testTobikoImage:
type: string
type: object
deployedVersion:
type: string
Expand Down
12 changes: 12 additions & 0 deletions apis/core/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ const (

// OpenStackControlPlaneExposeBarbicanReadyCondition Status=True condition which indicates if Barbican is exposed via a route
OpenStackControlPlaneExposeBarbicanReadyCondition condition.Type = "OpenStackControlPlaneExposeBarbicanReady"

// OpenStackControlPlaneTestCMReadyCondition Status=True condition which indicates if Test operator CM is ready
OpenStackControlPlaneTestCMReadyCondition condition.Type = "OpenStackControlPlaneTestCMReadyCondition"
)

// Common Messages used by API objects.
Expand Down Expand Up @@ -429,6 +432,15 @@ const (

// OpenStackControlPlaneCAReadyErrorMessage
OpenStackControlPlaneCustomTLSReadyErrorMessage = "OpenStackControlPlane custom TLS cert secret %s error occured %s"

// OpenStackControlPlaneTestCMReadyErrorMessage
OpenStackControlPlaneTestCMReadyErrorMessage = "OpenStackControlPlane Test Operator CM error occured %s"

// OpenStackControlPlaneTestCMReadyMessage
OpenStackControlPlaneTestCMReadyMessage = "OpenStackControlPlane Test Operator CM is available"

// OpenStackControlPlaneTestCMWaitingMessage
OpenStackControlPlaneTestCMWaitingMessage = "OpenStackControlPlane Test Operator CM is waiting for %s"
)

// Version Conditions used by API objects.
Expand Down
2 changes: 2 additions & 0 deletions apis/core/v1beta1/openstackversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type ContainerTemplate struct {
SwiftObjectImage *string `json:"swiftObjectImage,omitempty"`
SwiftProxyImage *string `json:"swiftProxyImage,omitempty"`
TelemetryNodeExporterImage *string `json:"telemetryNodeExporterImage,omitempty"`
TestTempestImage *string `json:"testTempestImage,omitempty"`
TestTobikoImage *string `json:"testTobikoImage,omitempty"`
}

// OpenStackVersionStatus defines the observed state of OpenStackVersion
Expand Down
10 changes: 10 additions & 0 deletions apis/core/v1beta1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions cmd/csv-merger/csv-merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var (
octaviaCsv = flag.String("octavia-csv", "", "Octavia CSV filename")
designateCsv = flag.String("designate-csv", "", "Designate CSV filename")
barbicanCsv = flag.String("barbican-csv", "", "Barbican CSV filename")
testCsv = flag.String("test-csv", "", "Test Operator CSV filename")
csvOverrides = flag.String("csv-overrides", "", "CSV like string with punctual changes that will be recursively applied (if possible)")
importEnvFiles = flag.String("import-env-files", "", "Comma separated list of file names to read default operator ENVs from. Used for inter-bundle ENV merging.")
exportEnvFile = flag.String("export-env-file", "", "Name the external file to write operator ENVs to. Used for inter-bundle ENV merging.")
Expand Down Expand Up @@ -144,6 +145,7 @@ func main() {
*octaviaCsv,
*designateCsv,
*barbicanCsv,
*testCsv,
}

csvVersion := os.Getenv("CSV_VERSION")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17476,6 +17476,10 @@ spec:
type: string
telemetryNodeExporterImage:
type: string
testTempestImage:
type: string
testTobikoImage:
type: string
type: object
deployedOVNVersion:
type: string
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/core.openstack.org_openstackversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ spec:
type: string
telemetryNodeExporterImage:
type: string
testTempestImage:
type: string
testTobikoImage:
type: string
type: object
targetVersion:
type: string
Expand Down Expand Up @@ -394,6 +398,10 @@ spec:
type: string
telemetryNodeExporterImage:
type: string
testTempestImage:
type: string
testTobikoImage:
type: string
type: object
type: object
containerImages:
Expand Down Expand Up @@ -560,6 +568,10 @@ spec:
type: string
telemetryNodeExporterImage:
type: string
testTempestImage:
type: string
testTobikoImage:
type: string
type: object
deployedVersion:
type: string
Expand Down
7 changes: 7 additions & 0 deletions controllers/core/openstackcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ func (r *OpenStackControlPlaneReconciler) reconcileNormal(ctx context.Context, i
return ctrlResult, nil
}

ctrlResult, err = openstack.ReconcileTest(ctx, instance, version, helper)
if err != nil {
return ctrl.Result{}, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

return ctrl.Result{}, nil
}

Expand Down
1 change: 1 addition & 0 deletions hack/bundle-cache-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ bin/csv-merger \
--octavia-csv=$CSV_DIR/octavia-operator.clusterserviceversion.yaml \
--designate-csv=$CSV_DIR/designate-operator.clusterserviceversion.yaml \
--barbican-csv=$CSV_DIR/barbican-operator.clusterserviceversion.yaml \
--test-csv=$CSV_DIR/test-operator.clusterserviceversion.yaml \
--base-csv=config/manifests/bases/openstack-operator.clusterserviceversion.yaml | tee "$EXTRACT_DIR/out.yaml"

# cleanup our temporary dir used for extraction
Expand Down
4 changes: 3 additions & 1 deletion hack/export_related_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ export RELATED_IMAGE_EDPM_NEUTRON_METADATA_AGENT_IMAGE_URL_DEFAULT=quay.io/podif
export RELATED_IMAGE_EDPM_NEUTRON_OVN_AGENT_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-neutron-ovn-agent:current-podified
export RELATED_IMAGE_EDPM_NEUTRON_SRIOV_AGENT_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-neutron-sriov-agent:current-podified
export RELATED_IMAGE_EDPM_OVN_BGP_AGENT_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-ovn-bgp-agent:current-podified
export RELATED_IMAGE_EDPM_NODE_EXPORTER_IMAGE_URL_DEFAULT=quay.io/prometheus/node-exporter:v1.5.0
export RELATED_IMAGE_EDPM_NODE_EXPORTER_IMAGE_URL_DEFAULT=quay.io/prometheus/node-exporter:v1.5
export RELATED_IMAGE_TEST_TEMPEST_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-tempest-all:current-podified
export RELATED_IMAGE_TEST_TOBIKO_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-tobiko:current-podified
77 changes: 77 additions & 0 deletions pkg/openstack/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package openstack

import (
"context"
"time"

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"

corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
ctrl "sigs.k8s.io/controller-runtime"
)

const (
// config map generated by Keyston operator containing clouds.yaml
CloudsConfigMap = "openstack-config"
TestOperatorConfigMap = "test-operator-config"

TempestImageKey = "tempest-image"
TobikoImageKey = "tobiko-image"
CloudsKey = "clouds-secret-name"
)

func ReconcileTest(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *helper.Helper) (ctrl.Result, error) {
customData := map[string]string{
TempestImageKey: *version.Status.ContainerImages.TestTempestImage,
TobikoImageKey: *version.Status.ContainerImages.TestTobikoImage,
CloudsKey: CloudsConfigMap,
}

_, _, err := configmap.GetConfigMapAndHashWithName(ctx, helper, CloudsConfigMap, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackControlPlaneTestCMReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
corev1beta1.OpenStackControlPlaneTestCMWaitingMessage,
CloudsConfigMap))

timeout := time.Second * 10
return ctrl.Result{RequeueAfter: timeout}, nil
}
}

cms := []util.Template{
{
Name: TestOperatorConfigMap,
Namespace: instance.Namespace,
InstanceType: instance.Kind,
Labels: nil,
ConfigOptions: nil,
CustomData: customData,
},
}

if err := configmap.EnsureConfigMaps(ctx, helper, instance, cms, nil); err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
corev1beta1.OpenStackControlPlaneTestCMReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
corev1beta1.OpenStackControlPlaneTestCMReadyErrorMessage,
err.Error()))

return ctrl.Result{}, err
}

instance.Status.Conditions.Set(condition.TrueCondition(
corev1beta1.OpenStackControlPlaneTestCMReadyCondition,
corev1beta1.OpenStackControlPlaneTestCMReadyMessage,
))

return ctrl.Result{}, nil
}
2 changes: 2 additions & 0 deletions pkg/openstack/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func GetContainerImages(defaults *corev1beta1.ContainerDefaults, instance corev1
SwiftObjectImage: getImg(instance.Spec.CustomContainerImages.SwiftObjectImage, defaults.SwiftObjectImage),
SwiftProxyImage: getImg(instance.Spec.CustomContainerImages.SwiftProxyImage, defaults.SwiftProxyImage),
TelemetryNodeExporterImage: getImg(instance.Spec.CustomContainerImages.TelemetryNodeExporterImage, defaults.TelemetryNodeExporterImage),
TestTempestImage: getImg(instance.Spec.CustomContainerImages.TestTempestImage, defaults.TestTempestImage),
TestTobikoImage: getImg(instance.Spec.CustomContainerImages.TestTobikoImage, defaults.TestTobikoImage),
}}
if containerImages.CinderVolumeImages == nil {
containerImages.CinderVolumeImages = make(map[string]*string)
Expand Down

0 comments on commit 7349e25

Please sign in to comment.