diff --git a/Makefile b/Makefile index 7f99f55a..e8dcbc60 100644 --- a/Makefile +++ b/Makefile @@ -239,24 +239,24 @@ generate_mocks: ## TODO: auto install go install go.uber.org/mock/mockgen@latest mockgen -destination ${GEN_DIR}/${NETBOX_MOCKS_OUTPUT_FILE} -source=${INTERFACE_DEFITIONS_DIR} # e2e tests -E2E_PARAM := --namespace e2e --parallel 3 --apply-timeout 3m --assert-timeout 3m --delete-timeout 3m --error-timeout 3m --exec-timeout 3m # --skip-delete (add this argument for local debugging) +E2E_PARAM := --namespace e2e --parallel 3 --apply-timeout 3m --assert-timeout 3m --delete-timeout 3m --error-timeout 3m --exec-timeout 3m --cleanup-timeout 3m # --skip-delete (add this argument for local debugging) .PHONY: create-kind-3.7.8 create-kind-3.7.8: ./kind/local-env.sh --version 3.7.8 .PHONY: test-e2e-3.7.8 -test-e2e-3.7.8: create-kind-3.7.8 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW) +test-e2e-3.7.8: create-kind-3.7.8 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW) chainsaw test $(E2E_PARAM) .PHONY: create-kind-4.0.11 create-kind-4.0.11: ./kind/local-env.sh --version 4.0.11 .PHONY: test-e2e-4.0.11 -test-e2e-4.0.11: create-kind-4.0.11 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW) +test-e2e-4.0.11: create-kind-4.0.11 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW) chainsaw test $(E2E_PARAM) .PHONY: create-kind-4.1.8 create-kind-4.1.8: ./kind/local-env.sh --version 4.1.8 .PHONY: test-e2e-4.1.8 -test-e2e-4.1.8: create-kind-4.1.8 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW) +test-e2e-4.1.8: create-kind-4.1.8 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW) chainsaw test $(E2E_PARAM) diff --git a/api/v1/prefixclaim_types.go b/api/v1/prefixclaim_types.go index a5616b25..54cfe7f7 100644 --- a/api/v1/prefixclaim_types.go +++ b/api/v1/prefixclaim_types.go @@ -174,7 +174,7 @@ var ConditionPrefixAssignedFalse = metav1.Condition{ Type: "PrefixAssigned", Status: "False", Reason: "PrefixCRNotCreated", - Message: "Failed to fetch new Prefix from NetBox", + Message: "Failed to assign prefix, prefix CR creation skipped", } var ConditionParentPrefixSelectedTrue = metav1.Condition{ diff --git a/internal/controller/prefixclaim_controller.go b/internal/controller/prefixclaim_controller.go index f2b9589b..f769bd96 100644 --- a/internal/controller/prefixclaim_controller.go +++ b/internal/controller/prefixclaim_controller.go @@ -154,10 +154,11 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) // The existing algorithm for prefix allocation within a ParentPrefix remains unchanged // fetch available prefixes from netbox - parentPrefixCandidates, err := r.NetboxClient.GetAvailablePrefixByParentPrefixSelector(&prefixClaim.Spec) + parentPrefixCandidates, err := r.NetboxClient.GetAvailablePrefixesByParentPrefixSelector(&prefixClaim.Spec) if err != nil || len(parentPrefixCandidates) == 0 { - if errReport := r.EventStatusRecorder.Report(ctx, prefixClaim, netboxv1.ConditionParentPrefixSelectedFalse, corev1.EventTypeWarning, fmt.Errorf("no parent prefix can be obtained with the query conditions set in ParentPrefixSelector, err = %w, number of candidates = %v", err, len(parentPrefixCandidates))); errReport != nil { - return ctrl.Result{}, errReport + r.EventStatusRecorder.Recorder().Event(prefixClaim, corev1.EventTypeWarning, netboxv1.ConditionPrefixAssignedFalse.Reason, netboxv1.ConditionPrefixAssignedFalse.Message+": "+err.Error()) + if err := r.EventStatusRecorder.Report(ctx, prefixClaim, netboxv1.ConditionPrefixAssignedFalse, corev1.EventTypeWarning, err); err != nil { + return ctrl.Result{}, err } // we requeue as this might be a temporary prefix exhausation diff --git a/pkg/netbox/api/prefix_claim.go b/pkg/netbox/api/prefix_claim.go index 621eaee6..33f9f904 100644 --- a/pkg/netbox/api/prefix_claim.go +++ b/pkg/netbox/api/prefix_claim.go @@ -19,10 +19,11 @@ package api import ( "errors" "fmt" + "slices" "strconv" "strings" - "github.com/go-openapi/runtime" + "github.com/netbox-community/go-netbox/v3/netbox/client/extras" "github.com/netbox-community/go-netbox/v3/netbox/client/ipam" "github.com/netbox-community/netbox-operator/pkg/config" "github.com/netbox-community/netbox-operator/pkg/netbox/models" @@ -93,7 +94,7 @@ func validatePrefixLengthOrError(prefixClaim *models.PrefixClaim, prefixFamily i return nil } -func (r *NetboxClient) GetAvailablePrefixByParentPrefixSelector(prefixClaimSpec *netboxv1.PrefixClaimSpec) ([]*models.Prefix, error) { +func (r *NetboxClient) GetAvailablePrefixesByParentPrefixSelector(prefixClaimSpec *netboxv1.PrefixClaimSpec) ([]*models.Prefix, error) { fieldEntries := make(map[string]string) if tenant, ok := prefixClaimSpec.ParentPrefixSelector["tenant"]; ok { @@ -125,16 +126,25 @@ func (r *NetboxClient) GetAvailablePrefixByParentPrefixSelector(prefixClaimSpec fieldEntries["family"] = family } - var conditions func(co *runtime.ClientOperation) - parentPrefixSelectorEntries := make([]CustomFieldEntry, 0, len(prefixClaimSpec.ParentPrefixSelector)) + parentPrefixSelectorCustomFields := make([]CustomFieldEntry, 0, len(prefixClaimSpec.ParentPrefixSelector)) for k, v := range prefixClaimSpec.ParentPrefixSelector { - parentPrefixSelectorEntries = append(parentPrefixSelectorEntries, CustomFieldEntry{ - key: k, - value: v, - }) + switch k { + case "tenant", "site", "family": + // skip built in fields + default: + parentPrefixSelectorCustomFields = append(parentPrefixSelectorCustomFields, CustomFieldEntry{ + key: k, + value: v, + }) + } } - conditions = newQueryFilterOperation(fieldEntries, parentPrefixSelectorEntries) + err := r.customFieldsExistsOrErr(parentPrefixSelectorCustomFields) + if err != nil { + return nil, err + } + + conditions := newQueryFilterOperation(fieldEntries, parentPrefixSelectorCustomFields) list, err := r.Ipam.IpamPrefixesList(ipam.NewIpamPrefixesListParams(), nil, conditions) if err != nil { @@ -158,6 +168,48 @@ func (r *NetboxClient) GetAvailablePrefixByParentPrefixSelector(prefixClaimSpec return prefixes, nil } +func (r *NetboxClient) customFieldsExistsOrErr(customfieldFilterEntries []CustomFieldEntry) error { + if len(customfieldFilterEntries) == 0 { + // as the parent prefix selector does not filter for custom fields + // the check can be skipped + return nil + } + + responseGetCustomFieldsList, err := r.Extras.ExtrasCustomFieldsList(extras.NewExtrasCustomFieldsListParams(), nil) + if err != nil { + return err + } + + existingCustomFields := responseGetCustomFieldsList.Payload.Results + if len(existingCustomFields) == 0 { + return fmt.Errorf("netbox custom fields list is nil or empty") + } + + customFieldNames := make([]string, len(existingCustomFields)) + for i, field := range existingCustomFields { + if field.Name == nil { + return fmt.Errorf("netbox custom field name is nil") + } + customFieldNames[i] = *field.Name + } + + missingCustomFields := make([]string, 0) + for _, entry := range customfieldFilterEntries { + if !slices.Contains(customFieldNames, entry.key) { + missingCustomFields = append(missingCustomFields, entry.key) + } + } + + if len(missingCustomFields) > 0 { + return fmt.Errorf( + "invalid parentPrefixSelector, netbox custom fields %s do not exist", + strings.Join(missingCustomFields, ", "), + ) + } + + return nil +} + func (r *NetboxClient) isParentPrefixCandidate(prefixClaimSpec *netboxv1.PrefixClaimSpec, prefix string) bool { // if we can allocate a prefix from it, we can take it as a parent prefix if _, err := r.GetAvailablePrefixByClaim(&models.PrefixClaim{ diff --git a/pkg/netbox/api/prefix_claim_test.go b/pkg/netbox/api/prefix_claim_test.go index f68f8df0..75860140 100644 --- a/pkg/netbox/api/prefix_claim_test.go +++ b/pkg/netbox/api/prefix_claim_test.go @@ -22,9 +22,11 @@ import ( "testing" "github.com/netbox-community/go-netbox/v3/netbox/client/dcim" + "github.com/netbox-community/go-netbox/v3/netbox/client/extras" "github.com/netbox-community/go-netbox/v3/netbox/client/ipam" "github.com/netbox-community/go-netbox/v3/netbox/client/tenancy" netboxModels "github.com/netbox-community/go-netbox/v3/netbox/models" + netboxv1 "github.com/netbox-community/netbox-operator/api/v1" "github.com/netbox-community/netbox-operator/gen/mock_interfaces" "github.com/netbox-community/netbox-operator/pkg/netbox/models" "github.com/stretchr/testify/assert" @@ -1047,3 +1049,213 @@ func TestPrefixClaim_GetAvailablePrefixIfNoSiteInSpec(t *testing.T) { assert.Nil(t, err) assert.Equal(t, prefix, actual.Prefix) } + +func TestPrefixClaim_GetAvailablePrefixByParentPrefixSelector(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + pxcSpec := netboxv1.PrefixClaimSpec{ + ParentPrefixSelector: map[string]string{ + "environment": "dev", + "family": "IPv4", + "tenant": "tenant", + "site": "Site1", + }, + PrefixLength: "/32", + } + + mockTenancy := mock_interfaces.NewMockTenancyInterface(ctrl) + mockPrefixIpam := mock_interfaces.NewMockIpamInterface(ctrl) + mockExtras := mock_interfaces.NewMockExtrasInterface(ctrl) + mockDcim := mock_interfaces.NewMockDcimInterface(ctrl) + + // example of site + siteId := int64(3) + siteName := "Site1" + siteOutputSlug := "site1" + expectedSite := &dcim.DcimSitesListOK{ + Payload: &dcim.DcimSitesListOKBody{ + Results: []*netboxModels.Site{ + { + ID: siteId, + Name: &siteName, + Slug: &siteOutputSlug, + }, + }, + }, + } + inputSite := dcim.NewDcimSitesListParams().WithName(&siteName) + + // tenant + tenantName := "tenant" + tenantId := int64(2) + tenantOutputSlug := "tenant1" + + expectedTenant := &tenancy.TenancyTenantsListOK{ + Payload: &tenancy.TenancyTenantsListOKBody{ + Results: []*netboxModels.Tenant{ + { + ID: tenantId, + Name: &tenantName, + Slug: &tenantOutputSlug, + }, + }, + }, + } + + parentPrefix := "10.112.140.0/24" + parentPrefixId := int64(1) + prefixListInput := ipam. + NewIpamPrefixesListParams() + + prefixFamily := int64(IPv4Family) + prefixFamilyLabel := netboxModels.PrefixFamilyLabelIPV4 + prefixListOutput := &ipam.IpamPrefixesListOK{ + Payload: &ipam.IpamPrefixesListOKBody{ + Results: []*netboxModels.Prefix{ + { + ID: parentPrefixId, + Prefix: &parentPrefix, + Family: &netboxModels.PrefixFamily{Label: &prefixFamilyLabel, Value: &prefixFamily}, + }, + }, + }, + } + + prefixListInputWithParam := ipam.NewIpamPrefixesListParams().WithPrefix(&parentPrefix) + prefixListOutputWithParam := &ipam.IpamPrefixesListOK{ + Payload: &ipam.IpamPrefixesListOKBody{ + Results: []*netboxModels.Prefix{ + { + Prefix: &parentPrefix, + ID: parentPrefixId, + Family: &netboxModels.PrefixFamily{Label: &prefixFamilyLabel, Value: &prefixFamily}, + }, + }, + }, + } + + prefixAvailableListInput := ipam.NewIpamPrefixesAvailablePrefixesListParams().WithID(parentPrefixId) + prefixAvailableListOutput := &ipam.IpamPrefixesAvailablePrefixesListOK{ + Payload: []*netboxModels.AvailablePrefix{ + { + Family: prefixFamily, + Prefix: parentPrefix, + }, + }, + } + + // get prefix to check if it's a candidate + expectedCustomFieldName := "environment" + expectedCustomFields := &extras.ExtrasCustomFieldsListOK{ + Payload: &extras.ExtrasCustomFieldsListOKBody{ + Results: []*netboxModels.CustomField{ + { + Name: &expectedCustomFieldName, + }, + }, + }, + } + + mockPrefixIpam.EXPECT().IpamPrefixesList(prefixListInput, nil, gomock.Any()).Return(prefixListOutput, nil).Times(1) + mockPrefixIpam.EXPECT().IpamPrefixesList(prefixListInputWithParam, nil).Return(prefixListOutputWithParam, nil).Times(1) + mockPrefixIpam.EXPECT().IpamPrefixesAvailablePrefixesList(prefixAvailableListInput, nil).Return(prefixAvailableListOutput, nil).AnyTimes() + mockTenancy.EXPECT().TenancyTenantsList(gomock.Any(), nil).Return(expectedTenant, nil).AnyTimes() + mockDcim.EXPECT().DcimSitesList(inputSite, nil).Return(expectedSite, nil).AnyTimes() + mockExtras.EXPECT().ExtrasCustomFieldsList(extras.NewExtrasCustomFieldsListParams(), gomock.Any(), gomock.Any()).Return(expectedCustomFields, nil).AnyTimes() + + netboxClient := &NetboxClient{ + Ipam: mockPrefixIpam, + Tenancy: mockTenancy, + Extras: mockExtras, + Dcim: mockDcim, + } + + actual, err := netboxClient.GetAvailablePrefixesByParentPrefixSelector(&pxcSpec) + + assert.Nil(t, err) + assert.Equal(t, parentPrefix, actual[0].Prefix) +} + +func TestPrefixClaim_GetAvailablePrefixByParentPrefixSelectorFailIfNonExistingFieldInParentPrefixSelector(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + pxcSpec := netboxv1.PrefixClaimSpec{ + ParentPrefixSelector: map[string]string{ + "non-existing": "non-existing", + "environment": "dev", + "family": "IPv4", + "tenant": "tenant", + "site": "Site1", + }, + PrefixLength: "/32", + } + + mockTenancy := mock_interfaces.NewMockTenancyInterface(ctrl) + mockPrefixIpam := mock_interfaces.NewMockIpamInterface(ctrl) + mockExtras := mock_interfaces.NewMockExtrasInterface(ctrl) + mockDcim := mock_interfaces.NewMockDcimInterface(ctrl) + + // example of site + siteId := int64(3) + siteName := "Site1" + siteOutputSlug := "site1" + expectedSite := &dcim.DcimSitesListOK{ + Payload: &dcim.DcimSitesListOKBody{ + Results: []*netboxModels.Site{ + { + ID: siteId, + Name: &siteName, + Slug: &siteOutputSlug, + }, + }, + }, + } + inputSite := dcim.NewDcimSitesListParams().WithName(&siteName) + + // tenant + tenantName := "tenant" + tenantId := int64(2) + tenantOutputSlug := "tenant1" + + expectedTenant := &tenancy.TenancyTenantsListOK{ + Payload: &tenancy.TenancyTenantsListOKBody{ + Results: []*netboxModels.Tenant{ + { + ID: tenantId, + Name: &tenantName, + Slug: &tenantOutputSlug, + }, + }, + }, + } + + // get prefix to check if it's a candidate + expectedCustomFieldName := "environment" + expectedCustomFields := &extras.ExtrasCustomFieldsListOK{ + Payload: &extras.ExtrasCustomFieldsListOKBody{ + Results: []*netboxModels.CustomField{ + { + Name: &expectedCustomFieldName, + }, + }, + }, + } + + mockTenancy.EXPECT().TenancyTenantsList(gomock.Any(), nil).Return(expectedTenant, nil).AnyTimes() + mockDcim.EXPECT().DcimSitesList(inputSite, nil).Return(expectedSite, nil).AnyTimes() + mockExtras.EXPECT().ExtrasCustomFieldsList(extras.NewExtrasCustomFieldsListParams(), gomock.Any(), gomock.Any()).Return(expectedCustomFields, nil).AnyTimes() + + netboxClient := &NetboxClient{ + Ipam: mockPrefixIpam, + Tenancy: mockTenancy, + Extras: mockExtras, + Dcim: mockDcim, + } + + actual, err := netboxClient.GetAvailablePrefixesByParentPrefixSelector(&pxcSpec) + + assert.Nil(t, actual) + AssertError(t, err, "invalid parentPrefixSelector, netbox custom fields non-existing do not exist") +} diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-invalid-parentprefixselector/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-invalid-parentprefixselector/chainsaw-test.yaml index 34a876ef..3e80e47b 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-invalid-parentprefixselector/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-invalid-parentprefixselector/chainsaw-test.yaml @@ -34,19 +34,24 @@ spec: environment: "nilenv" poolName: "nilpool" status: - (conditions[?type == 'ParentPrefixSelected']): + (conditions[?type == 'PrefixAssigned']): - status: 'False' - assert: resource: apiVersion: v1 - count: 1 kind: Event type: Warning - reason: ParentPrefixNotSelected + reason: PrefixCRNotCreated source: component: prefix-claim-controller - message: "The parent prefix was not able to be selected: no parent prefix can be obtained with the query conditions set in ParentPrefixSelector, err = failed to fetch tenant 'niltenant': not found, number of candidates = 0" + message: "Failed to assign prefix, prefix CR creation skipped: failed to fetch tenant 'niltenant': not found" involvedObject: apiVersion: netbox.dev/v1 kind: PrefixClaim name: prefixclaim-ipv4-invalid-parentprefixselector + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-invalid-parentprefixselector -n $NAMESPACE diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-apply-update/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-apply-update/chainsaw-test.yaml index 11926289..f8a823e5 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-apply-update/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-apply-update/chainsaw-test.yaml @@ -79,3 +79,9 @@ spec: prefix: 2.0.2.0/28 site: MY_SITE tenant: MY_TENANT + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefix-apply-update -n $NAMESPACE diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml index 4bad5a2d..ff77b4d7 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml @@ -130,3 +130,10 @@ spec: tenant: MY_TENANT customFields: netboxOperatorRestorationHash: 00b8772de73cdac083b0732d5bb85ab4f0caa16c + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefix-restore-1 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefix-restore-2 -n $NAMESPACE diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield/chainsaw-test.yaml new file mode 100644 index 00000000..7f8807d6 --- /dev/null +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield/chainsaw-test.yaml @@ -0,0 +1,66 @@ +--- +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield + annotations: + description: Tests if creation fails for parentPrefixSelector with non exising custom field +spec: + steps: + - name: Apply CR + try: + - apply: + file: netbox_v1_prefixclaim.yaml + - name: Check CR spec + try: + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + name: prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield + spec: + comments: your comments + description: some description + parentPrefixSelector: # The keys and values are case-sensitive + tenant: "MY_TENANT" + site: "MY_SITE" + family: "IPv4" + environment: "Production" + poolName: "Pool 1" + nonexisingfield: "value" + prefixLength: /31 + preserveInNetbox: false + site: MY_SITE_2 + tenant: MY_TENANT_2 + - name: Check CR status + try: + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + name: prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield + status: + (conditions[?type == 'PrefixAssigned']): + - status: 'False' + reason: 'PrefixCRNotCreated' + - assert: + resource: + apiVersion: v1 + kind: Event + type: Warning + reason: PrefixCRNotCreated + source: + component: prefix-claim-controller + message: "Failed to assign prefix, prefix CR creation skipped: invalid parentPrefixSelector, netbox custom fields nonexisingfield do not exist" + involvedObject: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + name: prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield -n $NAMESPACE diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield/netbox_v1_prefixclaim.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield/netbox_v1_prefixclaim.yaml new file mode 100644 index 00000000..6bf76dfd --- /dev/null +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield/netbox_v1_prefixclaim.yaml @@ -0,0 +1,23 @@ +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + labels: + app.kubernetes.io/name: netbox-operator + app.kubernetes.io/managed-by: kustomize + name: prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield +spec: + tenant: "MY_TENANT_2" # Use the `name` value instead of the `slug` value + site: "MY_SITE_2" # Use the `name` value instead of the `slug` value + description: "some description" + comments: "your comments" + preserveInNetbox: false + prefixLength: "/31" + parentPrefixSelector: # The keys and values are case-sensitive + tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value + site: "MY_SITE" # Use the `name` value instead of the `slug` value + family: "IPv4" # Can only be either IPv4 or IPv6" + # custom fields of your interest + environment: "Production" + poolName: "Pool 1" + nonexisingfield: "value" diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml index 2d044a90..ed66186a 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml @@ -102,7 +102,7 @@ spec: - name: Apply CR 1 for the second time again try: - apply: - file: netbox_v1_prefixclaim_1.yaml + file: netbox_v1_prefixclaim_1.yaml - name: Check CR 1 spec and status and make sure it is restored try: - assert: @@ -143,3 +143,10 @@ spec: tenant: MY_TENANT_2 customFields: netboxOperatorRestorationHash: 8a5e15cd391ec02a7a2b2e316bc163f4fe46ef0b + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefixselector-restore-1 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefixselector-restore-2 -n $NAMESPACE diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml index c7f2244e..cec6420b 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml @@ -50,3 +50,9 @@ spec: tenant: MY_TENANT_2 customFields: netboxOperatorRestorationHash: 46116345cc81820fdb412dc83e7147d4b1dc1afa + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefixselector-apply -n $NAMESPACE diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-prefixexhausted/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-prefixexhausted/chainsaw-test.yaml index a371ca73..f8c7d436 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-prefixexhausted/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-prefixexhausted/chainsaw-test.yaml @@ -88,14 +88,21 @@ spec: - assert: resource: apiVersion: v1 - count: 1 kind: Event type: Warning reason: PrefixCRNotCreated source: component: prefix-claim-controller - message: "Failed to fetch new Prefix from NetBox: parent prefix exhausted, will restart the parent prefix selection process" + message: "Failed to assign prefix, prefix CR creation skipped: parent prefix exhausted, will restart the parent prefix selection process" involvedObject: apiVersion: netbox.dev/v1 kind: PrefixClaim name: prefixclaim-ipv4-prefixexhausted-3 + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-prefixexhausted-1 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-prefixexhausted-2 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-prefixexhausted-3 -n $NAMESPACE diff --git a/tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml b/tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml index c35c0392..51b91fe1 100644 --- a/tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml @@ -86,3 +86,9 @@ spec: prefix: 2::/124 preserveInNetbox: true tenant: MY_TENANT_2 + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv6-apply-update -n $NAMESPACE diff --git a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-apply-update/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-apply-update/chainsaw-test.yaml index f4e27930..5aa99f7f 100644 --- a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-apply-update/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-apply-update/chainsaw-test.yaml @@ -107,3 +107,9 @@ spec: status: (conditions[?type == 'Ready']): - status: 'True' + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-apply-update -n $NAMESPACE diff --git a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-prefixexhausted/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-prefixexhausted/chainsaw-test.yaml index 2c9cafe4..dccd850a 100644 --- a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-prefixexhausted/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-prefixexhausted/chainsaw-test.yaml @@ -123,7 +123,6 @@ spec: - assert: resource: apiVersion: v1 - count: 1 kind: Event type: Warning reason: IPAddressCRNotCreated @@ -134,3 +133,11 @@ spec: apiVersion: netbox.dev/v1 kind: IpAddressClaim name: ipaddressclaim-ipv4-prefixexhausted-3 + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-prefixexhausted-1 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-prefixexhausted-2 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-prefixexhausted-3 -n $NAMESPACE diff --git a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml index e441caaf..91a1631e 100644 --- a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml @@ -155,3 +155,10 @@ spec: status: (conditions[?type == 'Ready']): - status: 'True' + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-restore-1 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-restore-2 -n $NAMESPACE diff --git a/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-apply-update/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-apply-update/chainsaw-test.yaml index 53ecbb93..179bf2c1 100644 --- a/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-apply-update/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-apply-update/chainsaw-test.yaml @@ -107,3 +107,9 @@ spec: status: (conditions[?type == 'Ready']): - status: 'True' + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-apply-update -n $NAMESPACE diff --git a/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-prefixexhausted/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-prefixexhausted/chainsaw-test.yaml index a5b0f503..44986ead 100644 --- a/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-prefixexhausted/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-prefixexhausted/chainsaw-test.yaml @@ -123,7 +123,6 @@ spec: - assert: resource: apiVersion: v1 - count: 1 kind: Event type: Warning reason: IPAddressCRNotCreated @@ -134,3 +133,11 @@ spec: apiVersion: netbox.dev/v1 kind: IpAddressClaim name: ipaddressclaim-ipv6-prefixexhausted-3 + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-prefixexhausted-1 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-prefixexhausted-2 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-prefixexhausted-3 -n $NAMESPACE diff --git a/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml index fce8cfc6..6aae130b 100644 --- a/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml @@ -155,3 +155,10 @@ spec: status: (conditions[?type == 'Ready']): - status: 'True' + - name: Cleanup events + description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource + cleanup: + - script: + content: | + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-restore-1 -n $NAMESPACE + kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-restore-2 -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-apply-update/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-apply-update/chainsaw-test.yaml index a4b0044b..624075ea 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-apply-update/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-apply-update/chainsaw-test.yaml @@ -121,9 +121,9 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-apply-update -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-cidr/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-cidr/chainsaw-test.yaml index 851f769e..458c3821 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-cidr/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-cidr/chainsaw-test.yaml @@ -18,9 +18,9 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-invalid-cidr -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-customfieldnotexisting/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-customfieldnotexisting/chainsaw-test.yaml index e7f91f3e..8dc62cc9 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-customfieldnotexisting/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-customfieldnotexisting/chainsaw-test.yaml @@ -64,9 +64,9 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-invalid-customfieldnotexisting -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-customfieldwrongdatatype/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-customfieldwrongdatatype/chainsaw-test.yaml index cabb572a..53c1150b 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-customfieldwrongdatatype/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-customfieldwrongdatatype/chainsaw-test.yaml @@ -64,9 +64,9 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-invalid-customfieldwrongdatatype -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-parentprefix/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-parentprefix/chainsaw-test.yaml index 641d343e..d44868a4 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-parentprefix/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-parentprefix/chainsaw-test.yaml @@ -24,7 +24,6 @@ spec: - assert: resource: apiVersion: v1 - count: 1 kind: Event type: Warning reason: IPRangeCRNotCreated @@ -39,9 +38,9 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-invalid-parentprefix -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-size/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-size/chainsaw-test.yaml index 6151f902..b31d4ccf 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-size/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-size/chainsaw-test.yaml @@ -18,9 +18,9 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-invalid-size -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-tenant/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-tenant/chainsaw-test.yaml index baf1024a..b799eae3 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-tenant/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-tenant/chainsaw-test.yaml @@ -30,7 +30,6 @@ spec: - assert: resource: apiVersion: v1 - count: 1 kind: Event type: Warning reason: IPRangeCRNotCreated @@ -45,9 +44,9 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-invalid-tenant -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-prefixexhausted/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-prefixexhausted/chainsaw-test.yaml index 77691c69..19f493ba 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-prefixexhausted/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-prefixexhausted/chainsaw-test.yaml @@ -132,7 +132,6 @@ spec: - assert: resource: apiVersion: v1 - count: 1 kind: Event type: Warning reason: IPRangeCRNotCreated @@ -147,11 +146,11 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-prefixexhausted-1 -n $NAMESPACE kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-prefixexhausted-2 -n $NAMESPACE kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-prefixexhausted-3 -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-restore/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-restore/chainsaw-test.yaml index 67b34ad6..22338434 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-restore/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-restore/chainsaw-test.yaml @@ -176,10 +176,10 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-restore-1 -n $NAMESPACE kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv4-restore-2 -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-apply-update/chainsaw-test.yaml b/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-apply-update/chainsaw-test.yaml index 54bd67f1..1498c518 100644 --- a/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-apply-update/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-apply-update/chainsaw-test.yaml @@ -121,9 +121,9 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv6-apply-update -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-prefixexhausted/chainsaw-test.yaml b/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-prefixexhausted/chainsaw-test.yaml index 173d7bc1..a88d98fe 100644 --- a/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-prefixexhausted/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-prefixexhausted/chainsaw-test.yaml @@ -133,7 +133,6 @@ spec: - assert: resource: apiVersion: v1 - count: 1 kind: Event type: Warning reason: IPRangeCRNotCreated @@ -148,11 +147,11 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv6-prefixexhausted-1 -n $NAMESPACE kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv6-prefixexhausted-2 -n $NAMESPACE kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv6-prefixexhausted-3 -n $NAMESPACE diff --git a/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-restore/chainsaw-test.yaml b/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-restore/chainsaw-test.yaml index 31cbc2d5..957148bb 100644 --- a/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-restore/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-restore/chainsaw-test.yaml @@ -176,10 +176,10 @@ spec: description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: - script: - env: - - name: NAMESPACE - value: ($namespace) content: | - kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete # to be enhanced in usage of leaselocker + LEASES=$(kubectl -n netbox-operator-system get lease -oname | grep -v netbox) # to be enhanced in usage of leaselocker + if [ -n "$LEASES" ]; then + echo "$LEASES" | xargs -n1 kubectl -n netbox-operator-system delete + fi kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv6-restore-1 -n $NAMESPACE kubectl delete events --field-selector involvedObject.name=iprangeclaim-ipv6-restore-2 -n $NAMESPACE