Skip to content

Commit

Permalink
scaffold service validator
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Bortnikov <[email protected]>
  • Loading branch information
BROngineer committed Jan 8, 2025
1 parent 7a4e501 commit d218cad
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/e2e/clusterdeployment/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
// debugging of test failures.
EnvVarNoCleanup = "NO_CLEANUP"

EnvVarServiceNamespace = "SERVICE_NAMESPACE"

// AWS
EnvVarAWSAccessKeyID = "AWS_ACCESS_KEY_ID"
EnvVarAWSSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ 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}
65 changes: 65 additions & 0 deletions test/e2e/clusterdeployment/servicevalidator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2024
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package clusterdeployment

import (
"context"
"fmt"

. "github.com/onsi/ginkgo/v2"

"github.com/K0rdent/kcm/test/e2e/kubeclient"
)

type ServiceValidator struct {
// managedClusterName is the name of managed cluster
managedClusterName 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
}

func NewServiceValidator(clusterName, namespace string) *ServiceValidator {
return &ServiceValidator{
managedClusterName: clusterName,
namespace: namespace,
resourcesToValidate: make(map[string]resourceValidationFunc),
}
}

func (v *ServiceValidator) WithResourceValidation(resourceName string, validationFunc resourceValidationFunc) *ServiceValidator {
v.resourcesToValidate[resourceName] = validationFunc
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)
if err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "[%s/%s] validation error: %v\n", v.template, res, err)
return err
}
_, _ = fmt.Fprintf(GinkgoWriter, "[%s/%s] validation succeeded\n", v.template, res)
}
return nil
}
1 change: 1 addition & 0 deletions test/e2e/provider_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var _ = Describe("AWS Templates", Label("provider:cloud", "provider:aws"), Order
// Deploy standalone with an xlarge instance since it will also be
// hosting the hosted cluster.
GinkgoT().Setenv(clusterdeployment.EnvVarAWSInstanceType, "t3.xlarge")
GinkgoT().Setenv(clusterdeployment.EnvVarServiceNamespace, "default")

templateBy(clusterdeployment.TemplateAWSStandaloneCP, "creating a ClusterDeployment")
sd := clusterdeployment.GetUnstructured(clusterdeployment.TemplateAWSStandaloneCP)
Expand Down

0 comments on commit d218cad

Please sign in to comment.