diff --git a/.github/workflows/ci-e2e-tests.yml b/.github/workflows/ci-e2e-tests.yml index 951976bf..ebc60b64 100644 --- a/.github/workflows/ci-e2e-tests.yml +++ b/.github/workflows/ci-e2e-tests.yml @@ -172,3 +172,26 @@ jobs: - name: Delete template run: | KARDINAL_CLI_DEV_MODE=TRUE /tmp/kardinal-cli template delete extra-item-shared + + - name: Delete base topology and dev flows + run: | + KARDINAL_CLI_DEV_MODE=TRUE /tmp/kardinal-cli flow delete prod > kardinal.out + cat kardinal.out + if KARDINAL_CLI_DEV_MODE=TRUE /tmp/kardinal-cli flow ls | grep prod; then echo "Topologies not deleted"; exit 1; fi + + # Check that the services have been terminated + while [ "$(kubectl get pods -n prod 2>&1 >/dev/null)" != "No resources found in prod namespace." ] + do + echo "Waiting for the services to terminate..." + kubectl get pods -n prod + ((c++)) && ((c==12)) && exit 1 + sleep 10 + done + kubectl get pods -n prod + + # Check for errors in the kardinal manager logs + if kubectl logs -n default -l dev.kardinal.app-id=kardinal-manager | grep "ERRO" + then + echo "Errors found in the kardinal manager" + kubectl logs -n default -l dev.kardinal.app-id=kardinal-manager | grep "ERRO" + fi diff --git a/kardinal-manager/kardinal-manager/cluster_manager/cluster_manager.go b/kardinal-manager/kardinal-manager/cluster_manager/cluster_manager.go index 2c8022c0..bfa5d301 100644 --- a/kardinal-manager/kardinal-manager/cluster_manager/cluster_manager.go +++ b/kardinal-manager/kardinal-manager/cluster_manager/cluster_manager.go @@ -284,6 +284,12 @@ func (manager *ClusterManager) CleanUpClusterResources(ctx context.Context, clus servicesByNS := lo.GroupBy(*clusterResources.Services, func(item corev1.Service) string { return item.Namespace }) + if len(servicesByNS) == 0 { + // There are no resources to apply so we attempt to clear resources in the namespace set in the dummy gateway + // sent by the kontrol service. This happens when the tenant has no base cluster topology; no initial deploy + // or the topologies have been deleted. + servicesByNS[clusterResources.Gateway.GetNamespace()] = []corev1.Service{} + } for namespace, services := range servicesByNS { if err := manager.cleanUpServicesInNamespace(ctx, namespace, services); err != nil { return stacktrace.Propagate(err, "An error occurred cleaning up services '%+v' in namespace '%s'", services, namespace) @@ -292,6 +298,9 @@ func (manager *ClusterManager) CleanUpClusterResources(ctx context.Context, clus // Clean up deployments deploymentsByNS := lo.GroupBy(*clusterResources.Deployments, func(item appsv1.Deployment) string { return item.Namespace }) + if len(deploymentsByNS) == 0 { + deploymentsByNS[clusterResources.Gateway.GetNamespace()] = []appsv1.Deployment{} + } for namespace, deployments := range deploymentsByNS { if err := manager.cleanUpDeploymentsInNamespace(ctx, namespace, deployments); err != nil { return stacktrace.Propagate(err, "An error occurred cleaning up deployments '%+v' in namespace '%s'", deployments, namespace) @@ -300,6 +309,9 @@ func (manager *ClusterManager) CleanUpClusterResources(ctx context.Context, clus // Clean up virtual services virtualServicesByNS := lo.GroupBy(*clusterResources.VirtualServices, func(item v1alpha3.VirtualService) string { return item.Namespace }) + if len(virtualServicesByNS) == 0 { + virtualServicesByNS[clusterResources.Gateway.GetNamespace()] = []v1alpha3.VirtualService{} + } for namespace, virtualServices := range virtualServicesByNS { if err := manager.cleanUpVirtualServicesInNamespace(ctx, namespace, virtualServices); err != nil { return stacktrace.Propagate(err, "An error occurred cleaning up virtual services '%+v' in namespace '%s'", virtualServices, namespace) @@ -310,6 +322,9 @@ func (manager *ClusterManager) CleanUpClusterResources(ctx context.Context, clus destinationRulesByNS := lo.GroupBy(*clusterResources.DestinationRules, func(item v1alpha3.DestinationRule) string { return item.Namespace }) + if len(destinationRulesByNS) == 0 { + destinationRulesByNS[clusterResources.Gateway.GetNamespace()] = []v1alpha3.DestinationRule{} + } for namespace, destinationRules := range destinationRulesByNS { if err := manager.cleanUpDestinationRulesInNamespace(ctx, namespace, destinationRules); err != nil { return stacktrace.Propagate(err, "An error occurred cleaning up destination rules '%+v' in namespace '%s'", destinationRules, namespace) @@ -331,6 +346,9 @@ func (manager *ClusterManager) CleanUpClusterResources(ctx context.Context, clus envoyFiltersByNS := lo.GroupBy(*clusterResources.EnvoyFilters, func(item v1alpha3.EnvoyFilter) string { return item.Namespace }) + if len(envoyFiltersByNS) == 0 { + envoyFiltersByNS[clusterResources.Gateway.GetNamespace()] = []v1alpha3.EnvoyFilter{} + } for namespace, envoyFilters := range envoyFiltersByNS { if err := manager.cleanupEnvoyFiltersInNamespace(ctx, namespace, envoyFilters); err != nil { return stacktrace.Propagate(err, "An error occurred cleaning up envoy filters '%+v' in namespace '%s'", envoyFilters, namespace) @@ -343,6 +361,9 @@ func (manager *ClusterManager) CleanUpClusterResources(ctx context.Context, clus authorizationPoliciesByNS := lo.GroupBy(*clusterResources.AuthorizationPolicies, func(item securityv1beta1.AuthorizationPolicy) string { return item.Namespace }) + if len(authorizationPoliciesByNS) == 0 { + authorizationPoliciesByNS[clusterResources.Gateway.GetNamespace()] = []securityv1beta1.AuthorizationPolicy{} + } for namespace, authorizationPolicies := range authorizationPoliciesByNS { if err := manager.cleanupAuthorizationPoliciesInNamespace(ctx, namespace, authorizationPolicies); err != nil { return stacktrace.Propagate(err, "An error occurred cleaning up authorization policies '%+v' in namespace '%s'", authorizationPolicies, namespace) diff --git a/kardinal-manager/kardinal-manager/main.go b/kardinal-manager/kardinal-manager/main.go index 5b351b04..af3f2974 100644 --- a/kardinal-manager/kardinal-manager/main.go +++ b/kardinal-manager/kardinal-manager/main.go @@ -13,7 +13,6 @@ import ( const ( successExitCode = 0 clusterConfigEndpointEnvVarKey = "KARDINAL_MANAGER_CLUSTER_CONFIG_ENDPOINT" - tenantUuidEnvVarKey = "KARDINAL_MANAGER_TENANT_UUID" ) func main() {