Skip to content

Commit

Permalink
Fix integration test (#386)
Browse files Browse the repository at this point in the history
* fix integration test

* make format
  • Loading branch information
MartinWeindel authored Oct 9, 2024
1 parent 5805706 commit e0f57bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 65 deletions.
8 changes: 4 additions & 4 deletions .test-defs/shootdns-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ spec:
- >-
go test -timeout=0 ./test/system
--v -ginkgo.v -ginkgo.progress -ginkgo.no-color
-seed-kubecfg=$TM_KUBECONFIG_PATH/seed.config
-shoot-kubecfg=$TM_KUBECONFIG_PATH/shoot.config
-shoot-name=$SHOOT_NAME
-project-namespace=$PROJECT_NAMESPACE
--kubecfg="$TM_KUBECONFIG_PATH/gardener.config"
--shoot-name=$SHOOT_NAME
--existing-shoot-name=$SHOOT_NAME
--project-namespace=$PROJECT_NAMESPACE
image: golang:1.23.2
86 changes: 25 additions & 61 deletions test/system/shootdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,89 +6,53 @@ package system_test

import (
"context"
"flag"
"fmt"
"net"
"net/http"
"os"
"strings"
"time"

"github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/pkg/client/kubernetes"
"github.com/gardener/gardener/pkg/extensions"
"github.com/gardener/gardener/test/framework"
. "github.com/onsi/ginkgo/v2"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/gardener/gardener-extension-shoot-dns-service/test/resources/templates"
)

var testCfg *ShootCPTestConfig

// ShootCPTestConfig holds configuration for shoot tests using the control plane
type ShootCPTestConfig struct {
ShootKubeconfig string
SeedKubeconfig string
ShootName string
ProjectNamespace string
}

func init() {
testCfg = RegisterShootCPTestFlags()
}

// RegisterShootCPTestFlags registers flags for ShootCPTestConfig
func RegisterShootCPTestFlags() *ShootCPTestConfig {
newCfg := &ShootCPTestConfig{}

flag.StringVar(&newCfg.ShootKubeconfig, "shoot-kubecfg", "", "the path with the shoot kubeconfig.")
flag.StringVar(&newCfg.SeedKubeconfig, "seed-kubecfg", "", "the path with the seed kubeconfig.")
flag.StringVar(&newCfg.ShootName, "shoot-name", "", "the shoot name")
flag.StringVar(&newCfg.ProjectNamespace, "project-namespace", "", "the project namespace of the shoot")

return newCfg
_ = framework.RegisterShootFrameworkFlags()
}

type shootDNSFramework struct {
*framework.CommonFramework
config ShootCPTestConfig

seedClient kubernetes.Interface
shootClient kubernetes.Interface
cluster *extensions.Cluster
*framework.ShootFramework
cluster *extensions.Cluster
}

func newShootDNSFramework(_ *framework.CommonConfig) *shootDNSFramework {
func newShootDNSFramework(cfg *framework.ShootConfig) *shootDNSFramework {
return &shootDNSFramework{
CommonFramework: framework.NewCommonFramework(&framework.CommonConfig{
ResourceDir: "../resources",
}),
config: *testCfg,
ShootFramework: framework.NewShootFramework(cfg),
}
}

func (f *shootDNSFramework) technicalShootId() string {
middle := strings.TrimPrefix(f.config.ProjectNamespace, "garden-")
return fmt.Sprintf("shoot--%s--%s", middle, f.config.ShootName)
middle := strings.TrimPrefix(f.ProjectNamespace, "garden-")
return fmt.Sprintf("shoot--%s--%s", middle, f.Config.ShootName)
}

func (f *shootDNSFramework) prepareClientsAndCluster() {
var err error
f.seedClient, err = kubernetes.NewClientFromFile("", f.config.SeedKubeconfig,
kubernetes.WithClientOptions(client.Options{Scheme: kubernetes.SeedScheme}),
kubernetes.WithDisabledCachedClient(),
)
framework.ExpectNoError(err)
f.shootClient, err = kubernetes.NewClientFromFile("", f.config.ShootKubeconfig,
kubernetes.WithClientOptions(client.Options{Scheme: kubernetes.ShootScheme}),
kubernetes.WithDisabledCachedClient(),
)
framework.ExpectNoError(err)
func (f *shootDNSFramework) prepareClientsAndCluster(ctx context.Context) {
if err := f.AddShoot(ctx, f.Config.ShootName, f.ProjectNamespace); err != nil {
Fail(fmt.Sprintf("addShoot failed: %s", err))
}

f.cluster, err = controller.GetCluster(context.TODO(), f.seedClient.Client(), f.technicalShootId())
framework.ExpectNoError(err)
var err error
f.cluster, err = controller.GetCluster(context.TODO(), f.SeedClient.Client(), f.technicalShootId())
if err != nil {
Fail(fmt.Sprintf("get cluster failed: %s", err))
}
if !f.cluster.Shoot.Spec.Addons.NginxIngress.Enabled {
Fail("The test requires .spec.addons.nginxIngress.enabled to be true")
}
Expand All @@ -105,17 +69,17 @@ func (f *shootDNSFramework) createNamespace(ctx context.Context, namespace strin
},
}

err := f.shootClient.Client().Create(ctx, ns)
err := f.ShootClient.Client().Create(ctx, ns)
framework.ExpectNoError(err)

return ns
}

func (f *shootDNSFramework) deleteNamespaceAndWait(ctx context.Context, ns *v1.Namespace) {
f.Logger.Info("Deleting namespace", "namespaceName", ns.Name)
err := f.shootClient.Client().Delete(ctx, ns)
err := f.ShootClient.Client().Delete(ctx, ns)
framework.ExpectNoError(err)
err = f.WaitUntilNamespaceIsDeleted(ctx, f.shootClient, ns.Name)
err = f.WaitUntilNamespaceIsDeleted(ctx, f.ShootClient, ns.Name)
framework.ExpectNoError(err)
f.Logger.Info("Deleted namespace", "namespaceName", ns.Name)
}
Expand All @@ -135,7 +99,7 @@ func (f *shootDNSFramework) createEchoheaders(ctx context.Context, svcLB, delete
"ShootDnsName": *f.cluster.Shoot.Spec.DNS.Domain,
"ServiceTypeLoadBalancer": svcLB,
}
err := f.RenderAndDeployTemplate(ctx, f.shootClient, templates.EchoserverApp, values)
err := f.RenderAndDeployTemplate(ctx, f.ShootClient, templates.EchoserverApp, values)
framework.ExpectNoError(err)

domainName := fmt.Sprintf("%s.%s", values["EchoName"], values["ShootDnsName"])
Expand All @@ -152,10 +116,10 @@ func (f *shootDNSFramework) createEchoheaders(ctx context.Context, svcLB, delete
}

var _ = Describe("ShootDNS test", func() {
dir, _ := os.Getwd()

f := newShootDNSFramework(&framework.CommonConfig{
ResourceDir: "../resources",
})
f := newShootDNSFramework(nil)
f.ResourcesDir = dir + "/../resources"

BeforeEach(f.prepareClientsAndCluster)

Expand All @@ -177,7 +141,7 @@ var _ = Describe("ShootDNS test", func() {
"Namespace": namespace,
"DNSName": domainName,
}
err := f.RenderAndDeployTemplate(ctx, f.shootClient, templates.CustomDNSEntry, values)
err := f.RenderAndDeployTemplate(ctx, f.ShootClient, templates.CustomDNSEntry, values)
framework.ExpectNoError(err)

err = awaitDNSRecord(domainName, 120*time.Second)
Expand Down

0 comments on commit e0f57bd

Please sign in to comment.