-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmachine_create_test.go
More file actions
74 lines (68 loc) · 2.84 KB
/
machine_create_test.go
File metadata and controls
74 lines (68 loc) · 2.84 KB
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
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0
package server_test
import (
computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1"
machinebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/machinebroker/api/v1alpha1"
"github.com/ironcore-dev/ironcore/broker/machinebroker/apiutils"
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
machinepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var _ = Describe("CreateMachine", func() {
ns, srv := SetupTest()
machineClass := SetupMachineClass()
It("should correctly create a machine", func(ctx SpecContext) {
By("creating a machine")
res, err := srv.CreateMachine(ctx, &iri.CreateMachineRequest{
Machine: &iri.Machine{
Metadata: &irimeta.ObjectMetadata{
Labels: map[string]string{
machinepoolletv1alpha1.MachineUIDLabel: "foobar",
},
},
Spec: &iri.MachineSpec{
Power: iri.Power_POWER_ON,
Class: machineClass.Name,
Volumes: []*iri.Volume{{
Name: "root",
LocalDisk: &iri.LocalDisk{
Image: &iri.ImageSpec{
Image: "example.org/foo:latest",
},
},
}},
},
},
})
Expect(err).NotTo(HaveOccurred())
Expect(res).NotTo(BeNil())
By("getting the ironcore machine")
ironcoreMachine := &computev1alpha1.Machine{}
ironcoreMachineKey := client.ObjectKey{Namespace: ns.Name, Name: res.Machine.Metadata.Id}
Expect(k8sClient.Get(ctx, ironcoreMachineKey, ironcoreMachine)).To(Succeed())
By("inspecting the ironcore machine")
Expect(ironcoreMachine.Labels).To(Equal(map[string]string{
poolletutils.DownwardAPILabel(machinepoolletv1alpha1.MachineDownwardAPIPrefix, "root-machine-uid"): "foobar",
machinebrokerv1alpha1.CreatedLabel: "true",
machinebrokerv1alpha1.ManagerLabel: machinebrokerv1alpha1.MachineBrokerManager,
machinepoolletv1alpha1.MachineUIDLabel: "foobar",
}))
encodedIRIAnnotations, err := apiutils.EncodeAnnotationsAnnotation(nil)
Expect(err).NotTo(HaveOccurred())
encodedIRILabels, err := apiutils.EncodeLabelsAnnotation(map[string]string{
machinepoolletv1alpha1.MachineUIDLabel: "foobar",
})
Expect(err).NotTo(HaveOccurred())
Expect(ironcoreMachine.Annotations).To(Equal(map[string]string{
machinebrokerv1alpha1.AnnotationsAnnotation: encodedIRIAnnotations,
machinebrokerv1alpha1.LabelsAnnotation: encodedIRILabels,
}))
Expect(ironcoreMachine.Spec.Power).To(Equal(computev1alpha1.PowerOn))
Expect(ironcoreMachine.Spec.MachineClassRef.Name).To(Equal(machineClass.Name))
})
})