Skip to content

Commit fe4a08b

Browse files
committed
Support configuring ExtraPortMappings for the kind cluster
1 parent 28f0335 commit fe4a08b

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

test/framework/bootstrap/kind_provider.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ func WithDualStackFamily() KindClusterOption {
8282
})
8383
}
8484

85+
// WithExtraPortMappings implements a New Option that instruct the kindClusterProvider to set extra port forward mappings.
86+
func WithExtraPortMappings(mappings []kindv1.PortMapping) KindClusterOption {
87+
return kindClusterOptionAdapter(func(k *KindClusterProvider) {
88+
k.extraPortMappings = mappings
89+
})
90+
}
91+
8592
// LogFolder implements a New Option that instruct the kindClusterProvider to dump bootstrap logs in a folder in case of errors.
8693
func LogFolder(path string) KindClusterOption {
8794
return kindClusterOptionAdapter(func(k *KindClusterProvider) {
@@ -104,12 +111,13 @@ func NewKindClusterProvider(name string, options ...KindClusterOption) *KindClus
104111

105112
// KindClusterProvider implements a ClusterProvider that can create a kind cluster.
106113
type KindClusterProvider struct {
107-
name string
108-
withDockerSock bool
109-
kubeconfigPath string
110-
nodeImage string
111-
ipFamily clusterv1.ClusterIPFamily
112-
logFolder string
114+
name string
115+
withDockerSock bool
116+
kubeconfigPath string
117+
nodeImage string
118+
ipFamily clusterv1.ClusterIPFamily
119+
logFolder string
120+
extraPortMappings []kindv1.PortMapping
113121
}
114122

115123
// Create a Kubernetes cluster using kind.
@@ -139,6 +147,11 @@ func (k *KindClusterProvider) createKindCluster() {
139147
APIVersion: "kind.x-k8s.io/v1alpha4",
140148
Kind: "Cluster",
141149
},
150+
Nodes: []kindv1.Node{
151+
{
152+
ExtraPortMappings: k.extraPortMappings,
153+
},
154+
},
142155
}
143156

144157
if k.ipFamily == clusterv1.IPv6IPFamily {

test/framework/bootstrap/kind_util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
. "github.com/onsi/gomega"
2626
"github.com/pkg/errors"
27+
kindv1 "sigs.k8s.io/kind/pkg/apis/config/v1alpha4"
2728
kind "sigs.k8s.io/kind/pkg/cluster"
2829
kindnodes "sigs.k8s.io/kind/pkg/cluster/nodes"
2930
kindnodesutils "sigs.k8s.io/kind/pkg/cluster/nodeutils"
@@ -52,6 +53,9 @@ type CreateKindBootstrapClusterAndLoadImagesInput struct {
5253

5354
// LogFolder where to dump logs in case of errors
5455
LogFolder string
56+
57+
// ExtraPortMappings specifies the port forward configuration of the kind node.
58+
ExtraPortMappings []kindv1.PortMapping
5559
}
5660

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

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

0 commit comments

Comments
 (0)