Skip to content

Commit

Permalink
e2e: Use Helm chart from the commit (kubernetes-sigs#2435)
Browse files Browse the repository at this point in the history
* e2e: Use Helm chart from the commit

* Address review comments
  • Loading branch information
johngmyers authored and Timothy-Dougherty committed Nov 9, 2023
1 parent d8c0c4b commit b7645e8
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 23 deletions.
3 changes: 3 additions & 0 deletions scripts/ci_e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ CLUSTER_INSTANCE_TYPE="m5.xlarge"
CLUSTER_NODE_COUNT="4"
CLUSTER_KUBECONFIG=${CLUSTER_KUBECONFIG:-"/tmp/lb-controller-e2e/clusters/${CLUSTER_NAME}.kubeconfig"}

HELM_DIR="$(cd $(dirname "${BASH_SOURCE[0]}")/../helm ; pwd)"

#######################################
# Build and push ECR image for AWS Load Balancer Controller
#
Expand Down Expand Up @@ -227,6 +229,7 @@ test_controller_image() {
--cluster-name=${CLUSTER_NAME} \
--aws-region=${AWS_REGION} \
--aws-vpc-id=${cluster_vpc_id} \
--helm-chart=${HELM_DIR}/aws-load-balancer-controller \
--controller-image=${CONTROLLER_IMAGE_NAME} \
--s3-bucket-name=${S3_BUCKET} \
--certificate-arns=${CERTIFICATE_ARNS}
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/ingress/multi_path_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package ingress
import (
"context"
"fmt"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2"
"sigs.k8s.io/aws-load-balancer-controller/test/framework"
"sigs.k8s.io/aws-load-balancer-controller/test/framework/http"
"sigs.k8s.io/aws-load-balancer-controller/test/framework/utils"
"time"
)

var _ = Describe("test ingresses with multiple path and backends", func() {
Expand All @@ -23,7 +24,8 @@ var _ = Describe("test ingresses with multiple path and backends", func() {

if tf.Options.ControllerImage != "" {
By(fmt.Sprintf("ensure cluster installed with controller: %s", tf.Options.ControllerImage), func() {
tf.CTRLInstallationManager.UpgradeController(tf.Options.ControllerImage)
err := tf.CTRLInstallationManager.UpgradeController(tf.Options.ControllerImage)
Expect(err).NotTo(HaveOccurred())
time.Sleep(60 * time.Second)
})
}
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/ingress/vanilla_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package ingress
import (
"context"
"fmt"
"net/http"
"time"

awssdk "github.com/aws/aws-sdk-go/aws"
"github.com/gavv/httpexpect/v2"
. "github.com/onsi/ginkgo"
Expand All @@ -12,13 +15,11 @@ import (
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"net/http"
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
"sigs.k8s.io/aws-load-balancer-controller/test/framework"
"sigs.k8s.io/aws-load-balancer-controller/test/framework/fixture"
"sigs.k8s.io/aws-load-balancer-controller/test/framework/manifest"
"sigs.k8s.io/aws-load-balancer-controller/test/framework/utils"
"time"
)

var _ = Describe("vanilla ingress tests", func() {
Expand All @@ -32,7 +33,8 @@ var _ = Describe("vanilla ingress tests", func() {
ctx = context.Background()
if tf.Options.ControllerImage != "" {
By(fmt.Sprintf("ensure cluster installed with controller: %s", tf.Options.ControllerImage), func() {
tf.CTRLInstallationManager.UpgradeController(tf.Options.ControllerImage)
err := tf.CTRLInstallationManager.UpgradeController(tf.Options.ControllerImage)
Expect(err).NotTo(HaveOccurred())
time.Sleep(60 * time.Second)
})
}
Expand Down
1 change: 0 additions & 1 deletion test/framework/controller/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controller
import "time"

const (
EKSHelmChartsRepo = "https://aws.github.io/eks-charts"
AWSLoadBalancerControllerHelmChart = "aws-load-balancer-controller"
AWSLoadBalancerControllerHelmRelease = "aws-load-balancer-controller"
AWSLoadBalancerControllerInstallationTimeout = 2 * time.Minute
Expand Down
11 changes: 7 additions & 4 deletions test/framework/controller/installation_manager.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package controller

import (
"strings"

"github.com/go-logr/logr"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/uuid"
"sigs.k8s.io/aws-load-balancer-controller/test/framework/helm"
"strings"
)

// InstallationManager is responsible for manage controller installation in cluster.
Expand All @@ -15,12 +16,13 @@ type InstallationManager interface {
}

// NewDefaultInstallationManager constructs new defaultInstallationManager.
func NewDefaultInstallationManager(helmReleaseManager helm.ReleaseManager, clusterName string, region string, vpcID string, logger logr.Logger) *defaultInstallationManager {
func NewDefaultInstallationManager(helmReleaseManager helm.ReleaseManager, clusterName string, region string, vpcID string, helmChart string, logger logr.Logger) *defaultInstallationManager {
return &defaultInstallationManager{
helmReleaseManager: helmReleaseManager,
clusterName: clusterName,
region: region,
vpcID: vpcID,
helmChart: helmChart,

namespace: "kube-system",
controllerSAName: "aws-load-balancer-controller",
Expand All @@ -36,6 +38,7 @@ type defaultInstallationManager struct {
clusterName string
region string
vpcID string
helmChart string

namespace string
controllerSAName string
Expand All @@ -44,7 +47,7 @@ type defaultInstallationManager struct {

func (m *defaultInstallationManager) ResetController() error {
vals := m.computeDefaultHelmVals()
_, err := m.helmReleaseManager.InstallOrUpgradeRelease(EKSHelmChartsRepo, AWSLoadBalancerControllerHelmChart,
_, err := m.helmReleaseManager.InstallOrUpgradeRelease(m.helmChart,
m.namespace, AWSLoadBalancerControllerHelmRelease, vals,
helm.WithTimeout(AWSLoadBalancerControllerInstallationTimeout))
return err
Expand All @@ -63,7 +66,7 @@ func (m *defaultInstallationManager) UpgradeController(controllerImage string) e
vals["podLabels"] = map[string]string{
"revision": string(uuid.NewUUID()),
}
_, err = m.helmReleaseManager.InstallOrUpgradeRelease(EKSHelmChartsRepo, AWSLoadBalancerControllerHelmChart,
_, err = m.helmReleaseManager.InstallOrUpgradeRelease(m.helmChart,
m.namespace, AWSLoadBalancerControllerHelmRelease, vals,
helm.WithTimeout(AWSLoadBalancerControllerInstallationTimeout))
return err
Expand Down
2 changes: 1 addition & 1 deletion test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ func InitFramework() (*Framework, error) {

func buildControllerInstallationManager(options Options, logger logr.Logger) controller.InstallationManager {
helmReleaseManager := helm.NewDefaultReleaseManager(options.KubeConfig, logger)
ctrlInstallationManager := controller.NewDefaultInstallationManager(helmReleaseManager, options.ClusterName, options.AWSRegion, options.AWSVPCID, logger)
ctrlInstallationManager := controller.NewDefaultInstallationManager(helmReleaseManager, options.ClusterName, options.AWSRegion, options.AWSVPCID, options.HelmChart, logger)
return ctrlInstallationManager
}
21 changes: 10 additions & 11 deletions test/framework/helm/release_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package helm

import (
"fmt"
"time"

"github.com/go-logr/logr"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage/driver"
"k8s.io/cli-runtime/pkg/genericclioptions"
"time"
)

// ActionOptions contains general helm action options
Expand Down Expand Up @@ -38,15 +39,15 @@ func WithTimeout(timeout time.Duration) ActionOption {
// ReleaseManager is responsible for manage helm releases
type ReleaseManager interface {
// InstallOrUpgradeRelease install or upgrade helm release
InstallOrUpgradeRelease(chartRepo string, chartName string,
InstallOrUpgradeRelease(chartName string,
namespace string, releaseName string, vals map[string]interface{}, opts ...ActionOption) (*release.Release, error)

// InstallRelease install helm release
InstallRelease(chartRepo string, chartName string,
InstallRelease(chartName string,
namespace string, releaseName string, vals map[string]interface{}, opts ...ActionOption) (*release.Release, error)

// UpgradeRelease upgrade helm release
UpgradeRelease(chartRepo string, chartName string,
UpgradeRelease(chartName string,
namespace string, releaseName string, vals map[string]interface{}, opts ...ActionOption) (*release.Release, error)
}

Expand All @@ -66,24 +67,23 @@ type defaultReleaseManager struct {
logger logr.Logger
}

func (m *defaultReleaseManager) InstallOrUpgradeRelease(chartRepo string, chartName string,
func (m *defaultReleaseManager) InstallOrUpgradeRelease(chartName string,
namespace string, releaseName string, vals map[string]interface{}, opts ...ActionOption) (*release.Release, error) {
actionCFG := m.obtainActionConfig(namespace)
historyAction := action.NewHistory(actionCFG)
historyAction.Max = 1
if _, err := historyAction.Run(releaseName); err == driver.ErrReleaseNotFound {
return m.InstallRelease(chartRepo, chartName, namespace, releaseName, vals, opts...)
return m.InstallRelease(chartName, namespace, releaseName, vals, opts...)
} else {
return m.UpgradeRelease(chartRepo, chartName, namespace, releaseName, vals, opts...)
return m.UpgradeRelease(chartName, namespace, releaseName, vals, opts...)
}
}

func (m *defaultReleaseManager) InstallRelease(chartRepo string, chartName string,
func (m *defaultReleaseManager) InstallRelease(chartName string,
namespace string, releaseName string, vals map[string]interface{}, opts ...ActionOption) (*release.Release, error) {

actionCFG := m.obtainActionConfig(namespace)
installAction := action.NewInstall(actionCFG)
installAction.ChartPathOptions.RepoURL = chartRepo
installAction.Namespace = namespace
installAction.SkipCRDs = false
installAction.ReleaseName = releaseName
Expand All @@ -107,12 +107,11 @@ func (m *defaultReleaseManager) InstallRelease(chartRepo string, chartName strin
return installAction.Run(chartRequested, vals)
}

func (m *defaultReleaseManager) UpgradeRelease(chartRepo string, chartName string,
func (m *defaultReleaseManager) UpgradeRelease(chartName string,
namespace string, releaseName string, vals map[string]interface{}, opts ...ActionOption) (*release.Release, error) {

actionCFG := m.obtainActionConfig(namespace)
upgradeAction := action.NewUpgrade(actionCFG)
upgradeAction.ChartPathOptions.RepoURL = chartRepo
upgradeAction.Namespace = namespace
upgradeAction.ResetValues = true

Expand Down
5 changes: 4 additions & 1 deletion test/framework/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"

"github.com/pkg/errors"
"sigs.k8s.io/aws-load-balancer-controller/test/framework/controller"
)

var globalOptions Options
Expand All @@ -12,11 +13,12 @@ func init() {
globalOptions.BindFlags()
}

// configuration options
// Options are the configuration options.
type Options struct {
ClusterName string
AWSRegion string
AWSVPCID string
HelmChart string
KubeConfig string

// AWS Load Balancer Controller image. leave empty to use default one from helm chart.
Expand All @@ -31,6 +33,7 @@ func (options *Options) BindFlags() {
flag.StringVar(&options.ClusterName, "cluster-name", "", `Kubernetes cluster name (required)`)
flag.StringVar(&options.AWSRegion, "aws-region", "", `AWS Region for the kubernetes cluster`)
flag.StringVar(&options.AWSVPCID, "aws-vpc-id", "", `ID of VPC to create load balancers in`)
flag.StringVar(&options.HelmChart, "helm-chart", controller.AWSLoadBalancerControllerHelmChart, `Helm chart`)

flag.StringVar(&options.ControllerImage, "controller-image", "", `AWS Load Balancer Controller image`)

Expand Down

0 comments on commit b7645e8

Please sign in to comment.