Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Use vm operator v1.8.6 for supervisor e2e testing #2894

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ VM_OPERATOR_IMAGE_NAME ?= extra/vm-operator
VM_OPERATOR_CONTROLLER_IMG ?= $(STAGING_REGISTRY)/$(VM_OPERATOR_IMAGE_NAME)
VM_OPERATOR_DIR := test/infrastructure/vm-operator
VM_OPERATOR_TMP_DIR ?= vm-operator.tmp
VM_OPERATOR_VERSION ?= v1.8.1
VM_OPERATOR_COMMIT ?= de75746a9505ef3161172d99b735d6593c54f0c5
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
VM_OPERATOR_VERSION ?= v1.8.6-0-gde75746a-dirty
VM_OPERATOR_ALL_ARCH = amd64 arm64

# It is set by Prow GIT_TAG, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971
Expand Down Expand Up @@ -783,14 +784,17 @@ vm-operator-checkout:
@if [ -z "${VM_OPERATOR_VERSION}" ]; then echo "VM_OPERATOR_VERSION is not set"; exit 1; fi
@if [ -d "$(VM_OPERATOR_TMP_DIR)" ]; then \
echo "$(VM_OPERATOR_TMP_DIR) exists, skipping clone"; \
cd "$(VM_OPERATOR_TMP_DIR)"; \
if [ "$$(git describe --match "v[0-9]*")" != "$(VM_OPERATOR_VERSION)" ]; then \
echo "ERROR: checked out version $$(git describe --match "v[0-9]*") does not match expected version $(VM_OPERATOR_VERSION)"; \
exit 1; \
fi \
else \
git clone --depth 1 --branch "$(VM_OPERATOR_VERSION)" "https://github.com/vmware-tanzu/vm-operator.git" "$(VM_OPERATOR_TMP_DIR)"; \
git clone "https://github.com/vmware-tanzu/vm-operator.git" "$(VM_OPERATOR_TMP_DIR)"; \
cd "$(VM_OPERATOR_TMP_DIR)"; \
git checkout "$(VM_OPERATOR_COMMIT)"; \
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
git apply "../test/infrastructure/vm-operator/Fix_defaulting_for_Named_networks.patch"; \
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
fi
@cd "$(ROOT_DIR)/$(VM_OPERATOR_TMP_DIR)"; \
if [ "$$(git describe --dirty 2> /dev/null)" != "$(VM_OPERATOR_VERSION)" ]; then \
echo "ERROR: checked out version $$(git describe --dirty 2> /dev/null) does not match expected version $(VM_OPERATOR_VERSION)"; \
exit 1; \
fi
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: vm-operator-manifest-build
vm-operator-manifest-build: $(RELEASE_DIR) $(KUSTOMIZE) vm-operator-checkout ## Build the vm-operator manifest yaml file
Expand Down
110 changes: 104 additions & 6 deletions test/framework/vmoperator/vmoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"fmt"
"net"
"net/url"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -343,10 +344,10 @@
for _, vmc := range config.Spec.VirtualMachineClasses {
vmClass := &vmoprv1.VirtualMachineClass{
ObjectMeta: metav1.ObjectMeta{
Name: vmc.Name,
Name: vmc.Name,
Namespace: config.Namespace,
},
Spec: vmoprv1.VirtualMachineClassSpec{
// TODO: figure out if to make vm class configurable via API
Hardware: vmoprv1.VirtualMachineClassHardware{
Cpus: vmc.Cpus,
Memory: vmc.Memory,
Expand Down Expand Up @@ -571,17 +572,19 @@

virtualMachineImage := &vmoprv1.VirtualMachineImage{
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
ObjectMeta: metav1.ObjectMeta{
Name: libraryItem.Name,
Name: libraryItem.Name,
Namespace: config.Namespace,
},
Spec: vmoprv1.VirtualMachineImageSpec{
ImageID: libraryItemID,
ImageSourceType: "Content Library",
Type: "ovf",
ProviderRef: vmoprv1.ContentProviderReference{
APIVersion: vmoprv1.SchemeGroupVersion.String(),
Kind: "ContentLibraryProvider",
Name: contentLibraryProvider.Name,
Namespace: contentLibraryProvider.Namespace,
Kind: "ContentLibraryItem",
// Not 100% sure about following values now that Kind is required to be ContentLibraryItem, but this doesn't seem to be an issue
Name: contentLibraryProvider.Name,
Namespace: contentLibraryProvider.Namespace,
},
ProductInfo: vmoprv1.VirtualMachineImageProductInfo{
FullVersion: item.ProductInfo,
Expand Down Expand Up @@ -614,6 +617,22 @@
return retryError
}

// Fakes reconciliation of virtualMachineImage by setting required status field for the image to be considered ready.
virtualMachineImageReconciled := virtualMachineImage.DeepCopy()
virtualMachineImageReconciled.Status.ImageName = virtualMachineImage.Name
Set(virtualMachineImageReconciled, TrueCondition(ReadyConditionType))
_ = wait.PollUntilContextTimeout(ctx, 250*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (bool, error) {
retryError = nil
if err := c.Status().Patch(ctx, virtualMachineImageReconciled, client.MergeFrom(virtualMachineImage)); err != nil {
retryError = errors.Wrapf(err, "failed to patch vm-operator VirtualMachineImage %s", virtualMachineImage.Name)
}
log.Info("Patched vm-operator VirtualMachineImage", "ContentSource", klog.KObj(contentSource), "ContentLibraryProvider", klog.KObj(contentLibraryProvider), "VirtualMachineImage", klog.KObj(virtualMachineImage))
return true, nil
})
if retryError != nil {
return retryError
}

existingFiles, err := libMgr.ListLibraryItemFiles(ctx, libraryItemID)
if err != nil {
return errors.Wrapf(err, "failed to list files for vm-operator libraryItem %s", libraryItem.Name)
Expand Down Expand Up @@ -669,3 +688,82 @@

return nil
}

// NOTE: code below is a fork of vm-operator's pkg/conditions (so we can avoid to import the entire project)

Check failure on line 692 in test/framework/vmoperator/vmoperator.go

View workflow job for this annotation

GitHub Actions / lint (test)

Comment should end in a period (godot)

Check failure on line 692 in test/framework/vmoperator/vmoperator.go

View workflow job for this annotation

GitHub Actions / lint (test)

Comment should end in a period (godot)

const (
ReadyConditionType = "Ready"
)

type Getter interface {
client.Object

// GetConditions returns the list of conditions for a cluster API object.
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
GetConditions() vmoprv1.Conditions
}

type Setter interface {
Getter
SetConditions(vmoprv1.Conditions)
}

func Set(to Setter, condition *vmoprv1.Condition) {
if to == nil || condition == nil {
return
}

// Check if the new conditions already exists, and change it only if there is a status
// transition (otherwise we should preserve the current last transition time)-
conditions := to.GetConditions()
exists := false
for i := range conditions {
existingCondition := conditions[i]
if existingCondition.Type == condition.Type {
exists = true
if !hasSameState(&existingCondition, condition) {
condition.LastTransitionTime = metav1.NewTime(time.Now().UTC().Truncate(time.Second))
conditions[i] = *condition
break
}
condition.LastTransitionTime = existingCondition.LastTransitionTime
break
}
}

// If the condition does not exist, add it, setting the transition time only if not already set
if !exists {
if condition.LastTransitionTime.IsZero() {
condition.LastTransitionTime = metav1.NewTime(time.Now().UTC().Truncate(time.Second))
}
conditions = append(conditions, *condition)
}

// Sorts conditions for convenience of the consumer, i.e. kubectl.
sort.Slice(conditions, func(i, j int) bool {
return lexicographicLess(&conditions[i], &conditions[j])
})

to.SetConditions(conditions)
}

func lexicographicLess(i, j *vmoprv1.Condition) bool {
return (i.Type == ReadyConditionType || i.Type < j.Type) && j.Type != ReadyConditionType
}

func hasSameState(i, j *vmoprv1.Condition) bool {
return i.Type == j.Type &&
i.Status == j.Status &&
i.Reason == j.Reason &&
i.Message == j.Message
}

func TrueCondition(t vmoprv1.ConditionType) *vmoprv1.Condition {
return &vmoprv1.Condition{
Type: t,
Status: corev1.ConditionTrue,
// This is a non-empty field in metav1.Conditions, when it was not in our v1a1 Conditions. This
// really doesn't work with how we've defined our conditions so do something to make things
// work for now.
Reason: string(corev1.ConditionTrue),
}
}
8 changes: 8 additions & 0 deletions test/infrastructure/vcsim/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ rules:
- get
- list
- watch
- apiGroups:
- vmoperator.vmware.com
resources:
- virtualmachineimages/status
verbs:
- get
- patch
- update
- apiGroups:
- vmoperator.vmware.com
resources:
Expand Down
1 change: 1 addition & 0 deletions test/infrastructure/vcsim/controllers/vcsim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type VCenterSimulatorReconciler struct {
// +kubebuilder:rbac:groups=vmoperator.vmware.com,resources=contentsources,verbs=get;list;watch;create
// +kubebuilder:rbac:groups=vmoperator.vmware.com,resources=contentsourcebindings,verbs=get;list;watch;create
// +kubebuilder:rbac:groups=vmoperator.vmware.com,resources=virtualmachineimages,verbs=get;list;watch;create
// +kubebuilder:rbac:groups=vmoperator.vmware.com,resources=virtualmachineimages/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=storage.k8s.io,resources=storageclasses,verbs=get;list;watch;create
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;create
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Subject: [PATCH] Fix defaulting for Named networks
---
Index: webhooks/virtualmachine/v1alpha2/validation/virtualmachine_validator.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/webhooks/virtualmachine/v1alpha2/validation/virtualmachine_validator.go b/webhooks/virtualmachine/v1alpha2/validation/virtualmachine_validator.go
--- a/webhooks/virtualmachine/v1alpha2/validation/virtualmachine_validator.go (revision de75746a9505ef3161172d99b735d6593c54f0c5)
+++ b/webhooks/virtualmachine/v1alpha2/validation/virtualmachine_validator.go (date 1712596700934)
@@ -443,9 +443,9 @@

// The networkInterface CR name ("vmName-networkName-interfaceName" or "vmName-interfaceName") needs to be a DNS1123 Label
if networkName != "" {
- networkIfCRName = fmt.Sprintf("%s-%s-%s", vmName, networkName, interfaceSpec.Name)
+ networkIfCRName = strings.ToLower(strings.ReplaceAll(fmt.Sprintf("%s-%s-%s", vmName, networkName, interfaceSpec.Name), " ", "-"))
} else {
- networkIfCRName = fmt.Sprintf("%s-%s", vmName, interfaceSpec.Name)
+ networkIfCRName = strings.ToLower(strings.ReplaceAll(fmt.Sprintf("%s-%s", vmName, interfaceSpec.Name), " ", "-"))
}

for _, msg := range validation.NameIsDNSSubdomain(networkIfCRName, false) {
Loading