Skip to content

Commit

Permalink
reconcile OCL API from v1alpha1 -> v1
Browse files Browse the repository at this point in the history
  • Loading branch information
djoshy committed Dec 13, 2024
1 parent 5f8f38a commit 6064540
Show file tree
Hide file tree
Showing 43 changed files with 599 additions and 711 deletions.
2 changes: 1 addition & 1 deletion cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
ctx.KubeInformerFactory.Core().V1().Nodes(),
ctx.KubeInformerFactory.Core().V1().Pods(),
ctx.TechPreviewInformerFactory.Machineconfiguration().V1alpha1().MachineOSConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().MachineOSConfigs(),
ctx.ConfigInformerFactory.Config().V1().Schedulers(),
ctx.ClientBuilder.KubeClientOrDie("node-update-controller"),
ctx.ClientBuilder.MachineConfigClientOrDie("node-update-controller"),
Expand Down
24 changes: 12 additions & 12 deletions pkg/apihelpers/machineosbuild.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package apihelpers

import (
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -17,13 +17,13 @@ func NewMachineOSBuildCondition(condType string, status metav1.ConditionStatus,
}
}

func GetMachineOSBuildCondition(status mcfgv1alpha1.MachineOSBuildStatus, condType mcfgv1alpha1.BuildProgress) *metav1.Condition {
func GetMachineOSBuildCondition(status mcfgv1.MachineOSBuildStatus, condType mcfgv1.BuildProgress) *metav1.Condition {
// in case of sync errors, return the last condition that matches, not the first
// this exists for redundancy and potential race conditions.
var LatestState *metav1.Condition
for i := range status.Conditions {
c := status.Conditions[i]
if mcfgv1alpha1.BuildProgress(c.Type) == condType {
if mcfgv1.BuildProgress(c.Type) == condType {
LatestState = &c
}
}
Expand All @@ -32,8 +32,8 @@ func GetMachineOSBuildCondition(status mcfgv1alpha1.MachineOSBuildStatus, condTy

// SetMachineOSBuildCondition updates the MachineOSBuild to include the provided condition. If the condition that
// we are about to add already exists and has the same status and reason then we are not going to update.
func SetMachineOSBuildCondition(status *mcfgv1alpha1.MachineOSBuildStatus, condition metav1.Condition) {
currentCond := GetMachineOSBuildCondition(*status, mcfgv1alpha1.BuildProgress(condition.Type))
func SetMachineOSBuildCondition(status *mcfgv1.MachineOSBuildStatus, condition metav1.Condition) {
currentCond := GetMachineOSBuildCondition(*status, mcfgv1.BuildProgress(condition.Type))
if currentCond != nil && currentCond.Status == condition.Status && currentCond.Reason == condition.Reason && currentCond.Message == condition.Message {
return
}
Expand All @@ -43,36 +43,36 @@ func SetMachineOSBuildCondition(status *mcfgv1alpha1.MachineOSBuildStatus, condi
}

// this may not be necessary
newConditions := filterOutMachineOSBuildCondition(status.Conditions, mcfgv1alpha1.BuildProgress(condition.Type))
newConditions := filterOutMachineOSBuildCondition(status.Conditions, mcfgv1.BuildProgress(condition.Type))
newConditions = append(newConditions, condition)
status.Conditions = newConditions
}

// RemoveMachineOSBuildCondition removes the MachineOSBuild condition with the provided type.
func RemoveMachineOSBuildCondition(status *mcfgv1alpha1.MachineOSBuildStatus, condType mcfgv1alpha1.BuildProgress) {
func RemoveMachineOSBuildCondition(status *mcfgv1.MachineOSBuildStatus, condType mcfgv1.BuildProgress) {
status.Conditions = filterOutMachineOSBuildCondition(status.Conditions, condType)
}

// filterOutMachineOSBuildCondition returns a new slice of MachineOSBuild conditions without conditions with the provided type.
func filterOutMachineOSBuildCondition(conditions []metav1.Condition, condType mcfgv1alpha1.BuildProgress) []metav1.Condition {
func filterOutMachineOSBuildCondition(conditions []metav1.Condition, condType mcfgv1.BuildProgress) []metav1.Condition {
var newConditions []metav1.Condition
for _, c := range conditions {
if mcfgv1alpha1.BuildProgress(c.Type) == condType {
if mcfgv1.BuildProgress(c.Type) == condType {
continue
}
newConditions = append(newConditions, c)
}
return newConditions
}

func IsMachineOSBuildConditionTrue(conditions []metav1.Condition, conditionType mcfgv1alpha1.BuildProgress) bool {
func IsMachineOSBuildConditionTrue(conditions []metav1.Condition, conditionType mcfgv1.BuildProgress) bool {
return IsMachineOSBuildConditionPresentAndEqual(conditions, conditionType, metav1.ConditionTrue)
}

// IsMachineOSBuildConditionPresentAndEqual returns true when conditionType is present and equal to status.
func IsMachineOSBuildConditionPresentAndEqual(conditions []metav1.Condition, conditionType mcfgv1alpha1.BuildProgress, status metav1.ConditionStatus) bool {
func IsMachineOSBuildConditionPresentAndEqual(conditions []metav1.Condition, conditionType mcfgv1.BuildProgress, status metav1.ConditionStatus) bool {
for _, condition := range conditions {
if mcfgv1alpha1.BuildProgress(condition.Type) == conditionType {
if mcfgv1.BuildProgress(condition.Type) == conditionType {
return condition.Status == status
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/apihelpers/machineosconfig.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package apihelpers

import (
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -17,7 +17,7 @@ func NewMachineOSConfigCondition(condType string, status metav1.ConditionStatus,
}
}

func GetMachineOSConfigCondition(status mcfgv1alpha1.MachineOSConfigStatus, condType string) *metav1.Condition {
func GetMachineOSConfigCondition(status mcfgv1.MachineOSConfigStatus, condType string) *metav1.Condition {
// in case of sync errors, return the last condition that matches, not the first
// this exists for redundancy and potential race conditions.
var LatestState *metav1.Condition
Expand All @@ -32,7 +32,7 @@ func GetMachineOSConfigCondition(status mcfgv1alpha1.MachineOSConfigStatus, cond

// SetMachineOSConfigCondition updates the MachineOSConfig to include the provided condition. If the condition that
// we are about to add already exists and has the same status and reason then we are not going to update.
func SetMachineOSConfigCondition(status *mcfgv1alpha1.MachineOSConfigStatus, condition metav1.Condition) {
func SetMachineOSConfigCondition(status *mcfgv1.MachineOSConfigStatus, condition metav1.Condition) {
currentCond := GetMachineOSConfigCondition(*status, condition.Type)
if currentCond != nil && currentCond.Status == condition.Status && currentCond.Reason == condition.Reason && currentCond.Message == condition.Message {
return
Expand All @@ -49,7 +49,7 @@ func SetMachineOSConfigCondition(status *mcfgv1alpha1.MachineOSConfigStatus, con
}

// RemoveMachineOSConfigCondition removes the MachineOSConfig condition with the provided type.
func RemoveMachineOSConfigCondition(status *mcfgv1alpha1.MachineOSConfigStatus, condType string) {
func RemoveMachineOSConfigCondition(status *mcfgv1.MachineOSConfigStatus, condType string) {
status.Conditions = filterOutMachineOSConfigCondition(status.Conditions, condType)
}

Expand Down
23 changes: 8 additions & 15 deletions pkg/controller/build/buildrequest/buildrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"text/template"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgclientset "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
"github.com/openshift/machine-config-operator/pkg/controller/build/constants"
"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
Expand Down Expand Up @@ -45,7 +44,7 @@ type buildRequestImpl struct {
}

// Constructs an imageBuildRequest from the Kube API server.
func NewBuildRequestFromAPI(ctx context.Context, kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig) (BuildRequest, error) {
func NewBuildRequestFromAPI(ctx context.Context, kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig) (BuildRequest, error) {
opts, err := newBuildRequestOptsFromAPI(ctx, kubeclient, mcfgclient, mosb, mosc)
if err != nil {
return nil, err
Expand All @@ -61,8 +60,8 @@ func newBuildRequest(opts BuildRequestOpts) BuildRequest {
}

// only support noArch for now
for _, file := range opts.MachineOSConfig.Spec.BuildInputs.Containerfile {
if file.ContainerfileArch == mcfgv1alpha1.NoArch {
for _, file := range opts.MachineOSConfig.Spec.Containerfile {
if file.ContainerfileArch == mcfgv1.NoArch {
br.userContainerfile = file.Content
break
}
Expand Down Expand Up @@ -226,20 +225,14 @@ func (br buildRequestImpl) renderContainerfile() (string, error) {
// default to a value from a different location, it makes more sense for us
// to implement that logic in Go as opposed to the Go template language.
items := struct {
MachineOSBuild *mcfgv1alpha1.MachineOSBuild
MachineOSConfig *mcfgv1alpha1.MachineOSConfig
MachineOSBuild *mcfgv1.MachineOSBuild
MachineOSConfig *mcfgv1.MachineOSConfig
UserContainerfile string
ReleaseVersion string
BaseOSImage string
ExtensionsImage string
ExtensionsPackages []string
}{
MachineOSBuild: br.opts.MachineOSBuild,
MachineOSConfig: br.opts.MachineOSConfig,
UserContainerfile: br.userContainerfile,
ReleaseVersion: br.opts.getReleaseVersion(),
BaseOSImage: br.opts.getBaseOSImagePullspec(),
ExtensionsImage: br.opts.getExtensionsImagePullspec(),
ExtensionsPackages: extPkgs,
}

Expand Down Expand Up @@ -315,7 +308,7 @@ func (br buildRequestImpl) toBuildahPod() *corev1.Pod {
},
{
Name: "TAG",
Value: br.opts.MachineOSBuild.Spec.RenderedImagePushspec,
Value: string(br.opts.MachineOSBuild.Spec.RenderedImagePushSpec),
},
{
Name: "BASE_IMAGE_PULL_CREDS",
Expand Down Expand Up @@ -525,7 +518,7 @@ func (br buildRequestImpl) toBuildahPod() *corev1.Pod {
// us to avoid parsing log files.
Name: "wait-for-done",
Command: append(command, waitScript),
Image: br.opts.getBaseOSImagePullspec(),
Image: br.opts.getBaseOSImagePullspec(), // QOCL: What do we replace this with?
Env: env,
ImagePullPolicy: corev1.PullAlways,
SecurityContext: securityContext,
Expand All @@ -543,7 +536,7 @@ func (br buildRequestImpl) getLabelsForObjectMeta() map[string]string {
return map[string]string{
constants.EphemeralBuildObjectLabelKey: "",
constants.OnClusterLayeringLabelKey: "",
constants.RenderedMachineConfigLabelKey: br.opts.MachineOSBuild.Spec.DesiredConfig.Name,
constants.RenderedMachineConfigLabelKey: br.opts.MachineOSBuild.Spec.MachineConfig.Name,
constants.TargetMachineConfigPoolLabelKey: br.opts.MachineOSConfig.Spec.MachineConfigPool.Name,
constants.MachineOSConfigNameLabelKey: br.opts.MachineOSConfig.Name,
constants.MachineOSBuildNameLabelKey: br.opts.MachineOSBuild.Name,
Expand Down
8 changes: 2 additions & 6 deletions pkg/controller/build/buildrequest/buildrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
"github.com/openshift/machine-config-operator/pkg/controller/build/constants"
"github.com/openshift/machine-config-operator/pkg/controller/build/fixtures"
"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
Expand Down Expand Up @@ -134,9 +133,6 @@ func TestBuildRequest(t *testing.T) {
name: "MachineOSConfig-provided options override OSImageURLConfig defaults",
optsFunc: func() BuildRequestOpts {
opts := getBuildRequestOpts()
opts.MachineOSConfig.Spec.BuildInputs.BaseOSImagePullspec = "base-os-image-from-machineosconfig"
opts.MachineOSConfig.Spec.BuildInputs.BaseOSExtensionsImagePullspec = "base-ext-image-from-machineosconfig"
opts.MachineOSConfig.Spec.BuildInputs.ReleaseVersion = "release-version-from-machineosconfig"
opts.MachineConfig.Spec.Extensions = []string{"usbguard"}
return opts
},
Expand Down Expand Up @@ -169,7 +165,7 @@ func TestBuildRequest(t *testing.T) {
if len(testCase.expectedContainerfileContents) == 0 {
testCase.expectedContainerfileContents = append(expectedContents(), []string{
machineConfigJSONFilename,
opts.MachineOSConfig.Spec.BuildInputs.Containerfile[0].Content,
opts.MachineOSConfig.Spec.Containerfile[0].Content,
}...)
}

Expand Down Expand Up @@ -321,7 +317,7 @@ RUN rpm-ostree install && \

layeredObjects := fixtures.NewObjectBuildersForTest("worker")
layeredObjects.MachineOSConfigBuilder.
WithContainerfile(mcfgv1alpha1.NoArch, containerfileContents)
WithContainerfile(mcfgv1.NoArch, containerfileContents)

layeredObjects.MachineOSBuildBuilder.
// Note: This is set statically so that the test suite is less brittle.
Expand Down
Loading

0 comments on commit 6064540

Please sign in to comment.