forked from gardener/landscaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-import.go
119 lines (97 loc) · 4.97 KB
/
simple-import.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-FileCopyrightText: 2021 SAP SE or an SAP affiliate company and Gardener contributors.
//
// SPDX-License-Identifier: Apache-2.0
package tutorial
import (
"context"
"path/filepath"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
lsv1alpha1helper "github.com/gardener/landscaper/apis/core/v1alpha1/helper"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1"
kutil "github.com/gardener/landscaper/controller-utils/pkg/kubernetes"
lsutils "github.com/gardener/landscaper/pkg/utils/landscaper"
"github.com/gardener/landscaper/test/framework"
"github.com/gardener/landscaper/test/utils"
)
func SimpleImportForNewReconcile(f *framework.Framework) {
_ = Describe("SimpleImport", func() {
state := f.Register()
It("should deploy a nginx ingress controller and a echo-server", func() {
var (
nginxTutorialResourcesRootDir = filepath.Join(f.RootPath, "/docs/tutorials/resources/local-ingress-nginx")
echoServerTutorialResourcesRootDir = filepath.Join(f.RootPath, "/docs/tutorials/resources/echo-server")
targetResource = filepath.Join(nginxTutorialResourcesRootDir, "my-target.yaml")
importResource = filepath.Join(nginxTutorialResourcesRootDir, "configmap.yaml")
nginxInstResource = filepath.Join(nginxTutorialResourcesRootDir, "installation.yaml")
echoServerInstResource = filepath.Join(echoServerTutorialResourcesRootDir, "installation.yaml")
)
ctx := context.Background()
defer ctx.Done()
By("Create Target for the installation")
target := &lsv1alpha1.Target{}
utils.ExpectNoError(utils.ReadResourceFromFile(target, targetResource))
target, err := utils.BuildInternalKubernetesTarget(ctx, f.Client, state.Namespace, target.Name, f.RestConfig, true)
utils.ExpectNoError(err)
utils.ExpectNoError(state.Create(ctx, target))
By("Create ConfigMap with imports for the installation")
cm := &corev1.ConfigMap{}
cm.SetNamespace(state.Namespace)
utils.ExpectNoError(utils.ReadResourceFromFile(cm, importResource))
cm.Data["namespace"] = state.Namespace
utils.ExpectNoError(state.Create(ctx, cm))
By("Create Nginx Ingress Installation")
nginxInst := &lsv1alpha1.Installation{}
Expect(utils.ReadResourceFromFile(nginxInst, nginxInstResource)).To(Succeed())
nginxInst.SetNamespace(state.Namespace)
lsv1alpha1helper.SetOperation(&nginxInst.ObjectMeta, lsv1alpha1.ReconcileOperation)
utils.ExpectNoError(state.Create(ctx, nginxInst))
// wait for installation to finish
utils.ExpectNoError(lsutils.WaitForInstallationToFinish(ctx, f.Client, nginxInst, lsv1alpha1.InstallationPhaseSucceeded, 2*time.Minute))
By("Create echo server Installation")
inst := &lsv1alpha1.Installation{}
Expect(utils.ReadResourceFromFile(inst, echoServerInstResource)).To(Succeed())
inst.SetNamespace(state.Namespace)
lsv1alpha1helper.SetOperation(&inst.ObjectMeta, lsv1alpha1.ReconcileOperation)
utils.ExpectNoError(state.Create(ctx, inst))
// wait for installation to finish
utils.ExpectNoError(lsutils.WaitForInstallationToFinish(ctx, f.Client, inst, lsv1alpha1.InstallationPhaseSucceeded, 2*time.Minute))
deployItems, err := lsutils.GetDeployItemsOfInstallation(ctx, f.Client, inst)
utils.ExpectNoError(err)
Expect(deployItems).To(HaveLen(1))
Expect(deployItems[0].Status.DeployItemPhase).To(Equal(lsv1alpha1.DeployItemPhaseSucceeded))
Expect(deployItems[0].Status.JobIDFinished).To(Equal(deployItems[0].Status.GetJobID()))
// expect that the echo server deployment is successfully running
echoServerDeploymentName := "echo-server"
echoServerObjectKey := kutil.ObjectKey(echoServerDeploymentName, state.Namespace)
utils.ExpectNoError(utils.WaitForDeploymentToBeReady(ctx, f.TestLog(), f.Client, echoServerObjectKey, 2*time.Minute))
// todo check if the echo server can be pinged
By("Delete echo server installation")
utils.ExpectNoError(f.Client.Delete(ctx, inst))
utils.ExpectNoError(utils.WaitForObjectDeletion(ctx, f.Client, inst, 2*time.Minute))
// expect that the echo server deployment will be deleted
echoServerDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: echoServerObjectKey.Name,
Namespace: echoServerObjectKey.Namespace,
},
}
utils.ExpectNoError(utils.WaitForObjectDeletion(ctx, f.Client, echoServerDeployment, 2*time.Minute))
By("Delete nginx installation")
utils.ExpectNoError(f.Client.Delete(ctx, nginxInst))
utils.ExpectNoError(utils.WaitForObjectDeletion(ctx, f.Client, nginxInst, 2*time.Minute))
// expect that the nginx deployment will be deleted
nginxDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-ingress-nginx-controller",
Namespace: state.Namespace,
},
}
utils.ExpectNoError(utils.WaitForObjectDeletion(ctx, f.Client, nginxDeployment, 2*time.Minute))
})
})
}