diff --git a/test/e2e/clusterdeployment/constants.go b/test/e2e/clusterdeployment/constants.go index 602ffa38..1a1211b9 100644 --- a/test/e2e/clusterdeployment/constants.go +++ b/test/e2e/clusterdeployment/constants.go @@ -24,7 +24,8 @@ const ( // debugging of test failures. EnvVarNoCleanup = "NO_CLEANUP" - EnvVarServiceNamespace = "SERVICE_NAMESPACE" + EnvVarServiceNamespace = "INGRESS_SERVICE_NAMESPACE" + EnvVarServiceName = "INGRESS_SERVICE_NAME" // AWS EnvVarAWSAccessKeyID = "AWS_ACCESS_KEY_ID" diff --git a/test/e2e/clusterdeployment/resources/aws-standalone-cp.yaml.tpl b/test/e2e/clusterdeployment/resources/aws-standalone-cp.yaml.tpl index 923e564a..fccca8e4 100644 --- a/test/e2e/clusterdeployment/resources/aws-standalone-cp.yaml.tpl +++ b/test/e2e/clusterdeployment/resources/aws-standalone-cp.yaml.tpl @@ -17,7 +17,8 @@ spec: instanceType: ${AWS_INSTANCE_TYPE:=t3.small} worker: instanceType: ${AWS_INSTANCE_TYPE:=t3.small} - services: - - template: ingress-nginx-4-11-0 - name: managed-ingress-nginx - namespace: ${SERVICE_NAMESPACE} + serviceSpec: + services: + - template: ingress-nginx-4-11-0 + name: ${INGRESS_SERVICE_NAME} + namespace: ${INGRESS_SERVICE_NAMESPACE} diff --git a/test/e2e/clusterdeployment/servicevalidator.go b/test/e2e/clusterdeployment/servicevalidator.go index e311bc52..a9cbdba5 100644 --- a/test/e2e/clusterdeployment/servicevalidator.go +++ b/test/e2e/clusterdeployment/servicevalidator.go @@ -23,43 +23,63 @@ import ( "github.com/K0rdent/kcm/test/e2e/kubeclient" ) +type ManagedServiceResource struct { + // ResourceNameSuffix is the suffix added to the resource name + ResourceNameSuffix string + + // ValidationFunc is the validation function for the resource + ValidationFunc resourceValidationFunc +} + +func (m ManagedServiceResource) resourceFullName(serviceName string) string { + if m.ResourceNameSuffix == "" { + return serviceName + } + return fmt.Sprintf("%s-%s", serviceName, m.ResourceNameSuffix) +} + type ServiceValidator struct { // managedClusterName is the name of managed cluster managedClusterName string + // managedServiceName is the name of managed service + managedServiceName string + // template being validated template Template // namespace is a namespace of deployed service namespace string - // resourcesToValidate is a map of resource names and corresponding validation functions - resourcesToValidate map[string]resourceValidationFunc + // resourcesToValidate is a map of resource names and corresponding resources definitions + resourcesToValidate map[string]ManagedServiceResource } -func NewServiceValidator(clusterName, namespace string) *ServiceValidator { +func NewServiceValidator(clusterName, serviceName, namespace string) *ServiceValidator { return &ServiceValidator{ managedClusterName: clusterName, + managedServiceName: serviceName, namespace: namespace, - resourcesToValidate: make(map[string]resourceValidationFunc), + resourcesToValidate: make(map[string]ManagedServiceResource), } } -func (v *ServiceValidator) WithResourceValidation(resourceName string, validationFunc resourceValidationFunc) *ServiceValidator { - v.resourcesToValidate[resourceName] = validationFunc +func (v *ServiceValidator) WithResourceValidation(resourceName string, resource ManagedServiceResource) *ServiceValidator { + v.resourcesToValidate[resourceName] = resource return v } func (v *ServiceValidator) Validate(ctx context.Context, kc *kubeclient.KubeClient) error { clusterKubeClient := kc.NewFromCluster(ctx, v.namespace, v.managedClusterName) - for res, f := range v.resourcesToValidate { - err := f(ctx, clusterKubeClient, res) + for resourceName, resource := range v.resourcesToValidate { + resourceFullName := resource.resourceFullName(v.managedServiceName) + err := resource.ValidationFunc(ctx, clusterKubeClient, resourceFullName) if err != nil { - _, _ = fmt.Fprintf(GinkgoWriter, "[%s/%s] validation error: %v\n", v.template, res, err) + _, _ = fmt.Fprintf(GinkgoWriter, "[%s/%s] validation error: %v\n", v.template, resourceName, err) return err } - _, _ = fmt.Fprintf(GinkgoWriter, "[%s/%s] validation succeeded\n", v.template, res) + _, _ = fmt.Fprintf(GinkgoWriter, "[%s/%s] validation succeeded\n", v.template, resourceName) } return nil } diff --git a/test/e2e/clusterdeployment/validate_deployed.go b/test/e2e/clusterdeployment/validate_deployed.go index 1dbcd788..182112f2 100644 --- a/test/e2e/clusterdeployment/validate_deployed.go +++ b/test/e2e/clusterdeployment/validate_deployed.go @@ -273,3 +273,22 @@ func validateCCM(ctx context.Context, kc *kubeclient.KubeClient, clusterName str return fmt.Errorf("%s Service does not yet have an external hostname", service.Name) } + +func ValidateService(ctx context.Context, kc *kubeclient.KubeClient, name string) error { + _, err := kc.Client.CoreV1().Services(kc.Namespace).Get(ctx, name, metav1.GetOptions{}) + if err != nil { + return err + } + return nil +} + +func ValidateDeployment(ctx context.Context, kc *kubeclient.KubeClient, name string) error { + dep, err := kc.Client.AppsV1().Deployments(kc.Namespace).Get(ctx, name, metav1.GetOptions{}) + if err != nil { + return err + } + if *dep.Spec.Replicas != dep.Status.ReadyReplicas { + return fmt.Errorf("deployment %s has %d ready replicas, expected %d", name, dep.Status.ReadyReplicas, *dep.Spec.Replicas) + } + return nil +} diff --git a/test/e2e/provider_aws_test.go b/test/e2e/provider_aws_test.go index 3ff5202f..63131a5f 100644 --- a/test/e2e/provider_aws_test.go +++ b/test/e2e/provider_aws_test.go @@ -78,6 +78,7 @@ var _ = Describe("AWS Templates", Label("provider:cloud", "provider:aws"), Order // hosting the hosted cluster. GinkgoT().Setenv(clusterdeployment.EnvVarAWSInstanceType, "t3.xlarge") GinkgoT().Setenv(clusterdeployment.EnvVarServiceNamespace, "default") + GinkgoT().Setenv(clusterdeployment.EnvVarServiceName, "managed-ingress-nginx") templateBy(clusterdeployment.TemplateAWSStandaloneCP, "creating a ClusterDeployment") sd := clusterdeployment.GetUnstructured(clusterdeployment.TemplateAWSStandaloneCP) @@ -96,6 +97,20 @@ var _ = Describe("AWS Templates", Label("provider:cloud", "provider:aws"), Order return deploymentValidator.Validate(context.Background(), kc) }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + // validating service included in the cluster deployment is deployed + serviceDeployedValidator := clusterdeployment.NewServiceValidator(clusterName, "default", "managed-ingress-nginx"). + WithResourceValidation("service", clusterdeployment.ManagedServiceResource{ + ResourceNameSuffix: "", + ValidationFunc: clusterdeployment.ValidateService, + }). + WithResourceValidation("deployment", clusterdeployment.ManagedServiceResource{ + ResourceNameSuffix: "", + ValidationFunc: clusterdeployment.ValidateDeployment, + }) + Eventually(func() error { + return serviceDeployedValidator.Validate(context.Background(), kc) + }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + templateBy(clusterdeployment.TemplateAWSHostedCP, "installing controller and templates on standalone cluster") // Download the KUBECONFIG for the standalone cluster and load it