Skip to content

Commit dd99619

Browse files
Add kind dns override
point resolver to 8.8.8.8
1 parent 0600eaa commit dd99619

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

hack/kind/dns-override.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: v1
2+
data:
3+
Corefile: |
4+
.:53 {
5+
errors
6+
health {
7+
lameduck 5s
8+
}
9+
ready
10+
kubernetes cluster.local in-addr.arpa ip6.arpa {
11+
pods insecure
12+
fallthrough in-addr.arpa ip6.arpa
13+
ttl 30
14+
}
15+
prometheus :9153
16+
forward . 8.8.8.8
17+
cache 30
18+
loop
19+
reload
20+
loadbalance
21+
}
22+
kind: ConfigMap
23+
metadata:
24+
name: coredns
25+
namespace: kube-system

test/e2e/e2e_suite_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ import (
1111
"encoding/base64"
1212
"encoding/gob"
1313
"flag"
14+
"fmt"
15+
corev1 "k8s.io/api/core/v1"
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
"k8s.io/apimachinery/pkg/types"
18+
"k8s.io/apimachinery/pkg/util/yaml"
1419
"os"
1520
"path/filepath"
1621
"slices"
1722
"strings"
1823
"testing"
24+
"time"
1925

2026
. "github.com/onsi/ginkgo/v2"
2127
. "github.com/onsi/gomega"
@@ -111,6 +117,28 @@ var _ = SynchronizedBeforeSuite(func() []byte {
111117
useExistingCluster,
112118
)
113119

120+
By("Overriding coreDNS resolver")
121+
// override coredns resolver to 8.8.8.8 and restart coredns deployment
122+
// read the dns-override.yaml file
123+
filePath, _ := filepath.Abs("../../hack/kind/dns-override.yaml")
124+
yamlFile, err := os.ReadFile(filePath)
125+
Expect(err).To(BeNil(), "Failed to read the dns-override.yaml file")
126+
127+
// decode the yaml file into a Kubernetes object
128+
decode := yaml.NewYAMLOrJSONDecoder(bytes.NewReader(yamlFile), 4096)
129+
configMap := &corev1.ConfigMap{}
130+
err = decode.Decode(&configMap)
131+
Expect(err).To(BeNil(), "Failed to decode the yaml file into a Kubernetes object")
132+
133+
_, err = bootstrapClusterProxy.GetClientSet().CoreV1().ConfigMaps(configMap.GetNamespace()).Update(context.Background(), configMap, metav1.UpdateOptions{})
134+
Expect(err).To(BeNil(), "Failed to update the coredns deployment with the dns-override.yaml file")
135+
136+
timeNow := time.Now().Format(time.RFC3339)
137+
patch := fmt.Sprintf(`{"spec":{"template":{"metadata":{"annotations":{"kubectl.kubernetes.io/restartedAt":"%s"}}}}}`, timeNow)
138+
139+
_, err = bootstrapClusterProxy.GetClientSet().AppsV1().Deployments("kube-system").Patch(context.Background(), "coredns", types.StrategicMergePatchType, []byte(patch), metav1.PatchOptions{})
140+
Expect(err).To(BeNil(), "Failed to restart the coredns deployment")
141+
114142
By("Initializing the bootstrap cluster")
115143
initBootstrapCluster(bootstrapClusterProxy, e2eConfig, clusterctlConfigPath, artifactFolder)
116144

@@ -240,6 +268,7 @@ func setupBootstrapCluster(
240268
Expect(
241269
kubeconfigPath,
242270
).To(BeAnExistingFile(), "Failed to get the kubeconfig file for the bootstrap cluster")
271+
243272
} else {
244273
// Loading image for already created cluster
245274
imagesInput := capibootstrap.LoadImagesToKindClusterInput{

0 commit comments

Comments
 (0)