Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module github.com/openshift/cluster-api-actuator-pkg
go 1.26.0

replace (
// OCPSTRAT-3624: Use fork with Licenses field added to GCPDisk
github.com/openshift/api => github.com/redhat-chai-bot/api v0.0.0-20260813080306-5e4780e5baca
github.com/openshift/cluster-api-actuator-pkg/testutils => ./testutils

// CAPA imports cluster-api/test, which has a placeholder for cluster-api
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ github.com/onsi/ginkgo/v2 v2.32.0 h1:Hw7s2pVrQo/8Yz5N77qdnpHaoc+c6cC9WIV1Jce+J6E
github.com/onsi/ginkgo/v2 v2.32.0/go.mod h1:+aXOY+vzZ5mu2iI2HpTZUPmM//oQfsNFX6gU9kNcA44=
github.com/onsi/gomega v1.42.1 h1:iN1rCUX+44NZ1Dc97MPoeFYbFR0vh8zxoxMFwKdyZ6I=
github.com/onsi/gomega v1.42.1/go.mod h1:REff/hsDsodHoKlWsP2mAPhu1+5/6hVYNf9rIEBpeSg=
github.com/openshift/api v0.0.0-20260715165912-72066cc9718b h1:gN3SihCYEwoIksD+f24wHhwiEgvaV0RxNjgmkDvBBeg=
github.com/openshift/api v0.0.0-20260715165912-72066cc9718b/go.mod h1:k6qH5QOVa5GDln2VVm8Jz4NV3Z7R2SATHFLwGS6Wh3M=
github.com/openshift/client-go v0.0.0-20260715172546-dac61734e0ec h1:UDjX+mot5IVLpcChyBqLXG1oSB29s4UkqFmgNb0Xsqc=
github.com/openshift/client-go v0.0.0-20260715172546-dac61734e0ec/go.mod h1:iMHec0APKVjOH8GfL/RxddX8DuiuSvPlRe+s7KDqlyA=
github.com/openshift/cluster-autoscaler-operator v0.0.1-0.20260608074635-5c8643284941 h1:WoIEsMhADq1Qw/biZTdYR7AEsknsOxLxXOfARlbMI/E=
Expand Down Expand Up @@ -516,6 +514,8 @@ github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 h1:M8mH9eK4OUR4l
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567/go.mod h1:DWNGW8A4Y+GyBgPuaQJuWiy0XYftx4Xm/y5Jqk9I6VQ=
github.com/raeperd/recvcheck v0.2.0 h1:GnU+NsbiCqdC2XX5+vMZzP+jAJC5fht7rcVTAhX74UI=
github.com/raeperd/recvcheck v0.2.0/go.mod h1:n04eYkwIR0JbgD73wT8wL4JjPC3wm0nFtzBnWNocnYU=
github.com/redhat-chai-bot/api v0.0.0-20260813080306-5e4780e5baca h1:uNQHAZlMrFQQFl//0yRuxmV6Fnc5XA/SBORuLg3QXRQ=
github.com/redhat-chai-bot/api v0.0.0-20260813080306-5e4780e5baca/go.mod h1:k6qH5QOVa5GDln2VVm8Jz4NV3Z7R2SATHFLwGS6Wh3M=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
149 changes: 149 additions & 0 deletions pkg/infra/gcp_disk_licenses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package infra

import (
"context"
"encoding/json"
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1beta1"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/openshift/cluster-api-actuator-pkg/pkg/framework"
"github.com/openshift/cluster-api-actuator-pkg/pkg/framework/gatherer"
)

var _ = Describe("[sig-cluster-lifecycle] Machine API GCP Disk Licenses", framework.LabelMAPI, framework.LabelDisruptive, framework.LabelPeriodic, func() {
var ctx context.Context

var (
client runtimeclient.Client
machineSet *machinev1.MachineSet
)

var stateGatherer *gatherer.StateGatherer

BeforeEach(func() {
var err error

ctx = framework.GetContext()

stateGatherer, err = framework.NewGatherer()
Expect(err).ToNot(HaveOccurred(), "StateGatherer should be able to be created")

client, err = framework.LoadClient()
Expect(err).ToNot(HaveOccurred(), "Controller-runtime client should be able to be created")

// Only run on GCP clusters.
platform, err := framework.GetPlatform(ctx, client)
Expect(err).NotTo(HaveOccurred(), "Should be able to get Platform type")

if platform != configv1.GCPPlatformType {
Skip(fmt.Sprintf("Platform %s is not GCP, skipping GCP disk license test.", platform))
}

// Make sure to clean up the resources we created.
DeferCleanup(func() {
if machineSet != nil {
By("Deleting the MachineSet with disk licenses")
Expect(client.Delete(ctx, machineSet)).To(Succeed(), "MachineSet should be able to be deleted")
framework.WaitForMachineSetsDeleted(ctx, client, machineSet)
}
})
})

AfterEach(func() {
specReport := CurrentSpecReport()
if specReport.Failed() {
Expect(stateGatherer.WithSpecReport(specReport).GatherAll()).To(Succeed(), "StateGatherer should be able to gather resources")
}
})

// Machines required for test: 1
// Reason: We create a single Machine with disk licenses to verify the GCP API accepts
// the Licenses field on InitializeParams and the Machine reaches Running phase.
It("should create a Machine with licenses on the boot disk [GCP]", func() {
By("Getting the base MachineSet parameters from a worker MachineSet")

machineSetParams := framework.BuildMachineSetParams(ctx, client, 1)

By("Adding licenses to the boot disk in the GCP provider spec")
Expect(setLicensesOnGCPProviderSpec(machineSetParams, []string{
"projects/vm-options/global/licenses/enable-vmx",
})).To(Succeed(), "Should be able to set disk licenses on GCP ProviderSpec")

var err error

By("Creating a MachineSet with disk licenses")

machineSet, err = framework.CreateMachineSet(client, machineSetParams)
Expect(err).ToNot(HaveOccurred(), "MachineSet with disk licenses should be able to be created")

By("Waiting for the Machine to reach Running phase")
framework.WaitForMachineSet(ctx, client, machineSet.GetName())

By("Verifying the Machine reached Running phase with disk licenses")

machines, err := framework.GetMachinesFromMachineSet(ctx, client, machineSet)
Expect(err).ToNot(HaveOccurred(), "Should be able to get Machines from MachineSet")
Expect(machines).To(HaveLen(1), "Should have exactly 1 Machine")

running := framework.FilterRunningMachines(machines)
Expect(running).To(HaveLen(1), "The Machine with disk licenses should be in Running phase")

By("Verifying the providerSpec on the Machine includes the expected licenses")

var machineProviderSpec machinev1.GCPMachineProviderSpec

Expect(json.Unmarshal(running[0].Spec.ProviderSpec.Value.Raw, &machineProviderSpec)).To(Succeed(),
"Should be able to unmarshal Machine providerSpec")

bootDiskFound := false

for _, disk := range machineProviderSpec.Disks {
if disk.Boot {
bootDiskFound = true

Expect(disk.Licenses).To(ContainElement("projects/vm-options/global/licenses/enable-vmx"),
"Boot disk should have the enable-vmx license")
}
}

Expect(bootDiskFound).To(BeTrue(), "Should find a boot disk in the Machine's providerSpec")
})
})

// setLicensesOnGCPProviderSpec adds the specified licenses to the boot disk in the GCP provider spec.
func setLicensesOnGCPProviderSpec(params framework.MachineSetParams, licenses []string) error {
var spec machinev1.GCPMachineProviderSpec
if err := json.Unmarshal(params.ProviderSpec.Value.Raw, &spec); err != nil {
return fmt.Errorf("error unmarshalling GCP providerSpec: %w", err)
}

bootDiskFound := false

for i := range spec.Disks {
if spec.Disks[i].Boot {
spec.Disks[i].Licenses = licenses
bootDiskFound = true

break
}
}

if !bootDiskFound {
return fmt.Errorf("no boot disk found in GCP providerSpec")
}

var err error

params.ProviderSpec.Value.Raw, err = json.Marshal(spec)
if err != nil {
return fmt.Errorf("error marshalling GCP providerSpec: %w", err)
}

return nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions vendor/github.com/openshift/api/config/v1/types_infrastructure.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions vendor/github.com/openshift/api/config/v1/types_ingress.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading