From 35d94bb7f0adbe2bfe76c14ea5ae6a4a0c05cdd1 Mon Sep 17 00:00:00 2001 From: Arnau Verdaguer Date: Tue, 30 Jul 2024 18:06:11 +0200 Subject: [PATCH] [ovn-controller] Don't create ovn-controller ds if no NicMappings set Resolves: OSPRH-7463 --- config/samples/nad_principal.yaml | 17 ++ config/samples/nncp_create_bridge.yaml | 26 +++ controllers/ovncontroller_controller.go | 119 ++++++++++++++ tests/functional/base_test.go | 10 ++ .../ovncontroller_controller_test.go | 152 +++++++++++++++++- tests/kuttl/common/assert_ovn_controller.yaml | 35 ++++ .../common/assert_sample_deployment.yaml | 64 +++----- .../attach_nic_mappings_ovn_controller.yaml} | 0 tests/kuttl/common/create_nad.yaml | 5 + tests/kuttl/common/create_oc_bridge.yaml | 15 ++ .../common/scripts/check_cluster_status.sh | 7 +- .../02-create-principal-bridge.yaml | 1 + tests/kuttl/tests/ovn_config/03-assert.yaml | 14 +- .../ovn_config/03-enable-ovncontroller.yaml | 1 + .../{02-assert.yaml => 04-assert.yaml} | 0 .../{02-az-patch.yaml => 04-az-patch.yaml} | 0 tests/kuttl/tests/ovn_config/05-assert.yaml | 13 ++ ...ller.yaml => 05-remove-ovncontroller.yaml} | 0 .../kuttl/tests/ovn_db_delete/02-assert.yaml | 47 ------ .../tests/ovn_db_delete/02-create-bridge.yaml | 1 + .../kuttl/tests/ovn_db_delete/03-assert.yaml | 10 +- .../03-enable-ovncontroller.yaml | 1 + .../kuttl/tests/ovn_db_delete/04-assert.yaml | 48 +++++- ...2-scale-ovndb.yaml => 04-scale-ovndb.yaml} | 0 .../kuttl/tests/ovn_db_delete/05-assert.yaml | 12 +- .../kuttl/tests/ovn_db_delete/06-assert.yaml | 1 + ...4-delete-pods.yaml => 06-delete-pods.yaml} | 0 .../kuttl/tests/ovn_db_delete/09-assert.yaml | 10 +- .../{08-assert.yaml => 10-assert.yaml} | 0 ...wn-ovndb.yaml => 10-scale-down-ovndb.yaml} | 0 .../kuttl/tests/ovn_db_delete/11-assert.yaml | 9 ++ ...0-cleanup-ovn.yaml => 12-cleanup-ovn.yaml} | 0 .../{10-errors.yaml => 12-errors.yaml} | 0 .../02-create-principal-bridge.yaml | 1 + .../tests/ovn_nicmappings/03-assert.yaml | 20 +-- .../03-enable-ovncontroller.yaml | 1 + ...04-new-network-attachment-definition.yaml} | 1 - .../tests/ovn_nicmappings/05-assert.yaml | 19 +++ .../05-nicmappings-patch-datacentre2.yaml | 10 ++ .../{04-assert.yaml => 06-assert.yaml} | 0 ... => 06-nicmappings-patch-datacentre3.yaml} | 0 ...6-cleanup-ovn.yaml => 08-cleanup-ovn.yaml} | 0 .../{06-errors.yaml => 08-errors.yaml} | 0 .../02-create-principal-bridge.yaml | 1 + .../tests/ovn_restart_flow/03-assert.yaml | 2 +- .../03-enable-ovncontroller.yaml | 1 + ...lows.yaml => 04-add-bridge-and-flows.yaml} | 0 .../tests/ovn_restart_flow/05-assert.yaml | 1 + ...3-delete-pods.yaml => 05-delete-pods.yaml} | 0 ...sent.yaml => 06-assert-flows-present.yaml} | 0 ...6-cleanup-ovn.yaml => 08-cleanup-ovn.yaml} | 0 .../{06-errors.yaml => 08-errors.yaml} | 0 .../ovn_scale/02-create-principal-bridge.yaml | 1 + tests/kuttl/tests/ovn_scale/03-assert.yaml | 27 +--- .../ovn_scale/03-enable-ovncontroller.yaml | 1 + tests/kuttl/tests/ovn_scale/04-assert.yaml | 12 +- tests/kuttl/tests/ovn_scale/04-errors.yaml | 7 - ...ovnnorthd.yaml => 04-scale-ovnnorthd.yaml} | 0 .../{02-assert.yaml => 05-assert.yaml} | 10 +- ...rthd.yaml => 05-scale-down-ovnnorthd.yaml} | 0 tests/kuttl/tests/ovn_scale/06-assert.yaml | 22 +++ tests/kuttl/tests/ovn_scale/06-errors.yaml | 8 +- ...yaml => 06-scale-down-zero-ovnnorthd.yaml} | 0 .../{05-errors.yaml => 07-errors.yaml} | 0 ... => 07-scale-down-pods-ovncontroller.yaml} | 0 ...6-cleanup-ovn.yaml => 08-cleanup-ovn.yaml} | 0 tests/kuttl/tests/ovn_scale/08-errors.yaml | 1 + 67 files changed, 569 insertions(+), 195 deletions(-) create mode 100644 config/samples/nad_principal.yaml create mode 100644 config/samples/nncp_create_bridge.yaml create mode 100644 tests/kuttl/common/assert_ovn_controller.yaml rename tests/kuttl/{tests/ovn_nicmappings/03-nicmappings-patch-datacentre2.yaml => common/attach_nic_mappings_ovn_controller.yaml} (100%) create mode 100644 tests/kuttl/common/create_nad.yaml create mode 100644 tests/kuttl/common/create_oc_bridge.yaml create mode 120000 tests/kuttl/tests/ovn_config/02-create-principal-bridge.yaml mode change 100644 => 120000 tests/kuttl/tests/ovn_config/03-assert.yaml create mode 120000 tests/kuttl/tests/ovn_config/03-enable-ovncontroller.yaml rename tests/kuttl/tests/ovn_config/{02-assert.yaml => 04-assert.yaml} (100%) rename tests/kuttl/tests/ovn_config/{02-az-patch.yaml => 04-az-patch.yaml} (100%) create mode 100644 tests/kuttl/tests/ovn_config/05-assert.yaml rename tests/kuttl/tests/ovn_config/{03-remove-ovncontroller.yaml => 05-remove-ovncontroller.yaml} (100%) delete mode 100644 tests/kuttl/tests/ovn_db_delete/02-assert.yaml create mode 120000 tests/kuttl/tests/ovn_db_delete/02-create-bridge.yaml mode change 100644 => 120000 tests/kuttl/tests/ovn_db_delete/03-assert.yaml create mode 120000 tests/kuttl/tests/ovn_db_delete/03-enable-ovncontroller.yaml mode change 120000 => 100644 tests/kuttl/tests/ovn_db_delete/04-assert.yaml rename tests/kuttl/tests/ovn_db_delete/{02-scale-ovndb.yaml => 04-scale-ovndb.yaml} (100%) mode change 120000 => 100644 tests/kuttl/tests/ovn_db_delete/05-assert.yaml create mode 120000 tests/kuttl/tests/ovn_db_delete/06-assert.yaml rename tests/kuttl/tests/ovn_db_delete/{04-delete-pods.yaml => 06-delete-pods.yaml} (100%) mode change 100644 => 120000 tests/kuttl/tests/ovn_db_delete/09-assert.yaml rename tests/kuttl/tests/ovn_db_delete/{08-assert.yaml => 10-assert.yaml} (100%) rename tests/kuttl/tests/ovn_db_delete/{08-scale-down-ovndb.yaml => 10-scale-down-ovndb.yaml} (100%) create mode 100644 tests/kuttl/tests/ovn_db_delete/11-assert.yaml rename tests/kuttl/tests/ovn_db_delete/{10-cleanup-ovn.yaml => 12-cleanup-ovn.yaml} (100%) rename tests/kuttl/tests/ovn_db_delete/{10-errors.yaml => 12-errors.yaml} (100%) create mode 120000 tests/kuttl/tests/ovn_nicmappings/02-create-principal-bridge.yaml mode change 100644 => 120000 tests/kuttl/tests/ovn_nicmappings/03-assert.yaml create mode 120000 tests/kuttl/tests/ovn_nicmappings/03-enable-ovncontroller.yaml rename tests/kuttl/tests/ovn_nicmappings/{02-new-network-attachment-definition.yaml => 04-new-network-attachment-definition.yaml} (65%) create mode 100644 tests/kuttl/tests/ovn_nicmappings/05-assert.yaml create mode 100644 tests/kuttl/tests/ovn_nicmappings/05-nicmappings-patch-datacentre2.yaml rename tests/kuttl/tests/ovn_nicmappings/{04-assert.yaml => 06-assert.yaml} (100%) rename tests/kuttl/tests/ovn_nicmappings/{04-nicmappings-patch-datacentre3.yaml => 06-nicmappings-patch-datacentre3.yaml} (100%) rename tests/kuttl/tests/ovn_nicmappings/{06-cleanup-ovn.yaml => 08-cleanup-ovn.yaml} (100%) rename tests/kuttl/tests/ovn_nicmappings/{06-errors.yaml => 08-errors.yaml} (100%) create mode 120000 tests/kuttl/tests/ovn_restart_flow/02-create-principal-bridge.yaml create mode 120000 tests/kuttl/tests/ovn_restart_flow/03-enable-ovncontroller.yaml rename tests/kuttl/tests/ovn_restart_flow/{02-add-bridge-and-flows.yaml => 04-add-bridge-and-flows.yaml} (100%) create mode 120000 tests/kuttl/tests/ovn_restart_flow/05-assert.yaml rename tests/kuttl/tests/ovn_restart_flow/{03-delete-pods.yaml => 05-delete-pods.yaml} (100%) rename tests/kuttl/tests/ovn_restart_flow/{04-assert-flows-present.yaml => 06-assert-flows-present.yaml} (100%) rename tests/kuttl/tests/ovn_restart_flow/{06-cleanup-ovn.yaml => 08-cleanup-ovn.yaml} (100%) rename tests/kuttl/tests/ovn_restart_flow/{06-errors.yaml => 08-errors.yaml} (100%) create mode 120000 tests/kuttl/tests/ovn_scale/02-create-principal-bridge.yaml mode change 100644 => 120000 tests/kuttl/tests/ovn_scale/03-assert.yaml create mode 120000 tests/kuttl/tests/ovn_scale/03-enable-ovncontroller.yaml delete mode 100644 tests/kuttl/tests/ovn_scale/04-errors.yaml rename tests/kuttl/tests/ovn_scale/{02-scale-ovnnorthd.yaml => 04-scale-ovnnorthd.yaml} (100%) rename tests/kuttl/tests/ovn_scale/{02-assert.yaml => 05-assert.yaml} (73%) rename tests/kuttl/tests/ovn_scale/{03-scale-down-ovnnorthd.yaml => 05-scale-down-ovnnorthd.yaml} (100%) create mode 100644 tests/kuttl/tests/ovn_scale/06-assert.yaml mode change 120000 => 100644 tests/kuttl/tests/ovn_scale/06-errors.yaml rename tests/kuttl/tests/ovn_scale/{04-scale-down-zero-ovnnorthd.yaml => 06-scale-down-zero-ovnnorthd.yaml} (100%) rename tests/kuttl/tests/ovn_scale/{05-errors.yaml => 07-errors.yaml} (100%) rename tests/kuttl/tests/ovn_scale/{05-scale-down-pods-ovncontroller.yaml => 07-scale-down-pods-ovncontroller.yaml} (100%) rename tests/kuttl/tests/ovn_scale/{06-cleanup-ovn.yaml => 08-cleanup-ovn.yaml} (100%) create mode 120000 tests/kuttl/tests/ovn_scale/08-errors.yaml diff --git a/config/samples/nad_principal.yaml b/config/samples/nad_principal.yaml new file mode 100644 index 00000000..bc0cd22b --- /dev/null +++ b/config/samples/nad_principal.yaml @@ -0,0 +1,17 @@ +apiVersion: k8s.cni.cncf.io/v1 +kind: NetworkAttachmentDefinition +metadata: + annotations: + labels: + osp/net: principal + service: ovn-controller + name: principal +spec: + config: | + { + "cniVersion": "0.3.1", + "name": "principal", + "type": "bridge", + "bridge": "ospbrprin", + "ipam": {} + } diff --git a/config/samples/nncp_create_bridge.yaml b/config/samples/nncp_create_bridge.yaml new file mode 100644 index 00000000..e28c24a3 --- /dev/null +++ b/config/samples/nncp_create_bridge.yaml @@ -0,0 +1,26 @@ +apiVersion: nmstate.io/v1 +kind: NodeNetworkConfigurationPolicy +metadata: + labels: + osp/interface: enp6s0 + name: enp6s0-crc +spec: + desiredState: + interfaces: + - description: Configuring Bridge + name: osptestbr + mtu: 1500 + type: linux-bridge + state: up + bridge: + options: + stp: + enabled: false + ipv4: + address: + - ip: 192.168.222.10 + prefix-length: 24 + enabled: true + dhcp: false + ipv6: + enabled: false diff --git a/controllers/ovncontroller_controller.go b/controllers/ovncontroller_controller.go index faeedb5b..5b37a523 100644 --- a/controllers/ovncontroller_controller.go +++ b/controllers/ovncontroller_controller.go @@ -313,6 +313,68 @@ func (r *OVNControllerReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Re return ctrl.Result{}, nil } +// use lib_commons.daemonset.GetDaemonSetWithName once +// https://github.com/openstack-k8s-operators/lib-common/pull/551 +// is merged +func getDaemonSetWithName( + ctx context.Context, + h *helper.Helper, + name string, + namespace string, +) (*appsv1.DaemonSet, error) { + + dset := &appsv1.DaemonSet{} + err := h.GetClient().Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, dset) + if err != nil { + return dset, err + } + + return dset, nil +} + +func (r *OVNControllerReconciler) ensureCMDeleted( + ctx context.Context, + h *helper.Helper, + instance *ovnv1.OVNController, +) error { + // Delete, if they exist + cms := []string{"ovncontroller-config", "ovncontroller-scripts"} + for _, cmName := range cms { + err := r.deleteConfigMaps(ctx, h, cmName, instance.Namespace) + if err != nil && !k8s_errors.IsNotFound(err) { + return fmt.Errorf("could not delete config map %v: %w", cmName, err) + } + + } + return nil +} + +func ensureDSDeleted( + ctx context.Context, + h *helper.Helper, + instance *ovnv1.OVNController, +) error { + // Delete, if they exist, ovn and ovs ds + daemonsets := []string{"ovn-controller", "ovn-controller-ovs"} + for _, dsName := range daemonsets { + ds, err := getDaemonSetWithName(ctx, h, dsName, instance.Namespace) + if err != nil && !k8s_errors.IsNotFound(err) { + return fmt.Errorf("error getting %s daemonset: %w", dsName, err) + } else if err != nil && k8s_errors.IsNotFound(err) { + // Already deleted + continue + } + + // Delete ds + err = h.GetClient().Delete(ctx, ds) + if err != nil && !k8s_errors.IsNotFound(err) { + return fmt.Errorf("error deleting daemonset %s: %w", ds.Name, err) + } + } + + return nil +} + func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance *ovnv1.OVNController, helper *helper.Helper) (ctrl.Result, error) { Log := r.GetLogger(ctx) @@ -339,6 +401,40 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance return rbacResult, nil } + // if ovn-controller has no nicMappings, it's useless create daemonset on + // OC nodes, since it won't do anything. + if len(instance.Spec.NicMappings) == 0 { + // Check if DS are created, if so delete the resources associated with it + // Resources associated with ovn-controller: + // - ovncontroller-scripts [cm] + // - ovncontroller-config [cm] + // - ovn-controller [ds] + // - ovn-controller-ovs [ds] + // - job [it gets deleted once it's done, skip] + Log.Info("DEBUG - Deleting Daemonsets") + err := ensureDSDeleted(ctx, helper, instance) + if err != nil { + return ctrl.Result{}, err + } + + Log.Info("DEBUG - Deleting ConfigMaps") + err = r.ensureCMDeleted(ctx, helper, instance) + if err != nil { + return ctrl.Result{}, err + } + + // Set conditions to true as no more work is needed. + Log.Info("DEBUG: No nicMappings provided, skipping creation of DS") + instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) + instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage) + instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage) + instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) + instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage) + instance.Status.Conditions.MarkTrue(condition.TLSInputReadyCondition, condition.InputReadyMessage) + return ctrl.Result{}, nil + } + Log.Info(fmt.Sprintf("DEBUG ARNAU: NicMappings not empty: %v, continuing normal", instance.Spec.NicMappings)) + // ConfigMap configMapVars := make(map[string]env.Setter) @@ -677,6 +773,29 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance return ctrl.Result{}, nil } +// generateServiceConfigMaps - create configmaps which hold scripts and service configuration +func (r *OVNControllerReconciler) deleteConfigMaps( + ctx context.Context, + h *helper.Helper, + name string, + namespace string, +) error { + serviceCM := &corev1.ConfigMap{} + err := h.GetClient().Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, serviceCM) + if err != nil && !k8s_errors.IsNotFound(err) { + return err + } else if k8s_errors.IsNotFound(err) { + return nil + } + + err = h.GetClient().Delete(ctx, serviceCM) + if err != nil && !k8s_errors.IsNotFound(err) { + return fmt.Errorf("error deleting config map %s: %w", serviceCM.Name, err) + } + + return nil +} + // generateServiceConfigMaps - create configmaps which hold scripts and service configuration func (r *OVNControllerReconciler) generateServiceConfigMaps( ctx context.Context, diff --git a/tests/functional/base_test.go b/tests/functional/base_test.go index 0958e7d8..f3ad2c67 100644 --- a/tests/functional/base_test.go +++ b/tests/functional/base_test.go @@ -19,6 +19,7 @@ package functional_test import ( "encoding/json" + "fmt" "strings" "time" @@ -184,6 +185,15 @@ func GetOVNDBCluster(name types.NamespacedName) *ovnv1.OVNDBCluster { return ovn.GetOVNDBCluster(name) } +// GetConfigMap - +func GetConfigMap(name types.NamespacedName) *corev1.ConfigMap { + cm := &corev1.ConfigMap{} + Eventually(func(g Gomega) { + g.Expect(k8sClient.Get(ctx, name, cm)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + return cm +} + // GetDaemonSet - func GetDaemonSet(name types.NamespacedName) *appsv1.DaemonSet { ds := &appsv1.DaemonSet{} diff --git a/tests/functional/ovncontroller_controller_test.go b/tests/functional/ovncontroller_controller_test.go index ba321325..0787ed5e 100644 --- a/tests/functional/ovncontroller_controller_test.go +++ b/tests/functional/ovncontroller_controller_test.go @@ -30,17 +30,26 @@ import ( condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" ovn_common "github.com/openstack-k8s-operators/ovn-operator/pkg/common" + appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" + k8s_errors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" ) +// GINKGO_ARGS="--focus 'OVNController controller'" make test var _ = Describe("OVNController controller", func() { + // GINKGO_ARGS="--focus 'OVNController controller when A OVNController instance is created'" make test When("A OVNController instance is created", func() { var OVNControllerName types.NamespacedName BeforeEach(func() { - instance := CreateOVNController(namespace, GetDefaultOVNControllerSpec()) + specWithNicMappings := GetDefaultOVNControllerSpec() + + nicMappings := make(map[string]string) + nicMappings["examplebr"] = "examplebr" + specWithNicMappings.OVNControllerSpecCore.NicMappings = nicMappings + instance := CreateOVNController(namespace, specWithNicMappings) OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} DeferCleanup(th.DeleteInstance, instance) }) @@ -125,6 +134,7 @@ var _ = Describe("OVNController controller", func() { ) }) + // GINKGO_ARGS="--focus 'OVNController controller when A OVNController instance is created when OVNDBCluster instances are available without networkAttachments'" make test When("OVNDBCluster instances are available without networkAttachments", func() { var scriptsCM types.NamespacedName var dbs []types.NamespacedName @@ -204,6 +214,7 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when A OVNController instance is created when OVNDBCluster instances with networkAttachments are available'" make test When("OVNDBCluster instances with networkAttachments are available", func() { var configCM types.NamespacedName var daemonSetName types.NamespacedName @@ -274,6 +285,7 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController and OVNDBClusters are created with networkAttachments'" make test When("OVNController and OVNDBClusters are created with networkAttachments", func() { var OVNControllerName types.NamespacedName var dbs []types.NamespacedName @@ -288,6 +300,9 @@ var _ = Describe("OVNController controller", func() { } spec := GetDefaultOVNControllerSpec() spec.NetworkAttachment = "internalapi" + nicMappings := make(map[string]string) + nicMappings["foo-phynet"] = "foo-bridge" + spec.NicMappings = nicMappings instance := CreateOVNController(namespace, spec) OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} DeferCleanup(th.DeleteInstance, instance) @@ -341,12 +356,18 @@ var _ = Describe("OVNController controller", func() { expectedAnnotation, err := json.Marshal( []networkv1.NetworkSelectionElement{ + { + Name: "foo-phynet", + Namespace: namespace, + InterfaceRequest: "foo-phynet", + }, { Name: "internalapi", Namespace: namespace, InterfaceRequest: "internalapi", }, - }) + }, + ) Expect(err).ShouldNot(HaveOccurred()) Expect(ds.Spec.Template.ObjectMeta.Annotations).To( HaveKeyWithValue("k8s.v1.cni.cncf.io/networks", string(expectedAnnotation)), @@ -384,6 +405,11 @@ var _ = Describe("OVNController controller", func() { expectedAnnotation, err := json.Marshal( []networkv1.NetworkSelectionElement{ + { + Name: "foo-phynet", + Namespace: namespace, + InterfaceRequest: "foo-phynet", + }, { Name: "internalapi", Namespace: namespace, @@ -578,6 +604,7 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with missing networkAttachment'" make test When("OVNController is created with missing networkAttachment", func() { var OVNControllerName types.NamespacedName var dbs []types.NamespacedName @@ -589,6 +616,9 @@ var _ = Describe("OVNController controller", func() { } spec := GetDefaultOVNControllerSpec() spec.NetworkAttachment = "internalapi" + spec.NicMappings = map[string]string{ + "physnet1": "enp2s0.100", + } instance := CreateOVNController(namespace, spec) OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} DeferCleanup(th.DeleteInstance, instance) @@ -606,6 +636,7 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with nic configs'" make test When("OVNController is created with nic configs", func() { var OVNControllerName types.NamespacedName BeforeEach(func() { @@ -762,7 +793,9 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with networkAttachment and nic configs'" make test When("OVNController is created with networkAttachment and nic configs", func() { + var OVNControllerName types.NamespacedName BeforeEach(func() { dbs := CreateOVNDBClusters(namespace, map[string][]string{}, 1) DeferCleanup(DeleteOVNDBClusters, dbs) @@ -772,6 +805,7 @@ var _ = Describe("OVNController controller", func() { "physnet1": "enp2s0.100", } instance := CreateOVNController(namespace, spec) + OVNControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} DeferCleanup(th.DeleteInstance, instance) }) @@ -811,8 +845,115 @@ var _ = Describe("OVNController controller", func() { HaveKeyWithValue("k8s.v1.cni.cncf.io/networks", string(expectedAnnotation)), ) }) + + It("deletes daemonset if nicMappings are removed", func() { + // ensure daemonsets/pods are created + internalAPINADName := types.NamespacedName{Namespace: namespace, Name: "internalapi"} + nad := th.CreateNetworkAttachmentDefinition(internalAPINADName) + DeferCleanup(th.DeleteInstance, nad) + + daemonSetName := types.NamespacedName{ + Namespace: namespace, + Name: "ovn-controller", + } + daemonSetNameOVS := types.NamespacedName{ + Namespace: namespace, + Name: "ovn-controller-ovs", + } + + configCM := types.NamespacedName{ + Namespace: namespace, + Name: "ovncontroller-config", + } + scriptCM := types.NamespacedName{ + Namespace: namespace, + Name: "ovncontroller-scripts", + } + + // ensure daemonsets are created + Eventually(func() *appsv1.DaemonSet { + return GetDaemonSet(daemonSetName) + }, timeout, interval).ShouldNot(BeNil()) + + Eventually(func() *appsv1.DaemonSet { + return GetDaemonSet(daemonSetNameOVS) + }, timeout, interval).ShouldNot(BeNil()) + + SimulateDaemonsetNumberReadyWithPods( + daemonSetName, + map[string][]string{namespace + "/internalapi": {"10.0.0.1"}}, + ) + SimulateDaemonsetNumberReadyWithPods( + daemonSetNameOVS, + map[string][]string{namespace + "/internalapi": {"10.0.0.1"}}, + ) + + // ensure configmaps are created + Eventually(func() *corev1.ConfigMap { + return GetConfigMap(configCM) + }, timeout, interval).ShouldNot(BeNil()) + + Eventually(func() *corev1.ConfigMap { + return GetConfigMap(scriptCM) + }, timeout, interval).ShouldNot(BeNil()) + + // remove nicMappings + Eventually(func(g Gomega) { + c := GetOVNController(OVNControllerName) + c.Spec.NicMappings = make(map[string]string) + g.Expect(k8sClient.Update(ctx, c)).Should(Succeed()) + }).Should(Succeed()) + logger.Info(fmt.Sprintf("ARNAU - Empty NicMappings: %v", daemonSetName.Name)) + + // ensure daemonsets are deleted + Eventually(func() error { + ds := &appsv1.DaemonSet{} + err := k8sClient.Get(ctx, daemonSetName, ds) + if err == nil { + return fmt.Errorf("Daemonset is still present") + } else if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + return nil + }, timeout, interval).Should(Succeed()) + + Eventually(func() error { + ds := &appsv1.DaemonSet{} + err := k8sClient.Get(ctx, daemonSetNameOVS, ds) + if err == nil { + return fmt.Errorf("OVS Daemonset is still present") + } else if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + return nil + }, timeout, interval).Should(Succeed()) + + // ensure configmaps are deleted + Eventually(func() error { + cm := &corev1.ConfigMap{} + err := k8sClient.Get(ctx, configCM, cm) + if err == nil { + return fmt.Errorf("config CM is still present") + } else if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + return nil + }, timeout, interval).Should(Succeed()) + + Eventually(func() error { + cm := &corev1.ConfigMap{} + err := k8sClient.Get(ctx, scriptCM, cm) + if err == nil { + return fmt.Errorf("script CM is still present") + } else if err != nil && !k8s_errors.IsNotFound(err) { + return err + } + return nil + }, timeout, interval).Should(Succeed()) + }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with empty spec'" make test When("OVNController is created with empty spec", func() { var ovnControllerName types.NamespacedName @@ -834,13 +975,18 @@ var _ = Describe("OVNController controller", func() { }) }) + // GINKGO_ARGS="--focus 'OVNController controller when OVNController is created with TLS'" make test When("OVNController is created with TLS", func() { var ovnControllerName types.NamespacedName BeforeEach(func() { dbs := CreateOVNDBClusters(namespace, map[string][]string{}, 1) DeferCleanup(DeleteOVNDBClusters, dbs) - instance := CreateOVNController(namespace, GetTLSOVNControllerSpec()) + specWithNicMappings := GetTLSOVNControllerSpec() + nicMappings := make(map[string]string) + nicMappings["examplebr"] = "examplebr" + specWithNicMappings.OVNControllerSpecCore.NicMappings = nicMappings + instance := CreateOVNController(namespace, specWithNicMappings) DeferCleanup(th.DeleteInstance, instance) ovnControllerName = types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} diff --git a/tests/kuttl/common/assert_ovn_controller.yaml b/tests/kuttl/common/assert_ovn_controller.yaml new file mode 100644 index 00000000..f0bf727b --- /dev/null +++ b/tests/kuttl/common/assert_ovn_controller.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: ovn-controller +status: + numberMisscheduled: 0 +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: ovn-controller-ovs +status: + numberMisscheduled: 0 +--- +apiVersion: v1 +kind: Pod +metadata: + annotations: + openshift.io/scc: privileged + labels: + service: ovn-controller + generateName: ovn-controller- +status: + phase: Running +--- +apiVersion: v1 +kind: Pod +metadata: + annotations: + openshift.io/scc: privileged + labels: + service: ovn-controller-ovs + generateName: ovn-controller-ovs- +status: + phase: Running diff --git a/tests/kuttl/common/assert_sample_deployment.yaml b/tests/kuttl/common/assert_sample_deployment.yaml index df20ebcd..7c754173 100644 --- a/tests/kuttl/common/assert_sample_deployment.yaml +++ b/tests/kuttl/common/assert_sample_deployment.yaml @@ -167,20 +167,6 @@ status: availableReplicas: 1 replicas: 1 --- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: ovn-controller -status: - numberMisscheduled: 0 ---- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: ovn-controller-ovs -status: - numberMisscheduled: 0 ---- # the openshift annotations can't be checked through the deployment above apiVersion: v1 kind: Pod @@ -209,28 +195,6 @@ metadata: name: ovsdbserver-sb-0 --- apiVersion: v1 -kind: Pod -metadata: - annotations: - openshift.io/scc: privileged - labels: - service: ovn-controller - generateName: ovn-controller- -status: - phase: Running ---- -apiVersion: v1 -kind: Pod -metadata: - annotations: - openshift.io/scc: privileged - labels: - service: ovn-controller-ovs - generateName: ovn-controller-ovs- -status: - phase: Running ---- -apiVersion: v1 kind: Service metadata: labels: @@ -315,12 +279,22 @@ commands: num_pods_ovn=$(oc get pods -n $NAMESPACE -l service=ovn-controller -o name --field-selector=status.phase=Running | wc -l) num_pods_ovs=$(oc get pods -n $NAMESPACE -l service=ovn-controller-ovs -o name --field-selector=status.phase=Running | wc -l) num_pods=$(( num_pods_ovn + num_pods_ovs)) - # for each nodes, two pods are spawned - ovn-controller and ovn-controller-ovs - if [ "$((num_nodes * 2))" -ne "$num_pods" ]; then - echo "Cluster has $num_nodes nodes but OVNController spawned $num_pods pods, it should have $num_nodes * 2" - exit 1 + nic_mappings_set=$(oc get -n $NAMESPACE ovncontroller ovncontroller-sample -o json | jq '.spec | has("nicMappings")') + # if Spec.NicMappings is empty number should be 0, else should be equal to num_nodes. + echo $nic_mappings_set + if [ "$nic_mappings_set" == "true" ]; then + # for each nodes, two pods are spawned - ovn-controller and ovn-controller-ovs + if [ "$((num_nodes * 2))" -ne "$num_pods" ]; then + echo "Cluster has $num_nodes nodes but OVNController spawned $num_pods pods, it should have $num_nodes * 2" + exit 1 + fi + else + # nicMappings is not set, it should be zero regardless of num_nodes + if [ "0" -ne "$num_pods" ]; then + echo "Cluster has $num_nodes nodes but OVNController spawned $num_pods pods, it should be 0" + exit 1 + fi fi - tupleTemplate='{{ range (index .spec.template.spec.containers 1).env }}{{ .name }}{{ "#" }}{{ .value}}{{"\n"}}{{ end }}' imageTuples=$(oc get -n openstack-operators deployment ovn-operator-controller-manager -o go-template="$tupleTemplate") for ITEM in $(echo $imageTuples); do @@ -355,9 +329,9 @@ commands: exit 0 - script: | - controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller -o name|head -1) - host=$(oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl get open . external_ids:hostname) + #controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller -o name|head -1) + #host=$(oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl get open . external_ids:hostname) - sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) - oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q ${host} || exit 1 + #sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) + #oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q ${host} || exit 1 exit 0 diff --git a/tests/kuttl/tests/ovn_nicmappings/03-nicmappings-patch-datacentre2.yaml b/tests/kuttl/common/attach_nic_mappings_ovn_controller.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/03-nicmappings-patch-datacentre2.yaml rename to tests/kuttl/common/attach_nic_mappings_ovn_controller.yaml diff --git a/tests/kuttl/common/create_nad.yaml b/tests/kuttl/common/create_nad.yaml new file mode 100644 index 00000000..1b8dfa4b --- /dev/null +++ b/tests/kuttl/common/create_nad.yaml @@ -0,0 +1,5 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: + - script: | + oc apply -n $NAMESPACE -f ../../../../config/samples/nad_datacentre2.yaml diff --git a/tests/kuttl/common/create_oc_bridge.yaml b/tests/kuttl/common/create_oc_bridge.yaml new file mode 100644 index 00000000..be55f70b --- /dev/null +++ b/tests/kuttl/common/create_oc_bridge.yaml @@ -0,0 +1,15 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +apply: +- ../../../../config/samples/nad_principal.yaml +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +timeout: 60 +commands: + - script: | + oc patch OVNController -n $NAMESPACE ovncontroller-sample --type='json' -p='[{ + "op": "replace", + "path": "/spec/nicMappings", + "value":{"testattach":"ospbrprin"} + }]' diff --git a/tests/kuttl/common/scripts/check_cluster_status.sh b/tests/kuttl/common/scripts/check_cluster_status.sh index e062c44a..0d34e23e 100755 --- a/tests/kuttl/common/scripts/check_cluster_status.sh +++ b/tests/kuttl/common/scripts/check_cluster_status.sh @@ -21,12 +21,13 @@ declare -a pods for i in $(seq 0 $((NUM_PODS-1))); do pods+=("${POD_PREFIX}-${i}") done - +echo $pods # check each pod replica for pod in "${pods[@]}"; do - echo "Checking status of $pod" - output=$(oc exec $pod -n $NAMESPACE -- bash -c "OVS_RUNDIR=/tmp ovs-appctl -t /tmp/$CTL_FILE cluster/status $DB_NAME") + echo "Checking status of $pod on namespace $NAMESPACE" + output=$(oc rsh -n $NAMESPACE $pod bash -c "OVS_RUNDIR=/tmp ovs-appctl -t /tmp/$CTL_FILE cluster/status $DB_NAME") + echo $output # Example of part of output string that needs parsing: # Status: cluster member diff --git a/tests/kuttl/tests/ovn_config/02-create-principal-bridge.yaml b/tests/kuttl/tests/ovn_config/02-create-principal-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_config/02-create-principal-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_config/03-assert.yaml b/tests/kuttl/tests/ovn_config/03-assert.yaml deleted file mode 100644 index 92abb5a6..00000000 --- a/tests/kuttl/tests/ovn_config/03-assert.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# -# Check for: -# -# - chassis unregistered in sb db - -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -timeout: 30 -commands: - - script: | - sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) - oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q hostname && exit 1 - exit 0 diff --git a/tests/kuttl/tests/ovn_config/03-assert.yaml b/tests/kuttl/tests/ovn_config/03-assert.yaml new file mode 120000 index 00000000..6ede65dc --- /dev/null +++ b/tests/kuttl/tests/ovn_config/03-assert.yaml @@ -0,0 +1 @@ +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_config/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_config/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_config/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_config/02-assert.yaml b/tests/kuttl/tests/ovn_config/04-assert.yaml similarity index 100% rename from tests/kuttl/tests/ovn_config/02-assert.yaml rename to tests/kuttl/tests/ovn_config/04-assert.yaml diff --git a/tests/kuttl/tests/ovn_config/02-az-patch.yaml b/tests/kuttl/tests/ovn_config/04-az-patch.yaml similarity index 100% rename from tests/kuttl/tests/ovn_config/02-az-patch.yaml rename to tests/kuttl/tests/ovn_config/04-az-patch.yaml diff --git a/tests/kuttl/tests/ovn_config/05-assert.yaml b/tests/kuttl/tests/ovn_config/05-assert.yaml new file mode 100644 index 00000000..92abb5a6 --- /dev/null +++ b/tests/kuttl/tests/ovn_config/05-assert.yaml @@ -0,0 +1,13 @@ +# +# Check for: +# +# - chassis unregistered in sb db + +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 30 +commands: + - script: | + sb_pod=$(oc get pod -n $NAMESPACE -l service=ovsdbserver-sb -o name|head -1) + oc rsh -n $NAMESPACE ${sb_pod} ovn-sbctl list chassis | grep -q hostname && exit 1 + exit 0 diff --git a/tests/kuttl/tests/ovn_config/03-remove-ovncontroller.yaml b/tests/kuttl/tests/ovn_config/05-remove-ovncontroller.yaml similarity index 100% rename from tests/kuttl/tests/ovn_config/03-remove-ovncontroller.yaml rename to tests/kuttl/tests/ovn_config/05-remove-ovncontroller.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/02-assert.yaml b/tests/kuttl/tests/ovn_db_delete/02-assert.yaml deleted file mode 100644 index 0dd7be77..00000000 --- a/tests/kuttl/tests/ovn_db_delete/02-assert.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# -# Check for: -# -# - 1 OVNDBCluster CR -# - 3 Pods for OVNDBCluster nb CR -# - -apiVersion: ovn.openstack.org/v1beta1 -kind: OVNDBCluster -metadata: - finalizers: - - openstack.org/ovndbcluster - name: ovndbcluster-nb-sample -spec: - replicas: 3 -status: - readyCount: 3 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: ovsdbserver-nb -spec: - replicas: 3 -status: - availableReplicas: 3 ---- -apiVersion: ovn.openstack.org/v1beta1 -kind: OVNDBCluster -metadata: - finalizers: - - openstack.org/ovndbcluster - name: ovndbcluster-sb-sample -spec: - replicas: 3 -status: - readyCount: 3 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: ovsdbserver-sb -spec: - replicas: 3 -status: - availableReplicas: 3 ---- diff --git a/tests/kuttl/tests/ovn_db_delete/02-create-bridge.yaml b/tests/kuttl/tests/ovn_db_delete/02-create-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/02-create-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/03-assert.yaml b/tests/kuttl/tests/ovn_db_delete/03-assert.yaml deleted file mode 100644 index ffcf4ce9..00000000 --- a/tests/kuttl/tests/ovn_db_delete/03-assert.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -commands: - - script: | - $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh nb 3 - test $? -eq 0 - - script: | - $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh sb 3 - test $? -eq 0 diff --git a/tests/kuttl/tests/ovn_db_delete/03-assert.yaml b/tests/kuttl/tests/ovn_db_delete/03-assert.yaml new file mode 120000 index 00000000..6ede65dc --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/03-assert.yaml @@ -0,0 +1 @@ +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_db_delete/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/04-assert.yaml b/tests/kuttl/tests/ovn_db_delete/04-assert.yaml deleted file mode 120000 index a30aa910..00000000 --- a/tests/kuttl/tests/ovn_db_delete/04-assert.yaml +++ /dev/null @@ -1 +0,0 @@ -02-assert.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/04-assert.yaml b/tests/kuttl/tests/ovn_db_delete/04-assert.yaml new file mode 100644 index 00000000..0dd7be77 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/04-assert.yaml @@ -0,0 +1,47 @@ +# +# Check for: +# +# - 1 OVNDBCluster CR +# - 3 Pods for OVNDBCluster nb CR +# + +apiVersion: ovn.openstack.org/v1beta1 +kind: OVNDBCluster +metadata: + finalizers: + - openstack.org/ovndbcluster + name: ovndbcluster-nb-sample +spec: + replicas: 3 +status: + readyCount: 3 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: ovsdbserver-nb +spec: + replicas: 3 +status: + availableReplicas: 3 +--- +apiVersion: ovn.openstack.org/v1beta1 +kind: OVNDBCluster +metadata: + finalizers: + - openstack.org/ovndbcluster + name: ovndbcluster-sb-sample +spec: + replicas: 3 +status: + readyCount: 3 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: ovsdbserver-sb +spec: + replicas: 3 +status: + availableReplicas: 3 +--- diff --git a/tests/kuttl/tests/ovn_db_delete/02-scale-ovndb.yaml b/tests/kuttl/tests/ovn_db_delete/04-scale-ovndb.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/02-scale-ovndb.yaml rename to tests/kuttl/tests/ovn_db_delete/04-scale-ovndb.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/05-assert.yaml b/tests/kuttl/tests/ovn_db_delete/05-assert.yaml deleted file mode 120000 index cf30bf5b..00000000 --- a/tests/kuttl/tests/ovn_db_delete/05-assert.yaml +++ /dev/null @@ -1 +0,0 @@ -03-assert.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/05-assert.yaml b/tests/kuttl/tests/ovn_db_delete/05-assert.yaml new file mode 100644 index 00000000..b752602a --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/05-assert.yaml @@ -0,0 +1,11 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + echo "$OVN_KUTTL_DIR/../common/scripts/" + ls $OVN_KUTTL_DIR/../common/scripts/ + $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh nb 3 + test $? -eq 0 + - script: | + $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh sb 3 + test $? -eq 0 diff --git a/tests/kuttl/tests/ovn_db_delete/06-assert.yaml b/tests/kuttl/tests/ovn_db_delete/06-assert.yaml new file mode 120000 index 00000000..cbe7a633 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/06-assert.yaml @@ -0,0 +1 @@ +04-assert.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/04-delete-pods.yaml b/tests/kuttl/tests/ovn_db_delete/06-delete-pods.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/04-delete-pods.yaml rename to tests/kuttl/tests/ovn_db_delete/06-delete-pods.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/09-assert.yaml b/tests/kuttl/tests/ovn_db_delete/09-assert.yaml deleted file mode 100644 index 38a7c6c5..00000000 --- a/tests/kuttl/tests/ovn_db_delete/09-assert.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -commands: - - script: | - $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh nb 1 - test $? -eq 0 - - script: | - $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh sb 1 - test $? -eq 0 diff --git a/tests/kuttl/tests/ovn_db_delete/09-assert.yaml b/tests/kuttl/tests/ovn_db_delete/09-assert.yaml new file mode 120000 index 00000000..cf30bf5b --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/09-assert.yaml @@ -0,0 +1 @@ +03-assert.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_db_delete/08-assert.yaml b/tests/kuttl/tests/ovn_db_delete/10-assert.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/08-assert.yaml rename to tests/kuttl/tests/ovn_db_delete/10-assert.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/08-scale-down-ovndb.yaml b/tests/kuttl/tests/ovn_db_delete/10-scale-down-ovndb.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/08-scale-down-ovndb.yaml rename to tests/kuttl/tests/ovn_db_delete/10-scale-down-ovndb.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/11-assert.yaml b/tests/kuttl/tests/ovn_db_delete/11-assert.yaml new file mode 100644 index 00000000..38a7c6c5 --- /dev/null +++ b/tests/kuttl/tests/ovn_db_delete/11-assert.yaml @@ -0,0 +1,9 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh nb 1 + test $? -eq 0 + - script: | + $OVN_KUTTL_DIR/../common/scripts/check_cluster_status.sh sb 1 + test $? -eq 0 diff --git a/tests/kuttl/tests/ovn_db_delete/10-cleanup-ovn.yaml b/tests/kuttl/tests/ovn_db_delete/12-cleanup-ovn.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/10-cleanup-ovn.yaml rename to tests/kuttl/tests/ovn_db_delete/12-cleanup-ovn.yaml diff --git a/tests/kuttl/tests/ovn_db_delete/10-errors.yaml b/tests/kuttl/tests/ovn_db_delete/12-errors.yaml similarity index 100% rename from tests/kuttl/tests/ovn_db_delete/10-errors.yaml rename to tests/kuttl/tests/ovn_db_delete/12-errors.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/02-create-principal-bridge.yaml b/tests/kuttl/tests/ovn_nicmappings/02-create-principal-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/02-create-principal-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml b/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml deleted file mode 100644 index 41021b0b..00000000 --- a/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml +++ /dev/null @@ -1,19 +0,0 @@ -# -# Check for: -# -# - The interface "datacentre2" exists in the ovn-controller container -# - The OVS Open vSwitch external_ids:ovn-bridge-mappings is configured correctly - -apiVersion: kuttl.dev/v1beta1 -kind: TestAssert -timeout: 300 -commands: - - script: | - controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller-ovs -o name|head -1) - oc rsh -n $NAMESPACE ${controller_pod} ip link show dev datacentre2 || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ip link show dev br-datacentre2 || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl list-ports br-datacentre2 | grep datacentre2 || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ip link show dev data-centre3 2>&1 | grep "does not exist" || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ip link show dev br-data-centre3 2>&1 | grep "does not exist" || exit 1 - oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl --if-exists get open . external_ids:ovn-bridge-mappings | grep -q "datacentre2:br-datacentre2" || exit 1 - exit 0 diff --git a/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml b/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml new file mode 120000 index 00000000..6ede65dc --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/03-assert.yaml @@ -0,0 +1 @@ +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_nicmappings/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_nicmappings/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_nicmappings/02-new-network-attachment-definition.yaml b/tests/kuttl/tests/ovn_nicmappings/04-new-network-attachment-definition.yaml similarity index 65% rename from tests/kuttl/tests/ovn_nicmappings/02-new-network-attachment-definition.yaml rename to tests/kuttl/tests/ovn_nicmappings/04-new-network-attachment-definition.yaml index 10b53dc2..4ed40498 100644 --- a/tests/kuttl/tests/ovn_nicmappings/02-new-network-attachment-definition.yaml +++ b/tests/kuttl/tests/ovn_nicmappings/04-new-network-attachment-definition.yaml @@ -2,5 +2,4 @@ apiVersion: kuttl.dev/v1beta1 kind: TestStep commands: - script: | - oc apply -n $NAMESPACE -f ../../../../config/samples/nad_datacentre2.yaml oc apply -n $NAMESPACE -f ../../../../config/samples/nad_data-centre3.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/05-assert.yaml b/tests/kuttl/tests/ovn_nicmappings/05-assert.yaml new file mode 100644 index 00000000..41021b0b --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/05-assert.yaml @@ -0,0 +1,19 @@ +# +# Check for: +# +# - The interface "datacentre2" exists in the ovn-controller container +# - The OVS Open vSwitch external_ids:ovn-bridge-mappings is configured correctly + +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 300 +commands: + - script: | + controller_pod=$(oc get pod -n $NAMESPACE -l service=ovn-controller-ovs -o name|head -1) + oc rsh -n $NAMESPACE ${controller_pod} ip link show dev datacentre2 || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ip link show dev br-datacentre2 || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl list-ports br-datacentre2 | grep datacentre2 || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ip link show dev data-centre3 2>&1 | grep "does not exist" || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ip link show dev br-data-centre3 2>&1 | grep "does not exist" || exit 1 + oc rsh -n $NAMESPACE ${controller_pod} ovs-vsctl --if-exists get open . external_ids:ovn-bridge-mappings | grep -q "datacentre2:br-datacentre2" || exit 1 + exit 0 diff --git a/tests/kuttl/tests/ovn_nicmappings/05-nicmappings-patch-datacentre2.yaml b/tests/kuttl/tests/ovn_nicmappings/05-nicmappings-patch-datacentre2.yaml new file mode 100644 index 00000000..ea8a9e1a --- /dev/null +++ b/tests/kuttl/tests/ovn_nicmappings/05-nicmappings-patch-datacentre2.yaml @@ -0,0 +1,10 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +timeout: 60 +commands: + - script: | + oc patch OVNController -n $NAMESPACE ovncontroller-sample --type='json' -p='[{ + "op": "replace", + "path": "/spec/nicMappings", + "value":{"datacentre2":"ospbr2"} + }]' diff --git a/tests/kuttl/tests/ovn_nicmappings/04-assert.yaml b/tests/kuttl/tests/ovn_nicmappings/06-assert.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/04-assert.yaml rename to tests/kuttl/tests/ovn_nicmappings/06-assert.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/04-nicmappings-patch-datacentre3.yaml b/tests/kuttl/tests/ovn_nicmappings/06-nicmappings-patch-datacentre3.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/04-nicmappings-patch-datacentre3.yaml rename to tests/kuttl/tests/ovn_nicmappings/06-nicmappings-patch-datacentre3.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/06-cleanup-ovn.yaml b/tests/kuttl/tests/ovn_nicmappings/08-cleanup-ovn.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/06-cleanup-ovn.yaml rename to tests/kuttl/tests/ovn_nicmappings/08-cleanup-ovn.yaml diff --git a/tests/kuttl/tests/ovn_nicmappings/06-errors.yaml b/tests/kuttl/tests/ovn_nicmappings/08-errors.yaml similarity index 100% rename from tests/kuttl/tests/ovn_nicmappings/06-errors.yaml rename to tests/kuttl/tests/ovn_nicmappings/08-errors.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/02-create-principal-bridge.yaml b/tests/kuttl/tests/ovn_restart_flow/02-create-principal-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_restart_flow/02-create-principal-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_restart_flow/03-assert.yaml b/tests/kuttl/tests/ovn_restart_flow/03-assert.yaml index 461654ea..6ede65dc 120000 --- a/tests/kuttl/tests/ovn_restart_flow/03-assert.yaml +++ b/tests/kuttl/tests/ovn_restart_flow/03-assert.yaml @@ -1 +1 @@ -../../common/assert_sample_deployment.yaml \ No newline at end of file +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_restart_flow/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_restart_flow/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_restart_flow/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_restart_flow/02-add-bridge-and-flows.yaml b/tests/kuttl/tests/ovn_restart_flow/04-add-bridge-and-flows.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/02-add-bridge-and-flows.yaml rename to tests/kuttl/tests/ovn_restart_flow/04-add-bridge-and-flows.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/05-assert.yaml b/tests/kuttl/tests/ovn_restart_flow/05-assert.yaml new file mode 120000 index 00000000..461654ea --- /dev/null +++ b/tests/kuttl/tests/ovn_restart_flow/05-assert.yaml @@ -0,0 +1 @@ +../../common/assert_sample_deployment.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_restart_flow/03-delete-pods.yaml b/tests/kuttl/tests/ovn_restart_flow/05-delete-pods.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/03-delete-pods.yaml rename to tests/kuttl/tests/ovn_restart_flow/05-delete-pods.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/04-assert-flows-present.yaml b/tests/kuttl/tests/ovn_restart_flow/06-assert-flows-present.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/04-assert-flows-present.yaml rename to tests/kuttl/tests/ovn_restart_flow/06-assert-flows-present.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/06-cleanup-ovn.yaml b/tests/kuttl/tests/ovn_restart_flow/08-cleanup-ovn.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/06-cleanup-ovn.yaml rename to tests/kuttl/tests/ovn_restart_flow/08-cleanup-ovn.yaml diff --git a/tests/kuttl/tests/ovn_restart_flow/06-errors.yaml b/tests/kuttl/tests/ovn_restart_flow/08-errors.yaml similarity index 100% rename from tests/kuttl/tests/ovn_restart_flow/06-errors.yaml rename to tests/kuttl/tests/ovn_restart_flow/08-errors.yaml diff --git a/tests/kuttl/tests/ovn_scale/02-create-principal-bridge.yaml b/tests/kuttl/tests/ovn_scale/02-create-principal-bridge.yaml new file mode 120000 index 00000000..90e436c3 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/02-create-principal-bridge.yaml @@ -0,0 +1 @@ +../../common/create_nad.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_scale/03-assert.yaml b/tests/kuttl/tests/ovn_scale/03-assert.yaml deleted file mode 100644 index d8b1a349..00000000 --- a/tests/kuttl/tests/ovn_scale/03-assert.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# -# Check for: -# -# - 1 OVNNorthd CR -# - 1 Pods for OVNNorthd CR -# - -apiVersion: ovn.openstack.org/v1beta1 -kind: OVNNorthd -metadata: - finalizers: - - openstack.org/ovnnorthd - name: ovnnorthd-sample -spec: - replicas: 1 -status: - readyCount: 1 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ovn-northd -spec: - replicas: 1 -status: - availableReplicas: 1 diff --git a/tests/kuttl/tests/ovn_scale/03-assert.yaml b/tests/kuttl/tests/ovn_scale/03-assert.yaml new file mode 120000 index 00000000..6ede65dc --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/03-assert.yaml @@ -0,0 +1 @@ +../../common/assert_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_scale/03-enable-ovncontroller.yaml b/tests/kuttl/tests/ovn_scale/03-enable-ovncontroller.yaml new file mode 120000 index 00000000..9180c2a4 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/03-enable-ovncontroller.yaml @@ -0,0 +1 @@ +../../common/attach_nic_mappings_ovn_controller.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_scale/04-assert.yaml b/tests/kuttl/tests/ovn_scale/04-assert.yaml index f0644b74..13c6d81e 100644 --- a/tests/kuttl/tests/ovn_scale/04-assert.yaml +++ b/tests/kuttl/tests/ovn_scale/04-assert.yaml @@ -1,8 +1,8 @@ # # Check for: # -# - 1 OVNNorthd CR with no replicas -# - 0 Pods for OVNNorthd CR +# - 1 OVNNorthd CR +# - 3 Pods for OVNNorthd CR # apiVersion: ovn.openstack.org/v1beta1 @@ -12,11 +12,15 @@ metadata: - openstack.org/ovnnorthd name: ovnnorthd-sample spec: - replicas: 0 + replicas: 3 +status: + readyCount: 3 --- apiVersion: apps/v1 kind: Deployment metadata: name: ovn-northd spec: - replicas: 0 + replicas: 3 +status: + availableReplicas: 3 diff --git a/tests/kuttl/tests/ovn_scale/04-errors.yaml b/tests/kuttl/tests/ovn_scale/04-errors.yaml deleted file mode 100644 index b18be191..00000000 --- a/tests/kuttl/tests/ovn_scale/04-errors.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - annotations: - openshift.io/scc: restricted-v2 - labels: - service: ovn diff --git a/tests/kuttl/tests/ovn_scale/02-scale-ovnnorthd.yaml b/tests/kuttl/tests/ovn_scale/04-scale-ovnnorthd.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/02-scale-ovnnorthd.yaml rename to tests/kuttl/tests/ovn_scale/04-scale-ovnnorthd.yaml diff --git a/tests/kuttl/tests/ovn_scale/02-assert.yaml b/tests/kuttl/tests/ovn_scale/05-assert.yaml similarity index 73% rename from tests/kuttl/tests/ovn_scale/02-assert.yaml rename to tests/kuttl/tests/ovn_scale/05-assert.yaml index 13c6d81e..d8b1a349 100644 --- a/tests/kuttl/tests/ovn_scale/02-assert.yaml +++ b/tests/kuttl/tests/ovn_scale/05-assert.yaml @@ -2,7 +2,7 @@ # Check for: # # - 1 OVNNorthd CR -# - 3 Pods for OVNNorthd CR +# - 1 Pods for OVNNorthd CR # apiVersion: ovn.openstack.org/v1beta1 @@ -12,15 +12,15 @@ metadata: - openstack.org/ovnnorthd name: ovnnorthd-sample spec: - replicas: 3 + replicas: 1 status: - readyCount: 3 + readyCount: 1 --- apiVersion: apps/v1 kind: Deployment metadata: name: ovn-northd spec: - replicas: 3 + replicas: 1 status: - availableReplicas: 3 + availableReplicas: 1 diff --git a/tests/kuttl/tests/ovn_scale/03-scale-down-ovnnorthd.yaml b/tests/kuttl/tests/ovn_scale/05-scale-down-ovnnorthd.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/03-scale-down-ovnnorthd.yaml rename to tests/kuttl/tests/ovn_scale/05-scale-down-ovnnorthd.yaml diff --git a/tests/kuttl/tests/ovn_scale/06-assert.yaml b/tests/kuttl/tests/ovn_scale/06-assert.yaml new file mode 100644 index 00000000..f0644b74 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/06-assert.yaml @@ -0,0 +1,22 @@ +# +# Check for: +# +# - 1 OVNNorthd CR with no replicas +# - 0 Pods for OVNNorthd CR +# + +apiVersion: ovn.openstack.org/v1beta1 +kind: OVNNorthd +metadata: + finalizers: + - openstack.org/ovnnorthd + name: ovnnorthd-sample +spec: + replicas: 0 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ovn-northd +spec: + replicas: 0 diff --git a/tests/kuttl/tests/ovn_scale/06-errors.yaml b/tests/kuttl/tests/ovn_scale/06-errors.yaml deleted file mode 120000 index 7314c155..00000000 --- a/tests/kuttl/tests/ovn_scale/06-errors.yaml +++ /dev/null @@ -1 +0,0 @@ -../../common/errors_cleanup_ovn.yaml \ No newline at end of file diff --git a/tests/kuttl/tests/ovn_scale/06-errors.yaml b/tests/kuttl/tests/ovn_scale/06-errors.yaml new file mode 100644 index 00000000..b18be191 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/06-errors.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + openshift.io/scc: restricted-v2 + labels: + service: ovn diff --git a/tests/kuttl/tests/ovn_scale/04-scale-down-zero-ovnnorthd.yaml b/tests/kuttl/tests/ovn_scale/06-scale-down-zero-ovnnorthd.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/04-scale-down-zero-ovnnorthd.yaml rename to tests/kuttl/tests/ovn_scale/06-scale-down-zero-ovnnorthd.yaml diff --git a/tests/kuttl/tests/ovn_scale/05-errors.yaml b/tests/kuttl/tests/ovn_scale/07-errors.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/05-errors.yaml rename to tests/kuttl/tests/ovn_scale/07-errors.yaml diff --git a/tests/kuttl/tests/ovn_scale/05-scale-down-pods-ovncontroller.yaml b/tests/kuttl/tests/ovn_scale/07-scale-down-pods-ovncontroller.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/05-scale-down-pods-ovncontroller.yaml rename to tests/kuttl/tests/ovn_scale/07-scale-down-pods-ovncontroller.yaml diff --git a/tests/kuttl/tests/ovn_scale/06-cleanup-ovn.yaml b/tests/kuttl/tests/ovn_scale/08-cleanup-ovn.yaml similarity index 100% rename from tests/kuttl/tests/ovn_scale/06-cleanup-ovn.yaml rename to tests/kuttl/tests/ovn_scale/08-cleanup-ovn.yaml diff --git a/tests/kuttl/tests/ovn_scale/08-errors.yaml b/tests/kuttl/tests/ovn_scale/08-errors.yaml new file mode 120000 index 00000000..7314c155 --- /dev/null +++ b/tests/kuttl/tests/ovn_scale/08-errors.yaml @@ -0,0 +1 @@ +../../common/errors_cleanup_ovn.yaml \ No newline at end of file