Skip to content

Commit 5a48311

Browse files
committed
create the fake cluster on FKAS in e2e
1 parent 50b7af2 commit 5a48311

File tree

6 files changed

+71
-3
lines changed

6 files changed

+71
-3
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ E2E_TEMPLATES_DIR ?= $(ROOT_DIR)/test/e2e/data/infrastructure-metal3
172172
cluster-templates: $(KUSTOMIZE) ## Generate cluster templates
173173
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-ubuntu > $(E2E_OUT_DIR)/cluster-template-ubuntu.yaml
174174
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-centos > $(E2E_OUT_DIR)/cluster-template-centos.yaml
175+
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-centos-fake > $(E2E_OUT_DIR)/cluster-template-centos-fake.yaml
175176
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-upgrade-workload > $(E2E_OUT_DIR)/cluster-template-upgrade-workload.yaml
176177
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-centos-md-remediation > $(E2E_OUT_DIR)/cluster-template-centos-md-remediation.yaml
177178
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-ubuntu-md-remediation > $(E2E_OUT_DIR)/cluster-template-ubuntu-md-remediation.yaml

test/e2e/basic_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
var _ = Describe("When testing basic cluster creation [basic]", Label("basic"), func() {
1313
BeforeEach(func() {
14-
osType := strings.ToLower(os.Getenv("OS"))
14+
osType := strings.ToLower(os.Getenv("OS"))+"-fake"
1515
Expect(osType).ToNot(Equal(""))
1616
validateGlobals(specName)
1717

@@ -23,7 +23,7 @@ var _ = Describe("When testing basic cluster creation [basic]", Label("basic"),
2323
By("Fetching cluster configuration")
2424
k8sVersion := e2eConfig.GetVariable("KUBERNETES_VERSION")
2525
By("Provision Workload cluster")
26-
targetCluster, _ = createTargetCluster(k8sVersion)
26+
targetCluster, _ = createFakeTargetCluster(k8sVersion)
2727
})
2828

2929
AfterEach(func() {

test/e2e/config/e2e_conf.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ providers:
150150
targetName: "cluster-template-ubuntu.yaml"
151151
- sourcePath: "../_out/cluster-template-centos.yaml"
152152
targetName: "cluster-template-centos.yaml"
153+
- sourcePath: "../_out/cluster-template-centos-fake.yaml"
154+
targetName: "cluster-template-centos-fake.yaml"
153155
- sourcePath: "../_out/clusterclass.yaml"
154156
targetName: "clusterclass-test-clusterclass.yaml"
155157
- sourcePath: "../_out/cluster-template-centos-md-remediation.yaml"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resources:
2+
- ../bases/ippool
3+
- ../bases/centos-kubeadm-config
4+
- secrets.yaml
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
labels:
6+
cluster.x-k8s.io/cluster-name: ${cluster}
7+
name: ${cluster}-ca
8+
namespace: ${namespace}
9+
type: kubernetes.io/tls
10+
data:
11+
tls.crt: ${caCertEncoded}
12+
tls.key: ${caKeyEncoded}
13+
---
14+
apiVersion: v1
15+
kind: Secret
16+
metadata:
17+
labels:
18+
cluster.x-k8s.io/cluster-name: ${cluster}
19+
name: ${cluster}-etcd
20+
namespace: ${namespace}
21+
type: kubernetes.io/tls
22+
data:
23+
tls.crt: ${etcdCertEncoded}
24+
tls.key: ${etcdKeyEncoded}

test/e2e/pivoting_based_feature_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1717
infrav1 "github.com/metal3-io/cluster-api-provider-metal3/api/v1beta1"
1818
"net/http"
19+
b64 "encoding/base64"
20+
"io/ioutil"
21+
"encoding/json"
1922
)
2023

2124
var (
@@ -173,6 +176,40 @@ var _ = Describe("Testing features in ephemeral or target cluster [pivoting] [fe
173176

174177
})
175178

179+
type Endpoint struct {
180+
Host string
181+
Port int
182+
}
183+
func check(e error){
184+
if e != nil {
185+
panic(e)
186+
}
187+
}
188+
func createFakeTargetCluster(k8sVersion string) (framework.ClusterProxy, *clusterctl.ApplyClusterTemplateAndWaitResult) {
189+
190+
caKey, err:= os.ReadFile("/tmp/ca.key")
191+
check(err)
192+
caCert, err:= os.ReadFile("/tmp/ca.crt")
193+
check(err)
194+
etcdKey, err:= os.ReadFile("/tmp/etcd.key")
195+
check(err)
196+
etcdCert, err:= os.ReadFile("/tmp/etcd.crt")
197+
check(err)
198+
caKeyEncoded:=b64.StdEncoding.EncodeToString(caKey)
199+
caCertEncoded:=b64.StdEncoding.EncodeToString(caCert)
200+
etcdKeyEncoded:=b64.StdEncoding.EncodeToString(etcdKey)
201+
etcdCertEncoded:=b64.StdEncoding.EncodeToString(etcdCert)
202+
cluster_endpoints, err :=http.Get("http://172.22.0.2:3333/register?resource=metal3/test72&caKey="+caKeyEncoded+"&caCert="+caCertEncoded+"&etcdKey="+etcdKeyEncoded+"&etcdCert="+etcdCertEncoded)
203+
check(err)
204+
defer cluster_endpoints.Body.Close()
205+
body, err := ioutil.ReadAll(cluster_endpoints.Body)
206+
check(err)
207+
var response Endpoint
208+
json.Unmarshal(body, &response)
209+
Logf("CLUSTER_APIENDPOINT_HOST %v CLUSTER_APIENDPOINT_PORT %v", response.Host, response.Port)
210+
return createTargetCluster(k8sVersion)
211+
212+
}
176213
func createTargetCluster(k8sVersion string) (framework.ClusterProxy, *clusterctl.ApplyClusterTemplateAndWaitResult) {
177214
By("Creating a high available cluster")
178215
imageURL, imageChecksum := EnsureImage(k8sVersion)
@@ -212,7 +249,7 @@ func createTargetCluster(k8sVersion string) (framework.ClusterProxy, *clusterctl
212249
for _, m3machine := range metal3Machines.Items {
213250
providerID:="metal3://metal3/"+Metal3MachineToBmhName(m3machine)+"/"+m3machine.GetName()
214251
machine, _ := Metal3MachineToMachineName(m3machine)
215-
resp, err :=http.Get("http://localhost:3333/updateNode?resource=metal3/test1&nodeName="+machine+"&providerID="+providerID)
252+
resp, err :=http.Get("http://172.22.0.2:3333/updateNode?resource=metal3/test1&nodeName="+machine+"&providerID="+providerID)
216253
Logf("resp : %v err: %v", resp, err)
217254
}
218255
},

0 commit comments

Comments
 (0)