Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 test/e2e: Support configuring ExtraPortMappings for the kind cluster #10046

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions test/framework/bootstrap/kind_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ func WithDualStackFamily() KindClusterOption {
})
}

// WithExtraPortMappings implements a New Option that instruct the kindClusterProvider to set extra port forward mappings.
func WithExtraPortMappings(mappings []kindv1.PortMapping) KindClusterOption {
return kindClusterOptionAdapter(func(k *KindClusterProvider) {
k.extraPortMappings = mappings
})
}

// LogFolder implements a New Option that instruct the kindClusterProvider to dump bootstrap logs in a folder in case of errors.
func LogFolder(path string) KindClusterOption {
return kindClusterOptionAdapter(func(k *KindClusterProvider) {
Expand All @@ -104,12 +111,13 @@ func NewKindClusterProvider(name string, options ...KindClusterOption) *KindClus

// KindClusterProvider implements a ClusterProvider that can create a kind cluster.
type KindClusterProvider struct {
name string
withDockerSock bool
kubeconfigPath string
nodeImage string
ipFamily clusterv1.ClusterIPFamily
logFolder string
name string
withDockerSock bool
kubeconfigPath string
nodeImage string
ipFamily clusterv1.ClusterIPFamily
logFolder string
extraPortMappings []kindv1.PortMapping
}

// Create a Kubernetes cluster using kind.
Expand Down Expand Up @@ -139,6 +147,11 @@ func (k *KindClusterProvider) createKindCluster() {
APIVersion: "kind.x-k8s.io/v1alpha4",
Kind: "Cluster",
},
Nodes: []kindv1.Node{
{
ExtraPortMappings: k.extraPortMappings,
},
},
}

if k.ipFamily == clusterv1.IPv6IPFamily {
Expand Down
5 changes: 5 additions & 0 deletions test/framework/bootstrap/kind_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

. "github.com/onsi/gomega"
"github.com/pkg/errors"
kindv1 "sigs.k8s.io/kind/pkg/apis/config/v1alpha4"
kind "sigs.k8s.io/kind/pkg/cluster"
kindnodes "sigs.k8s.io/kind/pkg/cluster/nodes"
kindnodesutils "sigs.k8s.io/kind/pkg/cluster/nodeutils"
Expand Down Expand Up @@ -52,6 +53,9 @@ type CreateKindBootstrapClusterAndLoadImagesInput struct {

// LogFolder where to dump logs in case of errors
LogFolder string

// ExtraPortMappings specifies the port forward configuration of the kind node.
ExtraPortMappings []kindv1.PortMapping
}

// CreateKindBootstrapClusterAndLoadImages returns a new Kubernetes cluster with pre-loaded images.
Expand All @@ -77,6 +81,7 @@ func CreateKindBootstrapClusterAndLoadImages(ctx context.Context, input CreateKi
if input.LogFolder != "" {
options = append(options, LogFolder(input.LogFolder))
}
options = append(options, WithExtraPortMappings(input.ExtraPortMappings))

clusterProvider := NewKindClusterProvider(input.Name, options...)
Expect(clusterProvider).ToNot(BeNil(), "Failed to create a kind cluster")
Expand Down