Skip to content

Commit

Permalink
e2e: validate subResourceNamePrefix is used to name appgw sub-resourc…
Browse files Browse the repository at this point in the history
…es (#1040)

* check that sub-resource prefix is used

* remove continue
  • Loading branch information
akshaysngupta authored Nov 2, 2020
1 parent 2ade9ec commit d8ab6e4
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 19 deletions.
16 changes: 10 additions & 6 deletions scripts/e2e/cmd/runner/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const (

// AzureAuthLocationVarName is the name of the AZURE_AUTH_LOCATION
AzureAuthLocationVarName = "AZURE_AUTH_LOCATION"

// SubResourceNamePrefixVarName is the name of the subResourceNamePrefix
SubResourceNamePrefixVarName = "subResourceNamePrefix"
)

// EnvVariables is a struct storing values for environment variables.
Expand All @@ -47,12 +50,13 @@ type EnvVariables struct {
// GetEnv returns values for defined environment variables for Ingress Controller.
func GetEnv() *EnvVariables {
return &EnvVariables{
SubscriptionID: os.Getenv(SubscriptionIDVarName),
ResourceGroupName: os.Getenv(ResourceGroupNameVarName),
AppGwName: os.Getenv(AppGwNameVarName),
KubeConfigFilePath: GetEnvironmentVariable(KubeConfigVarName, "~/.kube/config", nil),
ObjectID: os.Getenv(ObjectIDVarName),
AzureAuthLocation: os.Getenv(AzureAuthLocationVarName),
SubscriptionID: os.Getenv(SubscriptionIDVarName),
ResourceGroupName: os.Getenv(ResourceGroupNameVarName),
AppGwName: os.Getenv(AppGwNameVarName),
SubResourceNamePrefix: os.Getenv(SubResourceNamePrefixVarName),
KubeConfigFilePath: GetEnvironmentVariable(KubeConfigVarName, "~/.kube/config", nil),
ObjectID: os.Getenv(ObjectIDVarName),
AzureAuthLocation: os.Getenv(AzureAuthLocationVarName),
}
}

Expand Down
41 changes: 29 additions & 12 deletions scripts/e2e/cmd/runner/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ func applyYaml(clientset *kubernetes.Clientset, namespaceName string, fileName s
} else {
return errors.New("namespace is not defined for secrets")
}
}
if ingress, ok := objs.(*v1beta1.Ingress); ok {
} else if ingress, ok := objs.(*v1beta1.Ingress); ok {
nm := ingress.Namespace
if len(nm) == 0 && len(namespaceName) != 0 {
if _, err := clientset.ExtensionsV1beta1().Ingresses(namespaceName).Create(ingress); err != nil {
Expand All @@ -269,8 +268,7 @@ func applyYaml(clientset *kubernetes.Clientset, namespaceName string, fileName s
} else {
return errors.New("namespace is not defined for ingress")
}
}
if service, ok := objs.(*v1.Service); ok {
} else if service, ok := objs.(*v1.Service); ok {
nm := service.Namespace
if len(nm) == 0 && len(namespaceName) != 0 {
if _, err := clientset.CoreV1().Services(namespaceName).Create(service); err != nil {
Expand All @@ -283,8 +281,7 @@ func applyYaml(clientset *kubernetes.Clientset, namespaceName string, fileName s
} else {
return errors.New("namespace is not defined for service")
}
}
if deployment, ok := objs.(*appsv1.Deployment); ok {
} else if deployment, ok := objs.(*appsv1.Deployment); ok {
nm := deployment.Namespace
if len(nm) == 0 && len(namespaceName) != 0 {
if _, err := clientset.AppsV1().Deployments(namespaceName).Create(deployment); err != nil {
Expand All @@ -297,8 +294,7 @@ func applyYaml(clientset *kubernetes.Clientset, namespaceName string, fileName s
} else {
return errors.New("namespace is not defined for deployment")
}
}
if cm, ok := objs.(*v1.ConfigMap); ok {
} else if cm, ok := objs.(*v1.ConfigMap); ok {
nm := cm.Namespace
if len(nm) == 0 && len(namespaceName) != 0 {
if _, err := clientset.CoreV1().ConfigMaps(namespaceName).Create(cm); err != nil {
Expand All @@ -311,8 +307,7 @@ func applyYaml(clientset *kubernetes.Clientset, namespaceName string, fileName s
} else {
return errors.New("namespace is not defined for configmaps")
}
}
if pod, ok := objs.(*v1.Pod); ok {
} else if pod, ok := objs.(*v1.Pod); ok {
nm := pod.Namespace
if len(nm) == 0 && len(namespaceName) != 0 {
if _, err := clientset.CoreV1().Pods(namespaceName).Create(pod); err != nil {
Expand All @@ -325,9 +320,9 @@ func applyYaml(clientset *kubernetes.Clientset, namespaceName string, fileName s
} else {
return errors.New("namespace is not defined for pods")
}
} else {
return fmt.Errorf("unable to apply YAML. Unknown object type: %v", objs)
}

return fmt.Errorf("unable to apply YAML. Unknown object type: %v", objs)
}
return nil
}
Expand Down Expand Up @@ -464,3 +459,25 @@ func readBody(resp *http.Response) (string, error) {

return "", nil
}

func getGateway() (*n.ApplicationGateway, error) {
env := GetEnv()

klog.Info("preparing app gateway client")
client, err := getApplicationGatewaysClient()
if err != nil {
return nil, err
}

gateway, err := client.Get(
context.TODO(),
env.ResourceGroupName,
env.AppGwName,
)

if err != nil {
return nil, err
}

return &gateway, nil
}
46 changes: 45 additions & 1 deletion scripts/e2e/cmd/runner/lfu_one_namespace_one_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ package runner

import (
"fmt"
"strings"
"time"

"github.com/Azure/go-autorest/autorest/to"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/klog"
Expand Down Expand Up @@ -52,6 +55,47 @@ var _ = Describe("LFU", func() {
err = clientset.CoreV1().Namespaces().Delete("test-brownfield-ns", deleteOptions)
Expect(err).To(BeNil())
})
})

It("[sub-resource-prefix] should be use the sub-resource-prefix to prefix sub-resources", func() {
env := GetEnv()
klog.Infof("'subResourceNamePrefix': %s", env.SubResourceNamePrefix)
Expect(env.SubResourceNamePrefix).ToNot(Equal(""), "Please make sure that environment variable 'subResourceNamePrefix' is set")

namespaceName := "e2e-sub-resource-prefix"
ns := &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespaceName,
},
}
klog.Info("Creating namespace: ", namespaceName)
_, err = clientset.CoreV1().Namespaces().Create(ns)
Expect(err).To(BeNil())

SSLE2ERedirectYamlPath := "testdata/one-namespace-one-ingress/ssl-e2e-redirect/app.yaml"
klog.Info("Applying yaml: ", SSLE2ERedirectYamlPath)
err = applyYaml(clientset, namespaceName, SSLE2ERedirectYamlPath)
Expect(err).To(BeNil())
time.Sleep(30 * time.Second)

gateway, err := getGateway()
Expect(err).To(BeNil())

prefixUsed := false
for _, listener := range *gateway.HTTPListeners {
klog.Infof("checking listener %s for %s", *listener.Name, env.SubResourceNamePrefix)
if strings.HasPrefix(*listener.Name, env.SubResourceNamePrefix) {
klog.Infof("found %s that uses the prefix", *listener.Name)
prefixUsed = true
break
}
}

Expect(prefixUsed).To(BeTrue(), "%s wasn't used for naming the sub-resource of app gateway. Currently, this check looks at HTTP listener only", env.SubResourceNamePrefix)
})

AfterEach(func() {
// clear all namespaces
cleanUp(clientset)
})
})
})
2 changes: 2 additions & 0 deletions scripts/e2e/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function InstallAGIC() {
helm upgrade --install agic-${version} staging/ingress-azure \
--set appgw.name=${applicationGatewayName} \
--set appgw.subnetPrefix=${applicationGatewaySubnetPrefix} \
--set appgw.subResourceNamePrefix=${subResourceNamePrefix} \
--set armAuth.type=aadPodIdentity \
--set armAuth.identityResourceID=${identityResourceId} \
--set armAuth.identityClientID=${identityClientId} \
Expand Down Expand Up @@ -87,6 +88,7 @@ function SetupSharedBackend() {
helm upgrade --install agic-${version} staging/ingress-azure \
-f ./helm-config-with-prohibited-rules.yaml \
--set appgw.applicationGatewayID=${applicationGatewayId} \
--set appgw.subResourceNamePrefix=${subResourceNamePrefix} \
--set armAuth.type=aadPodIdentity \
--set armAuth.identityResourceID=${identityResourceId} \
--set armAuth.identityClientID=${identityClientId} \
Expand Down

0 comments on commit d8ab6e4

Please sign in to comment.