Skip to content

Commit

Permalink
Merge pull request #4756 from djoshy/reconcile-ocl-api
Browse files Browse the repository at this point in the history
MCO-1437: MCO-1476: MCO-1477: MCO-1284: Adapt MCO to OCL v1 API
deads2k authored Jan 27, 2025
2 parents eef257f + 1de506c commit cfdda14
Showing 127 changed files with 4,093 additions and 1,688 deletions.
2 changes: 1 addition & 1 deletion cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
@@ -250,7 +250,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"),
6 changes: 1 addition & 5 deletions devex/cmd/onclustertesting/ci.go
Original file line number Diff line number Diff line change
@@ -142,11 +142,7 @@ func setupMoscForCI(cs *framework.ClientSet, opts opts, poolName string) error {
}
}

if err := waitForBuildToComplete(ctx, cs, poolName); err != nil {
return err
}

return nil
return waitForBuildToComplete(ctx, cs, poolName)
}

func waitForPoolsToComplete(cs *framework.ClientSet, pools []string) error {
65 changes: 29 additions & 36 deletions devex/cmd/onclustertesting/machineosconfigs.go
Original file line number Diff line number Diff line change
@@ -6,8 +6,7 @@ import (
"time"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
clientmachineconfigv1alpha1 "github.com/openshift/client-go/machineconfiguration/clientset/versioned/typed/machineconfiguration/v1alpha1"
clientmachineconfigv1 "github.com/openshift/client-go/machineconfiguration/clientset/versioned/typed/machineconfiguration/v1"
"github.com/openshift/machine-config-operator/devex/internal/pkg/utils"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/test/framework"
@@ -25,47 +24,41 @@ type moscOpts struct {
finalImagePullspec string
}

func newMachineOSConfig(opts moscOpts) *mcfgv1alpha1.MachineOSConfig {
return &mcfgv1alpha1.MachineOSConfig{
func newMachineOSConfig(opts moscOpts) *mcfgv1.MachineOSConfig {
return &mcfgv1.MachineOSConfig{
ObjectMeta: metav1.ObjectMeta{
Name: opts.poolName,
Labels: map[string]string{
createdByOnClusterBuildsHelper: "",
},
},
Spec: mcfgv1alpha1.MachineOSConfigSpec{
MachineConfigPool: mcfgv1alpha1.MachineConfigPoolReference{
Spec: mcfgv1.MachineOSConfigSpec{
MachineConfigPool: mcfgv1.MachineConfigPoolReference{
Name: opts.poolName,
},
BuildInputs: mcfgv1alpha1.BuildInputs{
BaseImagePullSecret: mcfgv1alpha1.ImageSecretObjectReference{
Name: opts.pullSecretName,
},
RenderedImagePushSecret: mcfgv1alpha1.ImageSecretObjectReference{
Name: opts.pushSecretName,
},
RenderedImagePushspec: opts.finalImagePullspec,
ImageBuilder: &mcfgv1alpha1.MachineOSImageBuilder{
ImageBuilderType: mcfgv1alpha1.PodBuilder,
},
Containerfile: []mcfgv1alpha1.MachineOSContainerfile{
{
ContainerfileArch: mcfgv1alpha1.NoArch,
Content: opts.containerfileContents,
},
},
BaseImagePullSecret: &mcfgv1.ImageSecretObjectReference{
Name: opts.pullSecretName,
},
BuildOutputs: mcfgv1alpha1.BuildOutputs{
CurrentImagePullSecret: mcfgv1alpha1.ImageSecretObjectReference{
Name: opts.finalPullSecretName,
RenderedImagePushSecret: mcfgv1.ImageSecretObjectReference{
Name: opts.pushSecretName,
},
RenderedImagePushSpec: mcfgv1.ImageTagFormat(opts.finalImagePullspec),
ImageBuilder: mcfgv1.MachineOSImageBuilder{
ImageBuilderType: mcfgv1.MachineOSImageBuilderType("PodImageBuilder"),
},
Containerfile: []mcfgv1.MachineOSContainerfile{
{
ContainerfileArch: mcfgv1.NoArch,
Content: opts.containerfileContents,
},
},
},
}

}

func getMachineOSConfigForPool(cs *framework.ClientSet, pool *mcfgv1.MachineConfigPool) (*mcfgv1alpha1.MachineOSConfig, error) {
client := clientmachineconfigv1alpha1.NewForConfigOrDie(cs.GetRestConfig())
func getMachineOSConfigForPool(cs *framework.ClientSet, pool *mcfgv1.MachineConfigPool) (*mcfgv1.MachineOSConfig, error) {
client := clientmachineconfigv1.NewForConfigOrDie(cs.GetRestConfig())

moscList, err := client.MachineOSConfigs().List(context.TODO(), metav1.ListOptions{})
if err != nil {
@@ -89,8 +82,8 @@ func getMachineOSConfigForPool(cs *framework.ClientSet, pool *mcfgv1.MachineConf
return nil, fmt.Errorf("expected one MachineOSConfig for MachineConfigPool %s, found multiple: %v", pool.Name, names)
}

func filterMachineOSConfigsForPool(moscList *mcfgv1alpha1.MachineOSConfigList, pool *mcfgv1.MachineConfigPool) []*mcfgv1alpha1.MachineOSConfig {
found := []*mcfgv1alpha1.MachineOSConfig{}
func filterMachineOSConfigsForPool(moscList *mcfgv1.MachineOSConfigList, pool *mcfgv1.MachineConfigPool) []*mcfgv1.MachineOSConfig {
found := []*mcfgv1.MachineOSConfig{}

for _, mosc := range moscList.Items {
if mosc.Spec.MachineConfigPool.Name == pool.Name {
@@ -102,8 +95,8 @@ func filterMachineOSConfigsForPool(moscList *mcfgv1alpha1.MachineOSConfigList, p
return found
}

func createMachineOSConfig(cs *framework.ClientSet, mosc *mcfgv1alpha1.MachineOSConfig) error {
client := clientmachineconfigv1alpha1.NewForConfigOrDie(cs.GetRestConfig())
func createMachineOSConfig(cs *framework.ClientSet, mosc *mcfgv1.MachineOSConfig) error {
client := clientmachineconfigv1.NewForConfigOrDie(cs.GetRestConfig())

_, err := client.MachineOSConfigs().Create(context.TODO(), mosc, metav1.CreateOptions{})
if err != nil {
@@ -115,7 +108,7 @@ func createMachineOSConfig(cs *framework.ClientSet, mosc *mcfgv1alpha1.MachineOS
}

func deleteMachineOSConfigs(cs *framework.ClientSet) error {
client := clientmachineconfigv1alpha1.NewForConfigOrDie(cs.GetRestConfig())
client := clientmachineconfigv1.NewForConfigOrDie(cs.GetRestConfig())

moscList, err := client.MachineOSConfigs().List(context.TODO(), metav1.ListOptions{})
if err != nil {
@@ -135,7 +128,7 @@ func deleteMachineOSConfigs(cs *framework.ClientSet) error {
}

func deleteMachineOSBuilds(cs *framework.ClientSet) error {
client := clientmachineconfigv1alpha1.NewForConfigOrDie(cs.GetRestConfig())
client := clientmachineconfigv1.NewForConfigOrDie(cs.GetRestConfig())

mosbList, err := client.MachineOSBuilds().List(context.TODO(), metav1.ListOptions{})
if err != nil {
@@ -162,7 +155,7 @@ func waitForBuildToComplete(ctx context.Context, cs *framework.ClientSet, poolNa

start := time.Now()

return waitForMachineOSBuildToReachState(ctx, cs, poolName, func(mosb *mcfgv1alpha1.MachineOSBuild, err error) (bool, error) {
return waitForMachineOSBuildToReachState(ctx, cs, poolName, func(mosb *mcfgv1.MachineOSBuild, err error) (bool, error) {
// There is a lag between when the MachineOSConfig is created and the
// MachineOSBuild object gets created and is available.
if err != nil && !utils.IsNotFoundErr(err) {
@@ -206,7 +199,7 @@ func waitForBuildToComplete(ctx context.Context, cs *framework.ClientSet, poolNa
})
}

func waitForMachineOSBuildToReachState(ctx context.Context, cs *framework.ClientSet, poolName string, condFunc func(*mcfgv1alpha1.MachineOSBuild, error) (bool, error)) error {
func waitForMachineOSBuildToReachState(ctx context.Context, cs *framework.ClientSet, poolName string, condFunc func(*mcfgv1.MachineOSBuild, error) (bool, error)) error {
return wait.PollUntilContextCancel(ctx, time.Second, true, func(funcCtx context.Context) (bool, error) {
mosb, err := utils.GetMachineOSBuildForPoolName(funcCtx, cs, poolName)
return condFunc(mosb, err)
4 changes: 2 additions & 2 deletions devex/cmd/onclustertesting/opts.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"fmt"
"os"

mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
"k8s.io/klog/v2"
)

@@ -80,7 +80,7 @@ func (o *opts) shouldCloneGlobalPullSecret() bool {
return isNoneSet(o.pullSecretName, o.pullSecretPath)
}

func (o *opts) toMachineOSConfig() (*mcfgv1alpha1.MachineOSConfig, error) {
func (o *opts) toMachineOSConfig() (*mcfgv1.MachineOSConfig, error) {
pushSecretName, err := o.getPushSecretName()
if err != nil {
return nil, err
6 changes: 1 addition & 5 deletions devex/cmd/onclustertesting/teardown.go
Original file line number Diff line number Diff line change
@@ -85,9 +85,5 @@ func mobTeardown(cs *framework.ClientSet, targetPool string) error {
return err
}

if err := deleteMachineOSConfigs(cs); err != nil {
return err
}

return nil
return deleteMachineOSConfigs(cs)
}
5 changes: 2 additions & 3 deletions devex/internal/pkg/rollout/machineconfigpool.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import (
"time"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
errhelpers "github.com/openshift/machine-config-operator/devex/internal/pkg/errors"
"github.com/openshift/machine-config-operator/devex/internal/pkg/utils"
"github.com/openshift/machine-config-operator/pkg/apihelpers"
@@ -426,10 +425,10 @@ func isNodeImageDone(node *corev1.Node) bool {
return isNodeDone(node) && current == desired
}

func isNodeDoneAtMosc(mosc *mcfgv1alpha1.MachineOSConfig, node *corev1.Node) bool {
func isNodeDoneAtMosc(mosc *mcfgv1.MachineOSConfig, node *corev1.Node) bool {
current := node.Annotations[daemonconsts.CurrentImageAnnotationKey]
desired := node.Annotations[daemonconsts.DesiredImageAnnotationKey]
return isNodeDone(node) && isNodeImageDone(node) && desired == mosc.Status.CurrentImagePullspec && desired != "" && current != ""
return isNodeDone(node) && isNodeImageDone(node) && desired == string(mosc.Status.CurrentImagePullSpec) && desired != "" && current != ""
}

func isNodeDone(node *corev1.Node) bool {
4 changes: 2 additions & 2 deletions devex/internal/pkg/rollout/nodeimage.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package rollout

import (
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1alpha1"
daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants"
corev1 "k8s.io/api/core/v1"
)

func isNodeImageEqualToMachineOSConfig(node corev1.Node, mosc *mcfgv1alpha1.MachineOSConfig) bool {
func isNodeImageEqualToMachineOSConfig(node corev1.Node, mosc *mcfgv1.MachineOSConfig) bool {
desired := node.Annotations[daemonconsts.DesiredImageAnnotationKey]
current := node.Annotations[daemonconsts.CurrentImageAnnotationKey]
mcdState := node.Annotations[daemonconsts.MachineConfigDaemonStateAnnotationKey]
17 changes: 8 additions & 9 deletions devex/internal/pkg/utils/apiutils.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (
"fmt"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
"github.com/openshift/machine-config-operator/test/framework"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -21,7 +20,7 @@ type notFoundErr struct {
func newNotFoundErr(resource, poolName string) error {
return &notFoundErr{
poolName: poolName,
err: apierrs.NewNotFound(mcfgv1alpha1.GroupVersion.WithResource(resource).GroupResource(), ""),
err: apierrs.NewNotFound(mcfgv1.GroupVersion.WithResource(resource).GroupResource(), ""),
}
}

@@ -47,7 +46,7 @@ func IsMachineConfigPoolLayered(ctx context.Context, cs *framework.ClientSet, mc
return mosc != nil && !IsNotFoundErr(err), nil
}

func GetMachineOSBuildForPoolName(ctx context.Context, cs *framework.ClientSet, poolName string) (*mcfgv1alpha1.MachineOSBuild, error) {
func GetMachineOSBuildForPoolName(ctx context.Context, cs *framework.ClientSet, poolName string) (*mcfgv1.MachineOSBuild, error) {
mcp, err := cs.MachineConfigPools().Get(ctx, poolName, metav1.GetOptions{})
if err != nil {
return nil, err
@@ -56,7 +55,7 @@ func GetMachineOSBuildForPoolName(ctx context.Context, cs *framework.ClientSet,
return GetMachineOSBuildForPool(ctx, cs, mcp)
}

func GetMachineOSConfigForPoolName(ctx context.Context, cs *framework.ClientSet, poolName string) (*mcfgv1alpha1.MachineOSConfig, error) {
func GetMachineOSConfigForPoolName(ctx context.Context, cs *framework.ClientSet, poolName string) (*mcfgv1.MachineOSConfig, error) {
mcp, err := cs.MachineConfigPools().Get(ctx, poolName, metav1.GetOptions{})
if err != nil {
return nil, err
@@ -65,24 +64,24 @@ func GetMachineOSConfigForPoolName(ctx context.Context, cs *framework.ClientSet,
return GetMachineOSConfigForPool(ctx, cs, mcp)
}

func GetMachineOSBuildForPool(ctx context.Context, cs *framework.ClientSet, mcp *mcfgv1.MachineConfigPool) (*mcfgv1alpha1.MachineOSBuild, error) {
mosbList, err := cs.MachineOSBuilds().List(ctx, metav1.ListOptions{})
func GetMachineOSBuildForPool(ctx context.Context, cs *framework.ClientSet, mcp *mcfgv1.MachineConfigPool) (*mcfgv1.MachineOSBuild, error) {
mosbList, err := cs.MachineconfigurationV1Interface.MachineOSBuilds().List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}

for _, mosb := range mosbList.Items {
mosb := mosb
if mosb.Spec.DesiredConfig.Name == mcp.Spec.Configuration.Name {
if mosb.Spec.MachineConfig.Name == mcp.Spec.Configuration.Name {
return &mosb, nil
}
}

return nil, newNotFoundErr("machineosbuilds", mcp.Name)
}

func GetMachineOSConfigForPool(ctx context.Context, cs *framework.ClientSet, mcp *mcfgv1.MachineConfigPool) (*mcfgv1alpha1.MachineOSConfig, error) {
moscList, err := cs.MachineOSConfigs().List(ctx, metav1.ListOptions{})
func GetMachineOSConfigForPool(ctx context.Context, cs *framework.ClientSet, mcp *mcfgv1.MachineConfigPool) (*mcfgv1.MachineOSConfig, error) {
moscList, err := cs.MachineconfigurationV1Interface.MachineOSConfigs().List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ require (
github.com/imdario/mergo v0.3.16
github.com/opencontainers/go-digest v1.0.0
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec
github.com/openshift/client-go v0.0.0-20241203091221-452dfb8fa071
github.com/openshift/client-go v0.0.0-20250106104058-89709a455e2a
github.com/openshift/library-go v0.0.0-20241022210936-abb8c75b88dc
github.com/openshift/runtime-utils v0.0.0-20230921210328-7bdb5b9c177b
github.com/prometheus/client_golang v1.20.4
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -596,8 +596,8 @@ github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bl
github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec h1:VEDRGJmiYeN0V0xW1aI9wfzEMgaMZOVasy3FzEz27Lo=
github.com/openshift/api v0.0.0-20250102185430-d6d8306a24ec/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo=
github.com/openshift/client-go v0.0.0-20241203091221-452dfb8fa071 h1:l0++HnGVKBcs8kXFL/1yeozxioxPGNpp0PYe3Y+0sq4=
github.com/openshift/client-go v0.0.0-20241203091221-452dfb8fa071/go.mod h1:gL0laCCiIaNTNw1ZsMQZXBVu2NeQFpNWm9bLtYO9+ZU=
github.com/openshift/client-go v0.0.0-20250106104058-89709a455e2a h1:8lwO4lGTwHuVXsIeFoW3t7AEBROW5quMj5YjH9jF+98=
github.com/openshift/client-go v0.0.0-20250106104058-89709a455e2a/go.mod h1:34qRf2MsrJKXKAL8qxIkxZ3O5G+YhOB7foCR04H26JE=
github.com/openshift/kube-openapi v0.0.0-20230816122517-ffc8f001abb0 h1:GPlAy197Jkr+D0T2FNWanamraTdzS/r9ZkT29lxvHaA=
github.com/openshift/kube-openapi v0.0.0-20230816122517-ffc8f001abb0/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
github.com/openshift/library-go v0.0.0-20241022210936-abb8c75b88dc h1:fwtWTW+QcTyzGVAYxMPz9amtAURWvSs8p+a37nG/43c=
9 changes: 0 additions & 9 deletions manifests/machineconfigdaemon/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -42,10 +42,6 @@ spec:
- mountPath: /rootfs
name: rootfs
mountPropagation: HostToContainer
{{- range .MachineOSConfigs }}
- mountPath: /run/secrets/os-image-pull-secrets/{{ .Spec.MachineConfigPool.Name }}
name: {{ .Spec.BuildOutputs.CurrentImagePullSecret.Name }}
{{- end }}
livenessProbe:
initialDelaySeconds: 120
periodSeconds: 30
@@ -116,11 +112,6 @@ spec:
- configMap:
name: kube-rbac-proxy
name: mcd-auth-proxy-config
{{- range .MachineOSConfigs }}
- secret:
secretName: {{ .Spec.BuildOutputs.CurrentImagePullSecret.Name }}
name: {{ .Spec.BuildOutputs.CurrentImagePullSecret.Name }}
{{- end }}
tolerations:
# MCD needs to run everywhere. Tolerate all taints.
- operator: Exists
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"
)
@@ -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
}
}
@@ -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
}
@@ -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
}
}
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"
)
@@ -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
@@ -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
@@ -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)
}

Original file line number Diff line number Diff line change
@@ -40,9 +40,8 @@ RUN ostree container commit
COPY ./openshift-config-user-ca-bundle.crt /etc/pki/ca-trust/source/anchors/openshift-config-user-ca-bundle.crt
RUN update-ca-trust

LABEL machineconfig={{.MachineOSBuild.Spec.DesiredConfig.Name}}
LABEL machineconfig={{.MachineOSBuild.Spec.MachineConfig.Name}}
LABEL machineconfigpool={{.MachineOSConfig.Spec.MachineConfigPool.Name}}
LABEL releaseversion={{.ReleaseVersion}}
LABEL baseOSContainerImage={{.BaseOSImage}}

{{if .UserContainerfile}}
28 changes: 10 additions & 18 deletions pkg/controller/build/buildrequest/buildrequest.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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
@@ -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
}
@@ -226,20 +225,18 @@ 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(),
BaseOSImage: br.opts.OSImageURLConfig.BaseOSContainerImage,
ExtensionsImage: br.opts.OSImageURLConfig.BaseOSExtensionsContainerImage,
ExtensionsPackages: extPkgs,
}

@@ -315,7 +312,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",
@@ -489,11 +486,6 @@ func (br buildRequestImpl) toBuildahPod() *corev1.Pod {
volumes = append(volumes, opts.volumeForSecret(constants.EtcPkiRpmGpgSecretName))
}

// TODO: We need pull creds with permissions to pull the base image. By
// default, none of the MCO pull secrets can directly pull it. We can use the
// pull-secret creds from openshift-config to do that, though we'll need to
// mirror those creds into the MCO namespace. The operator portion of the MCO
// has some logic to detect whenever that secret changes.
return &corev1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
@@ -525,7 +517,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.OSImageURLConfig.BaseOSContainerImage,
Env: env,
ImagePullPolicy: corev1.PullAlways,
SecurityContext: securityContext,
@@ -543,7 +535,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,
24 changes: 2 additions & 22 deletions pkg/controller/build/buildrequest/buildrequest_test.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -130,25 +129,6 @@ func TestBuildRequest(t *testing.T) {
return opts
},
},
{
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
},
expectedContainerfileContents: []string{
"FROM base-os-image-from-machineosconfig AS extract",
"FROM base-os-image-from-machineosconfig AS configs",
"RUN --mount=type=bind,from=base-ext-image-from-machineosconfig",
"extensions=\"usbguard\"",
"LABEL releaseversion=release-version-from-machineosconfig",
},
unexpectedContainerfileContents: expectedContents(),
},
}

for _, testCase := range testCases {
@@ -169,7 +149,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,
}...)
}

@@ -321,7 +301,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.
86 changes: 32 additions & 54 deletions pkg/controller/build/buildrequest/buildrequestopts.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import (
"github.com/distribution/reference"
configv1 "github.com/openshift/api/config/v1"
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"
@@ -22,15 +21,17 @@ import (

// Holds all of the options used to produce a BuildRequest.
type BuildRequestOpts struct { //nolint:revive // This name is fine.
MachineOSConfig *mcfgv1alpha1.MachineOSConfig
MachineOSBuild *mcfgv1alpha1.MachineOSBuild
MachineOSConfig *mcfgv1.MachineOSConfig
MachineOSBuild *mcfgv1.MachineOSBuild
MachineConfig *mcfgv1.MachineConfig
Images *ctrlcommon.Images
OSImageURLConfig *ctrlcommon.OSImageURLConfig

BaseImagePullSecret *corev1.Secret
FinalImagePushSecret *corev1.Secret

// Has user defined base image pull secret
hasUserDefinedBaseImagePullSecret bool
// Has /etc/pki/entitlement
HasEtcPkiEntitlementKeys bool
// Has /etc/yum.repos.d configs
@@ -44,36 +45,6 @@ type BuildRequestOpts struct { //nolint:revive // This name is fine.
AdditionalTrustBundle []byte
}

// Gets the extensions image pullspec from the MachineOSConfig if available.
// Otherwise, it defaults to the value from the osimageurl ConfigMap.
func (b BuildRequestOpts) getExtensionsImagePullspec() string {
if b.MachineOSConfig.Spec.BuildInputs.BaseOSExtensionsImagePullspec != "" {
return b.MachineOSConfig.Spec.BuildInputs.BaseOSExtensionsImagePullspec
}

return b.OSImageURLConfig.BaseOSExtensionsContainerImage
}

// Gets the base OS image pullspec from the MachineOSConfig if available.
// Otherwise, it defaults to the value from the osimageurl ConfigMap.
func (b BuildRequestOpts) getBaseOSImagePullspec() string {
if b.MachineOSConfig.Spec.BuildInputs.BaseOSImagePullspec != "" {
return b.MachineOSConfig.Spec.BuildInputs.BaseOSImagePullspec
}

return b.OSImageURLConfig.BaseOSContainerImage
}

// Gets the release version value from the MachineOSConfig if available.
// Otherwise, it defaults to the value from the osimageurl ConfigMap.
func (b BuildRequestOpts) getReleaseVersion() string {
if b.MachineOSConfig.Spec.BuildInputs.ReleaseVersion != "" {
return b.MachineOSConfig.Spec.BuildInputs.ReleaseVersion
}

return b.OSImageURLConfig.ReleaseVersion
}

// Gets the packages for the extensions from the MachineConfig, if available.
func (b BuildRequestOpts) getExtensionsPackages() ([]string, error) {
if len(b.MachineConfig.Spec.Extensions) == 0 {
@@ -84,7 +55,7 @@ func (b BuildRequestOpts) getExtensionsPackages() ([]string, error) {
}

// Gets all of the image build request opts from the Kube API server.
func newBuildRequestOptsFromAPI(ctx context.Context, kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig) (*BuildRequestOpts, error) {
func newBuildRequestOptsFromAPI(ctx context.Context, kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig) (*BuildRequestOpts, error) {
og := optsGetter{
kubeclient: kubeclient,
mcfgclient: mcfgclient,
@@ -134,45 +105,41 @@ type optsGetter struct {
}

// TODO: Deduplicate this.
func (o *optsGetter) validateMachineOSConfig(mosc *mcfgv1alpha1.MachineOSConfig) error {
func (o *optsGetter) validateMachineOSConfig(mosc *mcfgv1.MachineOSConfig) error {
if mosc == nil {
return fmt.Errorf("expected MachineOSConfig not to be nil")
}

if mosc.Spec.BuildInputs.BaseImagePullSecret.Name == "" {
return fmt.Errorf("baseImagePullSecret empty for MachineOSConfig %s", mosc.Name)
}

if mosc.Spec.BuildInputs.RenderedImagePushSecret.Name == "" {
if mosc.Spec.RenderedImagePushSecret.Name == "" {
return fmt.Errorf("renderedImagePushSecret empty for MachineOSConfig %s", mosc.Name)
}

if mosc.Spec.BuildInputs.RenderedImagePushspec == "" {
if mosc.Spec.RenderedImagePushSpec == "" {
return fmt.Errorf("renderedImagePushspec empty for MachineOSConfig %s", mosc.Name)
}

if _, err := reference.ParseNamed(mosc.Spec.BuildInputs.RenderedImagePushspec); err != nil {
return fmt.Errorf("invalid renderedImagePushspec for MachineOSConfig %s: %w", mosc.Name, err)
if _, err := reference.ParseNamed(string(mosc.Spec.RenderedImagePushSpec)); err != nil {
return fmt.Errorf("invalid renderedImagePushSpec for MachineOSConfig %s: %w", mosc.Name, err)
}

return nil
}

// Validates that the required fields on a MachineOSBuild are set before beginning the build.
func (o *optsGetter) validateMachineOSBuild(mosb *mcfgv1alpha1.MachineOSBuild) error {
func (o *optsGetter) validateMachineOSBuild(mosb *mcfgv1.MachineOSBuild) error {
if mosb == nil {
return fmt.Errorf("expected MachineOSBuild not to be nil")
}

if mosb.Spec.DesiredConfig.Name == "" {
return fmt.Errorf("desiredConfig.name empty for MachineOSBuild %s", mosb.Name)
if mosb.Spec.MachineConfig.Name == "" {
return fmt.Errorf("machineConfig.name empty for MachineOSBuild %s", mosb.Name)
}

return nil
}

// Gets the BuildRequestOpts after making API queries to get all of the necessary info required.
func (o *optsGetter) getOpts(ctx context.Context, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig) (*BuildRequestOpts, error) {
func (o *optsGetter) getOpts(ctx context.Context, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig) (*BuildRequestOpts, error) {
if err := o.validateMachineOSConfig(mosc); err != nil {
return nil, fmt.Errorf("could not validate MachineOSConfig: %w", err)
}
@@ -196,19 +163,30 @@ func (o *optsGetter) getOpts(ctx context.Context, mosb *mcfgv1alpha1.MachineOSBu
return nil, fmt.Errorf("could not get osImageURL config: %w", err)
}

baseImagePullSecret, err := o.getValidatedSecret(ctx, mosc.Spec.BuildInputs.BaseImagePullSecret.Name)
var baseImagePullSecretName string
// Check if a base image pull secret was provided
opts.hasUserDefinedBaseImagePullSecret = mosc.Spec.BaseImagePullSecret != nil
if opts.hasUserDefinedBaseImagePullSecret {
baseImagePullSecretName = mosc.Spec.BaseImagePullSecret.Name
} else {
// If not provided, fall back to the global pull secret copy in the MCO namespace
klog.Infof("BaseImagePullSecret not defined for MachineOSConfig %s, falling back to global pull secret", mosc.Name)
baseImagePullSecretName = ctrlcommon.GlobalPullSecretCopyName
}

baseImagePullSecret, err := o.getValidatedSecret(ctx, baseImagePullSecretName)
if err != nil {
return nil, fmt.Errorf("could not get base image pull secret %s: %w", mosc.Spec.BuildInputs.BaseImagePullSecret.Name, err)
return nil, fmt.Errorf("could not get base image pull secret %s: %w", mosc.Spec.BaseImagePullSecret.Name, err)
}

finalImagePushSecret, err := o.getValidatedSecret(ctx, mosc.Spec.BuildInputs.RenderedImagePushSecret.Name)
finalImagePushSecret, err := o.getValidatedSecret(ctx, mosc.Spec.RenderedImagePushSecret.Name)
if err != nil {
return nil, fmt.Errorf("could not get final image push secret %s: %w", mosc.Spec.BuildInputs.RenderedImagePushSecret.Name, err)
return nil, fmt.Errorf("could not get final image push secret %s: %w", mosc.Spec.RenderedImagePushSecret.Name, err)
}

mc, err := o.mcfgclient.MachineconfigurationV1().MachineConfigs().Get(ctx, mosb.Spec.DesiredConfig.Name, metav1.GetOptions{})
mc, err := o.mcfgclient.MachineconfigurationV1().MachineConfigs().Get(ctx, mosb.Spec.MachineConfig.Name, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("could not retrieve machineconfig %s: %w", mosb.Spec.DesiredConfig.Name, err)
return nil, fmt.Errorf("could not retrieve machineconfig %s: %w", mosb.Spec.MachineConfig.Name, err)
}

cc, err := o.mcfgclient.MachineconfigurationV1().ControllerConfigs().Get(ctx, ctrlcommon.ControllerConfigName, metav1.GetOptions{})
@@ -245,7 +223,7 @@ func (o *optsGetter) getValidatedSecret(ctx context.Context, name string) (*core

// Determines whether the build makes use of entitlements based upon the
// presence (or lack thereof) of specific configmaps and secrets.
func (o *optsGetter) resolveEntitlements(ctx context.Context, mosc *mcfgv1alpha1.MachineOSConfig) (*BuildRequestOpts, error) {
func (o *optsGetter) resolveEntitlements(ctx context.Context, mosc *mcfgv1.MachineOSConfig) (*BuildRequestOpts, error) {
opts := &BuildRequestOpts{}

etcPkiEntitlements, err := o.getOptionalSecret(ctx, constants.EtcPkiEntitlementSecretName+"-"+mosc.Spec.MachineConfigPool.Name)
27 changes: 24 additions & 3 deletions pkg/controller/build/buildrequest/buildrequestopts_test.go
Original file line number Diff line number Diff line change
@@ -11,20 +11,24 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
)

func TestBuildRequestOpts(t *testing.T) {
testCases := []struct {
name string
addlObjects []runtime.Object
addlAsserts func(*testing.T, BuildRequestOpts)
name string
addlObjects []runtime.Object
addlObjectSetup func(*testing.T, *fixtures.ObjectsForTest)
addlAsserts func(*testing.T, BuildRequestOpts)
}{
{
name: "no entitlement data",
addlAsserts: func(t *testing.T, brOpts BuildRequestOpts) {
assert.False(t, brOpts.HasEtcPkiRpmGpgKeys)
assert.False(t, brOpts.HasEtcYumReposDConfigs)
assert.False(t, brOpts.HasEtcPkiEntitlementKeys)
assert.False(t, brOpts.hasUserDefinedBaseImagePullSecret)
},
},
{
@@ -41,6 +45,7 @@ func TestBuildRequestOpts(t *testing.T) {
assert.False(t, brOpts.HasEtcPkiRpmGpgKeys)
assert.False(t, brOpts.HasEtcYumReposDConfigs)
assert.True(t, brOpts.HasEtcPkiEntitlementKeys)
assert.False(t, brOpts.hasUserDefinedBaseImagePullSecret)
},
},
{
@@ -57,6 +62,7 @@ func TestBuildRequestOpts(t *testing.T) {
assert.False(t, brOpts.HasEtcPkiRpmGpgKeys)
assert.True(t, brOpts.HasEtcYumReposDConfigs)
assert.False(t, brOpts.HasEtcPkiEntitlementKeys)
assert.False(t, brOpts.hasUserDefinedBaseImagePullSecret)
},
},
{
@@ -73,6 +79,7 @@ func TestBuildRequestOpts(t *testing.T) {
assert.True(t, brOpts.HasEtcPkiRpmGpgKeys)
assert.False(t, brOpts.HasEtcYumReposDConfigs)
assert.False(t, brOpts.HasEtcPkiEntitlementKeys)
assert.False(t, brOpts.hasUserDefinedBaseImagePullSecret)
},
},
{
@@ -101,6 +108,16 @@ func TestBuildRequestOpts(t *testing.T) {
assert.True(t, brOpts.HasEtcPkiRpmGpgKeys)
assert.True(t, brOpts.HasEtcYumReposDConfigs)
assert.True(t, brOpts.HasEtcPkiEntitlementKeys)
assert.False(t, brOpts.hasUserDefinedBaseImagePullSecret)
},
},
{
name: "with user defined base image pull secret",
addlObjectSetup: func(t *testing.T, lobj *fixtures.ObjectsForTest) {
lobj.MachineOSConfig.Spec.BaseImagePullSecret = &mcfgv1.ImageSecretObjectReference{Name: fixtures.BaseImagePullSecretName}
},
addlAsserts: func(t *testing.T, brOpts BuildRequestOpts) {
assert.True(t, brOpts.hasUserDefinedBaseImagePullSecret)
},
},
}
@@ -115,6 +132,10 @@ func TestBuildRequestOpts(t *testing.T) {

kubeclient, mcfgclient, lobj, _ := fixtures.GetClientsForTestWithAdditionalObjects(t, testCase.addlObjects, []runtime.Object{})

if testCase.addlObjectSetup != nil {
testCase.addlObjectSetup(t, lobj)
}

brOpts, err := newBuildRequestOptsFromAPI(ctx, kubeclient, mcfgclient, lobj.MachineOSBuild, lobj.MachineOSConfig)
assert.NoError(t, err)

62 changes: 16 additions & 46 deletions pkg/controller/build/buildrequest/machineosbuild.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import (
"github.com/distribution/reference"
"github.com/ghodss/yaml"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -32,7 +31,7 @@ var (
// Holds the objects that are used to construct a MachineOSBuild with a hashed
// name.
type MachineOSBuildOpts struct {
MachineOSConfig *mcfgv1alpha1.MachineOSConfig
MachineOSConfig *mcfgv1.MachineOSConfig
MachineConfigPool *mcfgv1.MachineConfigPool
OSImageURLConfig *ctrlcommon.OSImageURLConfig
}
@@ -58,25 +57,8 @@ func (m *MachineOSBuildOpts) validateForHash() error {
return nil
}

// Makes a deep-copy of the MachineOSConfig and clears the data from it that
// can come from either the MachineOSConfig or from the OSImageURLConfig
// object. We do this to stabilize the hashing of the name so that whether the
// value comes from the MachineOSConfig or the OSImageURLConfig, the hash will
// be same, provided that the value is the same.
func (m *MachineOSBuildOpts) getMachineOSConfigForHashing() *mcfgv1alpha1.MachineOSConfig {
moscCopy := m.MachineOSConfig.DeepCopy()
moscCopy.Spec.BuildInputs.BaseOSImagePullspec = ""
moscCopy.Spec.BuildInputs.BaseOSExtensionsImagePullspec = ""
moscCopy.Spec.BuildInputs.ReleaseVersion = ""
return moscCopy
}

// Creates a list of objects that are consumed by the SHA256 hash.
func (m *MachineOSBuildOpts) objectsForHash() []interface{} {
o := BuildRequestOpts{
MachineOSConfig: m.MachineOSConfig,
OSImageURLConfig: m.OSImageURLConfig,
}

// The objects considered for hashing described inline:
out := []interface{}{
@@ -85,20 +67,10 @@ func (m *MachineOSBuildOpts) objectsForHash() []interface{} {
// the individual MachineConfigs that went into that rendered
// MachineConfig.
m.MachineConfigPool.Spec.Configuration,
// The deep-copy of the MachineOSConfig with the multisource data fields
// removed for stability.
m.getMachineOSConfigForHashing().Spec,
// The MachineOSConfig Spec field.
m.MachineOSConfig.Spec,
// The complete OSImageURLConfig object.
m.OSImageURLConfig,
// The OS image extensions pullspec from either the MachineOSConfig or the
// OSImageURLConfig.
o.getExtensionsImagePullspec(),
// The base OS image pullspec from either the MachineOSConfig or the
// OSImageURLConfig.
o.getBaseOSImagePullspec(),
// The release version from either the MachineOSConfig or the
// OSImageURLConfig.
o.getReleaseVersion(),
}

return out
@@ -147,7 +119,7 @@ func (m *MachineOSBuildOpts) getHashedName() (string, error) {

// Constructs the MachineOSBuildOpts by retrieving the OSImageURLConfig from
// the API server.
func NewMachineOSBuildOpts(ctx context.Context, kubeclient clientset.Interface, mosc *mcfgv1alpha1.MachineOSConfig, mcp *mcfgv1.MachineConfigPool) (MachineOSBuildOpts, error) {
func NewMachineOSBuildOpts(ctx context.Context, kubeclient clientset.Interface, mosc *mcfgv1.MachineOSConfig, mcp *mcfgv1.MachineConfigPool) (MachineOSBuildOpts, error) {
// TODO: Consider an implementation that uses listers instead of API clients
// just to cut down on API server traffic.
osImageURLs, err := ctrlcommon.GetOSImageURLConfig(ctx, kubeclient)
@@ -164,7 +136,7 @@ func NewMachineOSBuildOpts(ctx context.Context, kubeclient clientset.Interface,

// Constructs a new MachineOSBuild object or panics trying. Useful for testing
// scenarios.
func NewMachineOSBuildOrDie(opts MachineOSBuildOpts) *mcfgv1alpha1.MachineOSBuild {
func NewMachineOSBuildOrDie(opts MachineOSBuildOpts) *mcfgv1.MachineOSBuild {
mosb, err := NewMachineOSBuild(opts)

if err != nil {
@@ -176,7 +148,7 @@ func NewMachineOSBuildOrDie(opts MachineOSBuildOpts) *mcfgv1alpha1.MachineOSBuil

// Retrieves the MachineOSBuildOpts from the API and constructs a new
// MachineOSBuild object or panics trying. Useful for testing scenarios.
func NewMachineOSBuildFromAPIOrDie(ctx context.Context, kubeclient clientset.Interface, mosc *mcfgv1alpha1.MachineOSConfig, mcp *mcfgv1.MachineConfigPool) *mcfgv1alpha1.MachineOSBuild {
func NewMachineOSBuildFromAPIOrDie(ctx context.Context, kubeclient clientset.Interface, mosc *mcfgv1.MachineOSConfig, mcp *mcfgv1.MachineConfigPool) *mcfgv1.MachineOSBuild {
mosb, err := NewMachineOSBuildFromAPI(ctx, kubeclient, mosc, mcp)

if err != nil {
@@ -188,7 +160,7 @@ func NewMachineOSBuildFromAPIOrDie(ctx context.Context, kubeclient clientset.Int

// Retrieves the MachineOSBuildOpts from the API and constructs a new
// MachineOSBuild object.
func NewMachineOSBuildFromAPI(ctx context.Context, kubeclient clientset.Interface, mosc *mcfgv1alpha1.MachineOSConfig, mcp *mcfgv1.MachineConfigPool) (*mcfgv1alpha1.MachineOSBuild, error) {
func NewMachineOSBuildFromAPI(ctx context.Context, kubeclient clientset.Interface, mosc *mcfgv1.MachineOSConfig, mcp *mcfgv1.MachineConfigPool) (*mcfgv1.MachineOSBuild, error) {
opts, err := NewMachineOSBuildOpts(ctx, kubeclient, mosc, mcp)

if err != nil {
@@ -200,15 +172,15 @@ func NewMachineOSBuildFromAPI(ctx context.Context, kubeclient clientset.Interfac

// Constructs a new MachineOSBuild object with all of the labels, the tagged
// image pushpsec, and a hashed name.
func NewMachineOSBuild(opts MachineOSBuildOpts) (*mcfgv1alpha1.MachineOSBuild, error) {
func NewMachineOSBuild(opts MachineOSBuildOpts) (*mcfgv1.MachineOSBuild, error) {
mosbName, err := opts.getHashedNameWithConfig()
if err != nil {
return nil, fmt.Errorf("could not get hashed name for MachineOSBuild: %w", err)
}

now := metav1.Now()

namedRef, err := reference.ParseNamed(opts.MachineOSConfig.Spec.BuildInputs.RenderedImagePushspec)
namedRef, err := reference.ParseNamed(string(opts.MachineOSConfig.Spec.RenderedImagePushSpec))
if err != nil {
return nil, err
}
@@ -218,27 +190,25 @@ func NewMachineOSBuild(opts MachineOSBuildOpts) (*mcfgv1alpha1.MachineOSBuild, e
return nil, err
}

mosb := &mcfgv1alpha1.MachineOSBuild{
mosb := &mcfgv1.MachineOSBuild{
TypeMeta: metav1.TypeMeta{
Kind: "MachineOSBuild",
APIVersion: "machineconfiguration.openshift.io/v1alpha1",
APIVersion: "machineconfiguration.openshift.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: mosbName,
Labels: utils.GetMachineOSBuildLabels(opts.MachineOSConfig, opts.MachineConfigPool),
},
Spec: mcfgv1alpha1.MachineOSBuildSpec{
RenderedImagePushspec: taggedRef.String(),
Version: 1,
ConfigGeneration: 1,
DesiredConfig: mcfgv1alpha1.RenderedMachineConfigReference{
Spec: mcfgv1.MachineOSBuildSpec{
RenderedImagePushSpec: mcfgv1.ImageTagFormat(taggedRef.String()),
MachineConfig: mcfgv1.MachineConfigReference{
Name: opts.MachineConfigPool.Spec.Configuration.Name,
},
MachineOSConfig: mcfgv1alpha1.MachineOSConfigReference{
MachineOSConfig: mcfgv1.MachineOSConfigReference{
Name: opts.MachineOSConfig.Name,
},
},
Status: mcfgv1alpha1.MachineOSBuildStatus{
Status: mcfgv1.MachineOSBuildStatus{
BuildStart: &now,
},
}
114 changes: 5 additions & 109 deletions pkg/controller/build/buildrequest/machineosbuild_test.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import (
"k8s.io/apimachinery/pkg/labels"

mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
"github.com/openshift/machine-config-operator/pkg/controller/build/fixtures"
"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
testhelpers "github.com/openshift/machine-config-operator/test/helpers"
@@ -20,7 +19,7 @@ func TestMachineOSBuild(t *testing.T) {

poolName := "worker"

getMachineOSConfig := func() *mcfgv1alpha1.MachineOSConfig {
getMachineOSConfig := func() *mcfgv1.MachineOSConfig {
return testhelpers.NewMachineOSConfigBuilder(poolName).WithMachineConfigPool(poolName).MachineOSConfig()
}

@@ -29,7 +28,7 @@ func TestMachineOSBuild(t *testing.T) {
}

// Some of the test cases expect the hash name to be the same. This is that hash value.
expectedCommonHashName := "worker-d6e1cf069939c5cda06064edf431689c"
expectedCommonHashName := "worker-e945ec808b468c07f6a2cf1936c23a13"

testCases := []struct {
name string
@@ -81,109 +80,6 @@ func TestMachineOSBuild(t *testing.T) {
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
{
name: "Base OS image pullspec provided by MachineOSConfig equal to OSImageURLConfig",
expectedName: expectedCommonHashName,
opts: MachineOSBuildOpts{
MachineConfigPool: getMachineConfigPool(),
MachineOSConfig: testhelpers.NewMachineOSConfigBuilder(poolName).
WithMachineConfigPool(poolName).
WithBaseOSImagePullspec(fixtures.BaseOSContainerImage).
MachineOSConfig(),
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
{
name: "Extensions image provided by provided by MachineOSConfig equal to OSImageURLConfig",
expectedName: expectedCommonHashName,
opts: MachineOSBuildOpts{
MachineConfigPool: getMachineConfigPool(),
MachineOSConfig: testhelpers.NewMachineOSConfigBuilder(poolName).
WithMachineConfigPool(poolName).
WithExtensionsImagePullspec(fixtures.BaseOSExtensionsContainerImage).
MachineOSConfig(),
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
{
name: "Release version provided by MachineOSConfig equal to OSImageURLConfig",
expectedName: expectedCommonHashName,
opts: MachineOSBuildOpts{
MachineConfigPool: getMachineConfigPool(),
MachineOSConfig: testhelpers.NewMachineOSConfigBuilder(poolName).
WithMachineConfigPool(poolName).
WithReleaseVersion(fixtures.ReleaseVersion).
MachineOSConfig(),
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
{
name: "All values provided by MachineOSConfig equal to OSImageURLConfig values",
expectedName: expectedCommonHashName,
opts: MachineOSBuildOpts{
MachineConfigPool: getMachineConfigPool(),
MachineOSConfig: testhelpers.NewMachineOSConfigBuilder(poolName).
WithMachineConfigPool(poolName).
WithBaseOSImagePullspec(fixtures.BaseOSContainerImage).
WithExtensionsImagePullspec(fixtures.BaseOSExtensionsContainerImage).
WithReleaseVersion(fixtures.ReleaseVersion).
MachineOSConfig(),
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
// These cases ensure that should the value on the MachineOSConfig differ
// from what is in the OSImageURLConfig (provided it is not empty!), the
// hash will change.
{
name: "Custom base OS image pullspec provided by MachineOSConfig",
expectedName: "worker-45358521eec36e094dfba3d48f67bf2e",
opts: MachineOSBuildOpts{
MachineConfigPool: getMachineConfigPool(),
MachineOSConfig: testhelpers.NewMachineOSConfigBuilder(poolName).
WithMachineConfigPool(poolName).
WithBaseOSImagePullspec("registry.hostname.com/org/repo:custom-os-image").
MachineOSConfig(),
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
{
name: "Custom extensions image provided by provided by MachineOSConfig",
expectedName: "worker-e091d5caee71326bd29f9e30997eda11",
opts: MachineOSBuildOpts{
MachineConfigPool: getMachineConfigPool(),
MachineOSConfig: testhelpers.NewMachineOSConfigBuilder(poolName).
WithMachineConfigPool(poolName).
WithExtensionsImagePullspec("registry.hostname.com/org/repo:custom-extensions-image").
MachineOSConfig(),
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
{
name: "Custom release version provided by MachineOSConfig",
expectedName: "worker-33f019b45084bba3d6e6dfaf0a2335b0",
opts: MachineOSBuildOpts{
MachineConfigPool: getMachineConfigPool(),
MachineOSConfig: testhelpers.NewMachineOSConfigBuilder(poolName).
WithMachineConfigPool(poolName).
WithReleaseVersion("custom-release-version").
MachineOSConfig(),
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
{
name: "All custom values provided by MachineOSConfig",
expectedName: "worker-b9833dc380a7c5892856202669afae9c",
opts: MachineOSBuildOpts{
MachineConfigPool: getMachineConfigPool(),
MachineOSConfig: testhelpers.NewMachineOSConfigBuilder(poolName).
WithMachineConfigPool(poolName).
WithBaseOSImagePullspec("registry.hostname.com/org/repo:custom-os-image").
WithExtensionsImagePullspec("registry.hostname.com/org/repo:custom-extensions-image").
WithReleaseVersion("custom-release-version").
MachineOSConfig(),
OSImageURLConfig: fixtures.OSImageURLConfig(),
},
},
// These cases ensure that pausing the MachineConfigPool does not affect the hash.
{
name: "Unpaused MachineConfigPool",
@@ -211,7 +107,7 @@ func TestMachineOSBuild(t *testing.T) {
t.Parallel()

if testCase.opts.MachineOSConfig != nil {
testCase.opts.MachineOSConfig.Spec.BuildInputs.RenderedImagePushspec = "registry.hostname.com/org/repo:latest"
testCase.opts.MachineOSConfig.Spec.RenderedImagePushSpec = "registry.hostname.com/org/repo:latest"
}

mosb, err := NewMachineOSBuild(testCase.opts)
@@ -226,8 +122,8 @@ func TestMachineOSBuild(t *testing.T) {
assert.Equal(t, testCase.expectedName, mosb.Name)

expectedPullspec := fmt.Sprintf("registry.hostname.com/org/repo:%s", testCase.expectedName)
assert.Equal(t, expectedPullspec, mosb.Spec.RenderedImagePushspec)
assert.Equal(t, testCase.opts.MachineConfigPool.Spec.Configuration.Name, mosb.Spec.DesiredConfig.Name)
assert.Equal(t, expectedPullspec, string(mosb.Spec.RenderedImagePushSpec))
assert.Equal(t, testCase.opts.MachineConfigPool.Spec.Configuration.Name, mosb.Spec.MachineConfig.Name)
assert.NotNil(t, mosb.Status.BuildStart)

assert.True(t, utils.MachineOSBuildSelector(testCase.opts.MachineOSConfig, testCase.opts.MachineConfigPool).Matches(labels.Set(mosb.Labels)))
14 changes: 6 additions & 8 deletions pkg/controller/build/clients.go
Original file line number Diff line number Diff line change
@@ -13,9 +13,7 @@ import (
mcfgclientset "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
mcfginformers "github.com/openshift/client-go/machineconfiguration/informers/externalversions"
mcfginformersv1 "github.com/openshift/client-go/machineconfiguration/informers/externalversions/machineconfiguration/v1"
mcfginformersv1alpha1 "github.com/openshift/client-go/machineconfiguration/informers/externalversions/machineconfiguration/v1alpha1"
mcfglistersv1 "github.com/openshift/client-go/machineconfiguration/listers/machineconfiguration/v1"
mcfglistersv1alpha1 "github.com/openshift/client-go/machineconfiguration/listers/machineconfiguration/v1alpha1"

"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
@@ -26,8 +24,8 @@ type informers struct {
controllerConfigInformer mcfginformersv1.ControllerConfigInformer
machineConfigPoolInformer mcfginformersv1.MachineConfigPoolInformer
jobInformer batchinformersv1.JobInformer
machineOSBuildInformer mcfginformersv1alpha1.MachineOSBuildInformer
machineOSConfigInformer mcfginformersv1alpha1.MachineOSConfigInformer
machineOSBuildInformer mcfginformersv1.MachineOSBuildInformer
machineOSConfigInformer mcfginformersv1.MachineOSConfigInformer
toStart []interface{ Start(<-chan struct{}) }
hasSynced []cache.InformerSynced
}
@@ -52,8 +50,8 @@ func (i *informers) listers() *listers {

// Holds all of the required listers so that they can be passed around and reused.
type listers struct {
machineOSBuildLister mcfglistersv1alpha1.MachineOSBuildLister
machineOSConfigLister mcfglistersv1alpha1.MachineOSConfigLister
machineOSBuildLister mcfglistersv1.MachineOSBuildLister
machineOSConfigLister mcfglistersv1.MachineOSConfigLister
machineConfigPoolLister mcfglistersv1.MachineConfigPoolLister
jobLister batchlisterv1.JobLister
controllerConfigLister mcfglistersv1.ControllerConfigLister
@@ -85,8 +83,8 @@ func newInformers(mcfgclient mcfgclientset.Interface, kubeclient clientset.Inter

controllerConfigInformer := mcoInformerFactory.Machineconfiguration().V1().ControllerConfigs()
machineConfigPoolInformer := mcoInformerFactory.Machineconfiguration().V1().MachineConfigPools()
machineOSBuildInformer := mcoInformerFactory.Machineconfiguration().V1alpha1().MachineOSBuilds()
machineOSConfigInformer := mcoInformerFactory.Machineconfiguration().V1alpha1().MachineOSConfigs()
machineOSBuildInformer := mcoInformerFactory.Machineconfiguration().V1().MachineOSBuilds()
machineOSConfigInformer := mcoInformerFactory.Machineconfiguration().V1().MachineOSConfigs()
jobInformer := coreInformerFactory.Batch().V1().Jobs()

return &informers{
14 changes: 7 additions & 7 deletions pkg/controller/build/fixtures/helpers.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"fmt"
"testing"

mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/stretchr/testify/require"
batchv1 "k8s.io/api/batch/v1"
@@ -27,7 +27,7 @@ type JobStatus struct {
}

// Sets the provided job status on a given job under test. If successful, it will also insert the digestfile ConfigMap.
func SetJobStatus(ctx context.Context, t *testing.T, kubeclient clientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, jobStatus JobStatus) {
func SetJobStatus(ctx context.Context, t *testing.T, kubeclient clientset.Interface, mosb *mcfgv1.MachineOSBuild, jobStatus JobStatus) {
require.NoError(t, setJobStatusFields(ctx, kubeclient, mosb, jobStatus))

if jobStatus.Succeeded == 1 {
@@ -37,7 +37,7 @@ func SetJobStatus(ctx context.Context, t *testing.T, kubeclient clientset.Interf
}
}

func SetJobDeletionTimestamp(ctx context.Context, t *testing.T, kubeclient clientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, timestamp *metav1.Time) {
func SetJobDeletionTimestamp(ctx context.Context, t *testing.T, kubeclient clientset.Interface, mosb *mcfgv1.MachineOSBuild, timestamp *metav1.Time) {
jobName := fmt.Sprintf("build-%s", mosb.Name)

j, err := kubeclient.BatchV1().Jobs(ctrlcommon.MCONamespace).Get(ctx, jobName, metav1.GetOptions{})
@@ -49,7 +49,7 @@ func SetJobDeletionTimestamp(ctx context.Context, t *testing.T, kubeclient clien
require.NoError(t, err)
}

func setJobStatusFields(ctx context.Context, kubeclient clientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, jobStatus JobStatus) error {
func setJobStatusFields(ctx context.Context, kubeclient clientset.Interface, mosb *mcfgv1.MachineOSBuild, jobStatus JobStatus) error {
jobName := fmt.Sprintf("build-%s", mosb.Name)

j, err := kubeclient.BatchV1().Jobs(ctrlcommon.MCONamespace).Get(ctx, jobName, metav1.GetOptions{})
@@ -67,11 +67,11 @@ func setJobStatusFields(ctx context.Context, kubeclient clientset.Interface, mos
return err
}

func createDigestfileConfigMap(ctx context.Context, kubeclient clientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild) error {
func createDigestfileConfigMap(ctx context.Context, kubeclient clientset.Interface, mosb *mcfgv1.MachineOSBuild) error {
return createDigestfileConfigMapWithDigest(ctx, kubeclient, mosb, getDigest(mosb.Name))
}

func createDigestfileConfigMapWithDigest(ctx context.Context, kubeclient clientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, digest string) error {
func createDigestfileConfigMapWithDigest(ctx context.Context, kubeclient clientset.Interface, mosb *mcfgv1.MachineOSBuild, digest string) error {
digestName := fmt.Sprintf("digest-%s", mosb.Name)

cm := &corev1.ConfigMap{
@@ -92,7 +92,7 @@ func createDigestfileConfigMapWithDigest(ctx context.Context, kubeclient clients
return nil
}

func deleteDigestfileConfigMap(ctx context.Context, kubeclient clientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild) error {
func deleteDigestfileConfigMap(ctx context.Context, kubeclient clientset.Interface, mosb *mcfgv1.MachineOSBuild) error {
digestName := fmt.Sprintf("digest-%s", mosb.Name)
err := kubeclient.CoreV1().ConfigMaps(ctrlcommon.MCONamespace).Delete(ctx, digestName, metav1.DeleteOptions{})
if err != nil && !k8serrors.IsNotFound(err) {
22 changes: 9 additions & 13 deletions pkg/controller/build/fixtures/objects.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (

ign3types "github.com/coreos/ignition/v2/config/v3_4/types"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
"github.com/openshift/machine-config-operator/pkg/controller/build/constants"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
testhelpers "github.com/openshift/machine-config-operator/test/helpers"
@@ -15,17 +14,16 @@ import (
)

const (
baseImagePullSecretName string = "base-image-pull-secret"
finalImagePushSecretName string = "final-image-push-secret"
currentImagePullSecretName string = "current-image-pull-secret"
BaseImagePullSecretName string = "base-image-pull-secret"
finalImagePushSecretName string = "final-image-push-secret"
)

// Provides consistently instantiated objects for use in a given test.
type ObjectsForTest struct {
MachineConfigPool *mcfgv1.MachineConfigPool
MachineConfigs []*mcfgv1.MachineConfig
MachineOSConfig *mcfgv1alpha1.MachineOSConfig
MachineOSBuild *mcfgv1alpha1.MachineOSBuild
MachineOSConfig *mcfgv1.MachineOSConfig
MachineOSBuild *mcfgv1.MachineOSBuild
}

// Provides the builders to create consistently instantiated objects for use in
@@ -88,11 +86,9 @@ func NewObjectBuildersForTest(poolName string) ObjectBuildersForTest {

moscBuilder := testhelpers.NewMachineOSConfigBuilder(moscName).
WithMachineConfigPool(poolName).
WithBaseImagePullSecret(baseImagePullSecretName).
WithRenderedImagePushSecret(finalImagePushSecretName).
WithCurrentImagePullSecret(currentImagePullSecretName).
WithRenderedImagePushspec("registry.hostname.com/org/repo:latest").
WithContainerfile(mcfgv1alpha1.NoArch, "FROM configs AS final\n\nRUN echo 'hi' > /etc/hi")
WithRenderedImagePushSpec("registry.hostname.com/org/repo:latest").
WithContainerfile(mcfgv1.NoArch, "FROM configs AS final\n\nRUN echo 'hi' > /etc/hi")

mcpBuilder := testhelpers.NewMachineConfigPoolBuilder(poolName).
WithChildConfigs(getChildConfigs(poolName, 5)).
@@ -134,7 +130,7 @@ func defaultKubeObjects() []runtime.Object {
},
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: baseImagePullSecretName,
Name: BaseImagePullSecretName,
Namespace: ctrlcommon.MCONamespace,
},
Data: map[string][]byte{
@@ -144,7 +140,7 @@ func defaultKubeObjects() []runtime.Object {
},
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: currentImagePullSecretName,
Name: ctrlcommon.GlobalPullSecretCopyName,
Namespace: ctrlcommon.MCONamespace,
},
Data: map[string][]byte{
@@ -246,7 +242,7 @@ func OSImageURLConfig() *ctrlcommon.OSImageURLConfig {
}
}

func GetExpectedFinalImagePullspecForMachineOSBuild(mosb *mcfgv1alpha1.MachineOSBuild) string {
func GetExpectedFinalImagePullspecForMachineOSBuild(mosb *mcfgv1.MachineOSBuild) string {
digest := getDigest(mosb.Name)
return "registry.hostname.com/org/repo@" + digest
}
42 changes: 21 additions & 21 deletions pkg/controller/build/helpers.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import (

"github.com/containers/image/v5/docker/reference"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
"github.com/openshift/client-go/machineconfiguration/clientset/versioned"
mcfglistersv1 "github.com/openshift/client-go/machineconfiguration/listers/machineconfiguration/v1"
"github.com/openshift/machine-config-operator/pkg/controller/build/constants"
@@ -24,7 +23,7 @@ import (
// ValidateOnClusterBuildConfig validates the existence of the MachineOSConfig and the required build inputs.
func ValidateOnClusterBuildConfig(kubeclient clientset.Interface, mcfgclient versioned.Interface, layeredMCPs []*mcfgv1.MachineConfigPool) error {
// Validate the presence of the MachineOSConfig
machineOSConfigs, err := mcfgclient.MachineconfigurationV1alpha1().MachineOSConfigs().List(context.TODO(), metav1.ListOptions{})
machineOSConfigs, err := mcfgclient.MachineconfigurationV1().MachineOSConfigs().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return err
}
@@ -34,7 +33,7 @@ func ValidateOnClusterBuildConfig(kubeclient clientset.Interface, mcfgclient ver
}

moscForPoolExists := false
var moscForPool *mcfgv1alpha1.MachineOSConfig
var moscForPool *mcfgv1.MachineOSConfig
for _, pool := range layeredMCPs {
moscForPoolExists = false
for _, mosc := range machineOSConfigs.Items {
@@ -61,7 +60,7 @@ func ValidateOnClusterBuildConfig(kubeclient clientset.Interface, mcfgclient ver
return nil
}

func validateMachineOSConfig(mcpGetter func(string) (*mcfgv1.MachineConfigPool, error), secretGetter func(string) (*corev1.Secret, error), mosc *mcfgv1alpha1.MachineOSConfig) error {
func validateMachineOSConfig(mcpGetter func(string) (*mcfgv1.MachineConfigPool, error), secretGetter func(string) (*corev1.Secret, error), mosc *mcfgv1.MachineOSConfig) error {
_, err := mcpGetter(mosc.Spec.MachineConfigPool.Name)
if err != nil && k8serrors.IsNotFound(err) {
return fmt.Errorf("no MachineConfigPool named %s exists for MachineOSConfig %s", mosc.Spec.MachineConfigPool.Name, mosc.Name)
@@ -72,9 +71,11 @@ func validateMachineOSConfig(mcpGetter func(string) (*mcfgv1.MachineConfigPool,
}

secretFields := map[string]string{
mosc.Spec.BuildInputs.BaseImagePullSecret.Name: "baseImagePullSecret",
mosc.Spec.BuildInputs.RenderedImagePushSecret.Name: "renderedImagePushSecret",
mosc.Spec.BuildOutputs.CurrentImagePullSecret.Name: "currentImagePullSecret",
mosc.Spec.RenderedImagePushSecret.Name: "renderedImagePushSecret",
}
// Add base image pull secret if it has been defined in the MOSC
if mosc.Spec.BaseImagePullSecret != nil {
secretFields[mosc.Spec.BaseImagePullSecret.Name] = "baseImagePullSecret"
}

for secretName, fieldName := range secretFields {
@@ -83,14 +84,14 @@ func validateMachineOSConfig(mcpGetter func(string) (*mcfgv1.MachineConfigPool,
}
}

if _, err := reference.ParseNamed(mosc.Spec.BuildInputs.RenderedImagePushspec); err != nil {
return fmt.Errorf("could not validate renderdImagePushspec %s for MachineOSConfig %s: %w", mosc.Spec.BuildInputs.RenderedImagePushspec, mosc.Name, err)
if _, err := reference.ParseNamed(string(mosc.Spec.RenderedImagePushSpec)); err != nil {
return fmt.Errorf("could not validate renderdImagePushspec %s for MachineOSConfig %s: %w", string(mosc.Spec.RenderedImagePushSpec), mosc.Name, err)
}

return nil
}

func ValidateMachineOSConfigFromListers(mcpLister mcfglistersv1.MachineConfigPoolLister, secretLister corelisterv1.SecretLister, mosc *mcfgv1alpha1.MachineOSConfig) error {
func ValidateMachineOSConfigFromListers(mcpLister mcfglistersv1.MachineConfigPoolLister, secretLister corelisterv1.SecretLister, mosc *mcfgv1.MachineOSConfig) error {
mcpGetter := func(name string) (*mcfgv1.MachineConfigPool, error) {
return mcpLister.Get(name)
}
@@ -102,7 +103,7 @@ func ValidateMachineOSConfigFromListers(mcpLister mcfglistersv1.MachineConfigPoo
return validateMachineOSConfig(mcpGetter, secretGetter, mosc)
}

func validateSecret(secretGetter func(string) (*corev1.Secret, error), mosc *mcfgv1alpha1.MachineOSConfig, secretName string) error {
func validateSecret(secretGetter func(string) (*corev1.Secret, error), mosc *mcfgv1.MachineOSConfig, secretName string) error {
if secretName == "" {
return fmt.Errorf("no secret name provided")
}
@@ -123,7 +124,7 @@ func validateSecret(secretGetter func(string) (*corev1.Secret, error), mosc *mcf
// Determines if a MachineOSBuild status update is needed. These are needed
// primarily when we transition from the initial status -> transient state ->
// terminal state.
func isMachineOSBuildStatusUpdateNeeded(oldStatus, curStatus mcfgv1alpha1.MachineOSBuildStatus) (bool, string) {
func isMachineOSBuildStatusUpdateNeeded(oldStatus, curStatus mcfgv1.MachineOSBuildStatus) (bool, string) {
oldState := ctrlcommon.NewMachineOSBuildStateFromStatus(oldStatus)
curState := ctrlcommon.NewMachineOSBuildStateFromStatus(curStatus)

@@ -182,7 +183,7 @@ func isMachineOSBuildStatusUpdateNeeded(oldStatus, curStatus mcfgv1alpha1.Machin
}

// Converts a list of MachineOSConfigs into a list of their names.
func getMachineOSConfigNames(moscList []*mcfgv1alpha1.MachineOSConfig) []string {
func getMachineOSConfigNames(moscList []*mcfgv1.MachineOSConfig) []string {
out := []string{}

for _, mosc := range moscList {
@@ -193,7 +194,7 @@ func getMachineOSConfigNames(moscList []*mcfgv1alpha1.MachineOSConfig) []string
}

// Converts a list of MachineOSBuilds into a list of their names.
func getMachineOSBuildNames(mosbList []*mcfgv1alpha1.MachineOSBuild) []string {
func getMachineOSBuildNames(mosbList []*mcfgv1.MachineOSBuild) []string {
out := []string{}

for _, mosc := range mosbList {
@@ -205,7 +206,7 @@ func getMachineOSBuildNames(mosbList []*mcfgv1alpha1.MachineOSBuild) []string {

// Determines if a MachineOSBuild is current for a given MachineOSConfig solely
// by looking at the current build annotation on the MachineOSConfig.
func isMachineOSBuildCurrentForMachineOSConfig(mosc *mcfgv1alpha1.MachineOSConfig, mosb *mcfgv1alpha1.MachineOSBuild) bool {
func isMachineOSBuildCurrentForMachineOSConfig(mosc *mcfgv1.MachineOSConfig, mosb *mcfgv1.MachineOSBuild) bool {
// If we don't have the current build annotation, then we cannot even make this determination.
if !hasCurrentBuildAnnotation(mosc) {
return false
@@ -224,23 +225,22 @@ func isMachineOSBuildCurrentForMachineOSConfig(mosc *mcfgv1alpha1.MachineOSConfi
// considering the current build annotation and the image pullspec. If the
// MachineOSBuild has not (yet) set its final image pushspec, this will return
// false.
func isMachineOSBuildCurrentForMachineOSConfigWithPullspec(mosc *mcfgv1alpha1.MachineOSConfig, mosb *mcfgv1alpha1.MachineOSBuild) bool {
func isMachineOSBuildCurrentForMachineOSConfigWithPullspec(mosc *mcfgv1.MachineOSConfig, mosb *mcfgv1.MachineOSBuild) bool {
// If the MachineOSConfig has the same final image pullspec as
// the MachineOSBuild and the MachineOSBuild's pushspec is populated, we know
// they're the same.
return isMachineOSBuildCurrentForMachineOSConfig(mosc, mosb) &&
mosc.Status.CurrentImagePullspec == mosb.Status.FinalImagePushspec &&
mosb.Status.FinalImagePushspec != ""
mosc.Status.CurrentImagePullSpec == mosb.Status.DigestedImagePushSpec
}

// Determines if a given MachineOSConfig has the current build annotation.
func hasCurrentBuildAnnotation(mosc *mcfgv1alpha1.MachineOSConfig) bool {
func hasCurrentBuildAnnotation(mosc *mcfgv1.MachineOSConfig) bool {
return metav1.HasAnnotation(mosc.ObjectMeta, constants.CurrentMachineOSBuildAnnotationKey) && mosc.Annotations[constants.CurrentMachineOSBuildAnnotationKey] != ""
}

// Determines if a given MachineOSConfig has the current build annotation and
// it matches the name of the given MachineOSBuild.
func isCurrentBuildAnnotationEqual(mosc *mcfgv1alpha1.MachineOSConfig, mosb *mcfgv1alpha1.MachineOSBuild) bool {
func isCurrentBuildAnnotationEqual(mosc *mcfgv1.MachineOSConfig, mosb *mcfgv1.MachineOSBuild) bool {
if !hasCurrentBuildAnnotation(mosc) {
return false
}
@@ -249,7 +249,7 @@ func isCurrentBuildAnnotationEqual(mosc *mcfgv1alpha1.MachineOSConfig, mosb *mcf
}

// Determines if a given MachineOSConfig has the rebuild annotation.
func hasRebuildAnnotation(mosc *mcfgv1alpha1.MachineOSConfig) bool {
func hasRebuildAnnotation(mosc *mcfgv1.MachineOSConfig) bool {
return metav1.HasAnnotation(mosc.ObjectMeta, constants.RebuildMachineOSConfigAnnotationKey)
}

16 changes: 7 additions & 9 deletions pkg/controller/build/helpers_test.go
Original file line number Diff line number Diff line change
@@ -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/fixtures"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/stretchr/testify/assert"
@@ -16,7 +15,7 @@ import (
func TestValidateOnClusterBuildConfig(t *testing.T) {
t.Parallel()

newMosc := func() *mcfgv1alpha1.MachineOSConfig {
newMosc := func() *mcfgv1.MachineOSConfig {
lobj := fixtures.NewObjectsForTest("worker")
return lobj.MachineOSConfig
}
@@ -25,21 +24,21 @@ func TestValidateOnClusterBuildConfig(t *testing.T) {
name string
errExpected bool
secretsToDelete []string
mosc func() *mcfgv1alpha1.MachineOSConfig
mosc func() *mcfgv1.MachineOSConfig
}{
{
name: "happy path",
mosc: newMosc,
},
{
name: "missing secret",
secretsToDelete: []string{"current-image-pull-secret"},
secretsToDelete: []string{"final-image-push-secret"},
mosc: newMosc,
errExpected: true,
},
{
name: "missing MachineOSConfig",
mosc: func() *mcfgv1alpha1.MachineOSConfig {
mosc: func() *mcfgv1.MachineOSConfig {
mosc := newMosc()
mosc.Name = "other-machineosconfig"
mosc.Spec.MachineConfigPool.Name = "other-machineconfigpool"
@@ -49,9 +48,9 @@ func TestValidateOnClusterBuildConfig(t *testing.T) {
},
{
name: "malformed image pullspec",
mosc: func() *mcfgv1alpha1.MachineOSConfig {
mosc: func() *mcfgv1.MachineOSConfig {
mosc := newMosc()
mosc.Spec.BuildInputs.RenderedImagePushspec = "malformed-image-pullspec"
mosc.Spec.RenderedImagePushSpec = "malformed-image-pullspec"
return mosc
},
errExpected: true,
@@ -64,8 +63,7 @@ func TestValidateOnClusterBuildConfig(t *testing.T) {
t.Parallel()

kubeclient, mcfgclient, lobj, _ := fixtures.GetClientsForTest(t)

_, err := mcfgclient.MachineconfigurationV1alpha1().MachineOSConfigs().Create(context.TODO(), testCase.mosc(), metav1.CreateOptions{})
_, err := mcfgclient.MachineconfigurationV1().MachineOSConfigs().Create(context.TODO(), testCase.mosc(), metav1.CreateOptions{})
require.NoError(t, err)

for _, secret := range testCase.secretsToDelete {
95 changes: 48 additions & 47 deletions pkg/controller/build/imagebuilder/base.go
Original file line number Diff line number Diff line change
@@ -5,11 +5,12 @@ import (
"errors"
"fmt"

mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgclientset "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
"github.com/openshift/machine-config-operator/pkg/controller/build/buildrequest"
"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
clientset "k8s.io/client-go/kubernetes"
@@ -19,14 +20,14 @@ import (
type baseImageBuilder struct {
kubeclient clientset.Interface
mcfgclient mcfgclientset.Interface
mosb *mcfgv1alpha1.MachineOSBuild
mosc *mcfgv1alpha1.MachineOSConfig
mosb *mcfgv1.MachineOSBuild
mosc *mcfgv1.MachineOSConfig
builder buildrequest.Builder
buildrequest buildrequest.BuildRequest
}

// Constructs a baseImageBuilder, deep-copying objects as needed.
func newBaseImageBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig, builder buildrequest.Builder) *baseImageBuilder {
func newBaseImageBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig, builder buildrequest.Builder) *baseImageBuilder {
b := &baseImageBuilder{
kubeclient: kubeclient,
mcfgclient: mcfgclient,
@@ -45,7 +46,7 @@ func newBaseImageBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientse
}

// Constructs a baseImageBuilder and also instantiates a Cleaner instance based upon the object state.
func newBaseImageBuilderWithCleaner(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig, builder buildrequest.Builder) (*baseImageBuilder, Cleaner) {
func newBaseImageBuilderWithCleaner(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig, builder buildrequest.Builder) (*baseImageBuilder, Cleaner) {
b := newBaseImageBuilder(kubeclient, mcfgclient, mosb, mosc, builder)
return b, &cleanerImpl{
baseImageBuilder: b,
@@ -56,31 +57,31 @@ func newBaseImageBuilderWithCleaner(kubeclient clientset.Interface, mcfgclient m
func (b *baseImageBuilder) succeededConditions() []metav1.Condition {
return []metav1.Condition{
{
Type: string(mcfgv1alpha1.MachineOSBuildPrepared),
Type: string(mcfgv1.MachineOSBuildPrepared),
Status: metav1.ConditionFalse,
Reason: "Prepared",
Message: "Build Prepared and Pending",
},
{
Type: string(mcfgv1alpha1.MachineOSBuilding),
Type: string(mcfgv1.MachineOSBuilding),
Status: metav1.ConditionFalse,
Reason: "Building",
Message: "Image Build In Progress",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildFailed),
Type: string(mcfgv1.MachineOSBuildFailed),
Status: metav1.ConditionFalse,
Reason: "Failed",
Message: "Build Failed",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildInterrupted),
Type: string(mcfgv1.MachineOSBuildInterrupted),
Status: metav1.ConditionFalse,
Reason: "Interrupted",
Message: "Build Interrupted",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildSucceeded),
Type: string(mcfgv1.MachineOSBuildSucceeded),
Status: metav1.ConditionTrue,
Reason: "Ready",
Message: "Build Ready",
@@ -92,31 +93,31 @@ func (b *baseImageBuilder) succeededConditions() []metav1.Condition {
func (b *baseImageBuilder) pendingConditions() []metav1.Condition {
return []metav1.Condition{
{
Type: string(mcfgv1alpha1.MachineOSBuildPrepared),
Type: string(mcfgv1.MachineOSBuildPrepared),
Status: metav1.ConditionTrue,
Reason: "Prepared",
Message: "Build Prepared and Pending",
},
{
Type: string(mcfgv1alpha1.MachineOSBuilding),
Type: string(mcfgv1.MachineOSBuilding),
Status: metav1.ConditionFalse,
Reason: "Building",
Message: "Image Build In Progress",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildFailed),
Type: string(mcfgv1.MachineOSBuildFailed),
Status: metav1.ConditionFalse,
Reason: "Failed",
Message: "Build Failed",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildInterrupted),
Type: string(mcfgv1.MachineOSBuildInterrupted),
Status: metav1.ConditionFalse,
Reason: "Interrupted",
Message: "Build Interrupted",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildSucceeded),
Type: string(mcfgv1.MachineOSBuildSucceeded),
Status: metav1.ConditionFalse,
Reason: "Ready",
Message: "Build Ready",
@@ -128,31 +129,31 @@ func (b *baseImageBuilder) pendingConditions() []metav1.Condition {
func (b *baseImageBuilder) runningConditions() []metav1.Condition {
return []metav1.Condition{
{
Type: string(mcfgv1alpha1.MachineOSBuildPrepared),
Type: string(mcfgv1.MachineOSBuildPrepared),
Status: metav1.ConditionFalse,
Reason: "Prepared",
Message: "Build Prepared and Pending",
},
{
Type: string(mcfgv1alpha1.MachineOSBuilding),
Type: string(mcfgv1.MachineOSBuilding),
Status: metav1.ConditionTrue,
Reason: "Building",
Message: "Image Build In Progress",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildFailed),
Type: string(mcfgv1.MachineOSBuildFailed),
Status: metav1.ConditionFalse,
Reason: "Failed",
Message: "Build Failed",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildInterrupted),
Type: string(mcfgv1.MachineOSBuildInterrupted),
Status: metav1.ConditionFalse,
Reason: "Interrupted",
Message: "Build Interrupted",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildSucceeded),
Type: string(mcfgv1.MachineOSBuildSucceeded),
Status: metav1.ConditionFalse,
Reason: "Ready",
Message: "Build Ready",
@@ -164,31 +165,31 @@ func (b *baseImageBuilder) runningConditions() []metav1.Condition {
func (b *baseImageBuilder) failedConditions() []metav1.Condition {
return []metav1.Condition{
{
Type: string(mcfgv1alpha1.MachineOSBuildPrepared),
Type: string(mcfgv1.MachineOSBuildPrepared),
Status: metav1.ConditionFalse,
Reason: "Prepared",
Message: "Build Prepared and Pending",
},
{
Type: string(mcfgv1alpha1.MachineOSBuilding),
Type: string(mcfgv1.MachineOSBuilding),
Status: metav1.ConditionFalse,
Reason: "Building",
Message: "Image Build In Progress",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildFailed),
Type: string(mcfgv1.MachineOSBuildFailed),
Status: metav1.ConditionTrue,
Reason: "Failed",
Message: "Build Failed",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildInterrupted),
Type: string(mcfgv1.MachineOSBuildInterrupted),
Status: metav1.ConditionFalse,
Reason: "Interrupted",
Message: "Build Interrupted",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildSucceeded),
Type: string(mcfgv1.MachineOSBuildSucceeded),
Status: metav1.ConditionFalse,
Reason: "Ready",
Message: "Build Ready",
@@ -200,31 +201,31 @@ func (b *baseImageBuilder) failedConditions() []metav1.Condition {
func (b *baseImageBuilder) interruptedConditions() []metav1.Condition {
return []metav1.Condition{
{
Type: string(mcfgv1alpha1.MachineOSBuildPrepared),
Type: string(mcfgv1.MachineOSBuildPrepared),
Status: metav1.ConditionFalse,
Reason: "Prepared",
Message: "Build Prepared and Pending",
},
{
Type: string(mcfgv1alpha1.MachineOSBuilding),
Type: string(mcfgv1.MachineOSBuilding),
Status: metav1.ConditionFalse,
Reason: "Building",
Message: "Image Build In Progress",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildFailed),
Type: string(mcfgv1.MachineOSBuildFailed),
Status: metav1.ConditionFalse,
Reason: "Failed",
Message: "Build Failed",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildInterrupted),
Type: string(mcfgv1.MachineOSBuildInterrupted),
Status: metav1.ConditionTrue,
Reason: "Interrupted",
Message: "Build Interrupted",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildSucceeded),
Type: string(mcfgv1.MachineOSBuildSucceeded),
Status: metav1.ConditionFalse,
Reason: "Ready",
Message: "Build Ready",
@@ -236,31 +237,31 @@ func (b *baseImageBuilder) interruptedConditions() []metav1.Condition {
func (b *baseImageBuilder) initialConditions() []metav1.Condition {
return []metav1.Condition{
{
Type: string(mcfgv1alpha1.MachineOSBuildPrepared),
Type: string(mcfgv1.MachineOSBuildPrepared),
Status: metav1.ConditionFalse,
Reason: "Prepared",
Message: "Build Prepared and Pending",
},
{
Type: string(mcfgv1alpha1.MachineOSBuilding),
Type: string(mcfgv1.MachineOSBuilding),
Status: metav1.ConditionFalse,
Reason: "Building",
Message: "Image Build In Progress",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildFailed),
Type: string(mcfgv1.MachineOSBuildFailed),
Status: metav1.ConditionFalse,
Reason: "Failed",
Message: "Build Failed",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildInterrupted),
Type: string(mcfgv1.MachineOSBuildInterrupted),
Status: metav1.ConditionFalse,
Reason: "Interrupted",
Message: "Build Interrupted",
},
{
Type: string(mcfgv1alpha1.MachineOSBuildSucceeded),
Type: string(mcfgv1.MachineOSBuildSucceeded),
Status: metav1.ConditionFalse,
Reason: "Ready",
Message: "Build Ready",
@@ -278,35 +279,35 @@ type kubeObject interface {
// Computes the MachineOSBuild status given the build status as well as the
// conditions. Also fetches the final image pullspec from the digestfile
// ConfigMap.
func (b *baseImageBuilder) getMachineOSBuildStatus(ctx context.Context, obj kubeObject, buildStatus mcfgv1alpha1.BuildProgress, conditions []metav1.Condition) (mcfgv1alpha1.MachineOSBuildStatus, error) {
func (b *baseImageBuilder) getMachineOSBuildStatus(ctx context.Context, obj kubeObject, buildStatus mcfgv1.BuildProgress, conditions []metav1.Condition) (mcfgv1.MachineOSBuildStatus, error) {
now := metav1.Now()

out := mcfgv1alpha1.MachineOSBuildStatus{}
out := mcfgv1.MachineOSBuildStatus{}

out.BuildStart = &now

if buildStatus == mcfgv1alpha1.MachineOSBuildSucceeded || buildStatus == mcfgv1alpha1.MachineOSBuildFailed || buildStatus == mcfgv1alpha1.MachineOSBuildInterrupted {
if buildStatus == mcfgv1.MachineOSBuildSucceeded || buildStatus == mcfgv1.MachineOSBuildFailed || buildStatus == mcfgv1.MachineOSBuildInterrupted {
out.BuildEnd = &now
}

if buildStatus == mcfgv1alpha1.MachineOSBuildSucceeded {
if buildStatus == mcfgv1.MachineOSBuildSucceeded {
pullspec, err := b.getFinalImagePullspec(ctx)
if err != nil {
return out, err
}

out.FinalImagePushspec = pullspec
out.DigestedImagePushSpec = mcfgv1.ImageDigestFormat(pullspec)
}

out.Conditions = conditions
out.BuilderReference = &mcfgv1alpha1.MachineOSBuilderReference{
ImageBuilderType: mcfgv1alpha1.PodBuilder,
out.Builder = &mcfgv1.MachineOSBuilderReference{
ImageBuilderType: mcfgv1.JobBuilder,
// TODO: Should we clear this whenever the build is complete?
PodImageBuilder: &mcfgv1alpha1.ObjectReference{
Job: &mcfgv1.ObjectReference{
Name: obj.GetName(),
Group: obj.GroupVersionKind().Group,
Group: batchv1.SchemeGroupVersion.Group,
Namespace: obj.GetNamespace(),
Resource: obj.GetResourceVersion(),
Resource: "jobs",
},
}

@@ -351,9 +352,9 @@ func (b *baseImageBuilder) getFinalImagePullspec(ctx context.Context) (string, e
return "", fmt.Errorf("could not get final image digest configmap %q: %w", name, err)
}

sha, err := utils.ParseImagePullspec(b.mosc.Spec.BuildInputs.RenderedImagePushspec, digestConfigMap.Data["digest"])
sha, err := utils.ParseImagePullspec(string(b.mosc.Spec.RenderedImagePushSpec), digestConfigMap.Data["digest"])
if err != nil {
return "", fmt.Errorf("could not create digested image pullspec from the pullspec %q and the digest %q: %w", b.mosc.Status.CurrentImagePullspec, digestConfigMap.Data["digest"], err)
return "", fmt.Errorf("could not create digested image pullspec from the pullspec %q and the digest %q: %w", b.mosc.Status.CurrentImagePullSpec, digestConfigMap.Data["digest"], err)
}

return sha, nil
4 changes: 2 additions & 2 deletions pkg/controller/build/imagebuilder/cleaner.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"context"
"fmt"

mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgclientset "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
"github.com/openshift/machine-config-operator/pkg/controller/build/buildrequest"
"github.com/openshift/machine-config-operator/pkg/controller/build/constants"
@@ -26,7 +26,7 @@ type cleanerImpl struct {
// Constructs an instance of the cleaner from the MachineOSBuild and
// MachineOSConfig objects. It is possible that the MachineOSConfig can be nil,
// which this tolerates.
func newCleaner(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig) Cleaner {
func newCleaner(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig) Cleaner {
return &cleanerImpl{
baseImageBuilder: newBaseImageBuilder(kubeclient, mcfgclient, mosb, mosc, nil),
}
6 changes: 3 additions & 3 deletions pkg/controller/build/imagebuilder/interfaces.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package imagebuilder
import (
"context"

mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
"github.com/openshift/machine-config-operator/pkg/controller/build/buildrequest"
)

@@ -35,6 +35,6 @@ type Cleaner interface {
// MachineOSBuildStatus object.
type ImageBuildObserver interface {
Exists(context.Context) (bool, error)
Status(context.Context) (mcfgv1alpha1.BuildProgress, error)
MachineOSBuildStatus(context.Context) (mcfgv1alpha1.MachineOSBuildStatus, error)
Status(context.Context) (mcfgv1.BuildProgress, error)
MachineOSBuildStatus(context.Context) (mcfgv1.MachineOSBuildStatus, error)
}
36 changes: 18 additions & 18 deletions pkg/controller/build/imagebuilder/jobimagebuilder.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import (
"errors"
"fmt"

mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgclientset "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
"github.com/openshift/machine-config-operator/pkg/controller/build/buildrequest"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
@@ -22,7 +22,7 @@ type jobImageBuilder struct {
cleaner Cleaner
}

func newJobImageBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig, builder buildrequest.Builder) *jobImageBuilder {
func newJobImageBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig, builder buildrequest.Builder) *jobImageBuilder {
b, c := newBaseImageBuilderWithCleaner(kubeclient, mcfgclient, mosb, mosc, builder)
return &jobImageBuilder{
baseImageBuilder: b,
@@ -31,23 +31,23 @@ func newJobImageBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset
}

// Instantiates a ImageBuildObserver using the MachineOSBuild and MachineOSConfig objects.
func NewJobImageBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig) ImageBuilder {
func NewJobImageBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig) ImageBuilder {
return newJobImageBuilder(kubeclient, mcfgclient, mosb, mosc, nil)
}

// Instantiates an ImageBuildObserver using the MachineOSBuild and MachineOSConfig objects.
func NewJobImageBuildObserver(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig) ImageBuildObserver {
func NewJobImageBuildObserver(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig) ImageBuildObserver {
return newJobImageBuilder(kubeclient, mcfgclient, mosb, mosc, nil)
}

// Instantiates an ImageBuildObserver which infers the MachineOSBuild state
// from the provided builder object
func NewJobImageBuildObserverFromBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig, builder buildrequest.Builder) ImageBuildObserver {
func NewJobImageBuildObserverFromBuilder(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig, builder buildrequest.Builder) ImageBuildObserver {
return newJobImageBuilder(kubeclient, mcfgclient, mosb, mosc, builder)
}

// Instantiates a Cleaner using only the MachineOSBuild object.
func NewJobImageBuildCleaner(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild) Cleaner {
func NewJobImageBuildCleaner(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild) Cleaner {
return newJobImageBuilder(kubeclient, mcfgclient, mosb, nil, nil)
}

@@ -149,7 +149,7 @@ func (j *jobImageBuilder) Exists(ctx context.Context) (bool, error) {
}

// Gets the MachineOSBuildStatus for the currently running build.
func (j *jobImageBuilder) MachineOSBuildStatus(ctx context.Context) (mcfgv1alpha1.MachineOSBuildStatus, error) {
func (j *jobImageBuilder) MachineOSBuildStatus(ctx context.Context) (mcfgv1.MachineOSBuildStatus, error) {
status, err := j.machineOSBuildStatus(ctx)
if err != nil {
return status, j.addMachineOSBuildNameToError(fmt.Errorf("could not get MachineOSBuildStatus: %w", err))
@@ -180,7 +180,7 @@ func (j *jobImageBuilder) getBuildJobFromBuilderOrAPI(ctx context.Context) (*bat
return job, nil
}

func (j *jobImageBuilder) getStatus(ctx context.Context) (*batchv1.Job, mcfgv1alpha1.BuildProgress, []metav1.Condition, error) {
func (j *jobImageBuilder) getStatus(ctx context.Context) (*batchv1.Job, mcfgv1.BuildProgress, []metav1.Condition, error) {
job, err := j.getBuildJobFromBuilderOrAPI(ctx)
if err != nil {
return nil, "", nil, err
@@ -193,22 +193,22 @@ func (j *jobImageBuilder) getStatus(ctx context.Context) (*batchv1.Job, mcfgv1al
return job, status, conditions, nil
}

func (j *jobImageBuilder) machineOSBuildStatus(ctx context.Context) (mcfgv1alpha1.MachineOSBuildStatus, error) {
func (j *jobImageBuilder) machineOSBuildStatus(ctx context.Context) (mcfgv1.MachineOSBuildStatus, error) {
job, status, conditions, err := j.getStatus(ctx)
if err != nil {
return mcfgv1alpha1.MachineOSBuildStatus{}, err
return mcfgv1.MachineOSBuildStatus{}, err
}

buildStatus, err := j.getMachineOSBuildStatus(ctx, job, status, conditions)
if err != nil {
return mcfgv1alpha1.MachineOSBuildStatus{}, err
return mcfgv1.MachineOSBuildStatus{}, err
}

return buildStatus, nil
}

// Gets only the build progress field for a currently running build.
func (j *jobImageBuilder) Status(ctx context.Context) (mcfgv1alpha1.BuildProgress, error) {
func (j *jobImageBuilder) Status(ctx context.Context) (mcfgv1.BuildProgress, error) {
_, status, _, err := j.getStatus(ctx)
if err != nil {
return status, j.addMachineOSBuildNameToError(fmt.Errorf("could not get BuildProgress: %w", err))
@@ -217,26 +217,26 @@ func (j *jobImageBuilder) Status(ctx context.Context) (mcfgv1alpha1.BuildProgres
return status, nil
}

func (j *jobImageBuilder) mapJobStatusToBuildStatus(job *batchv1.Job) (mcfgv1alpha1.BuildProgress, []metav1.Condition) {
func (j *jobImageBuilder) mapJobStatusToBuildStatus(job *batchv1.Job) (mcfgv1.BuildProgress, []metav1.Condition) {
// If the job is being deleted and it was not in either a successful or failed state
// then the MachineOSBuild should be considered "interrupted"
if job.DeletionTimestamp != nil && job.Status.Succeeded == 0 && job.Status.Failed == 0 {
return mcfgv1alpha1.MachineOSBuildInterrupted, j.interruptedConditions()
return mcfgv1.MachineOSBuildInterrupted, j.interruptedConditions()
}

if job.Status.Active == 0 && job.Status.Succeeded == 0 && job.Status.Failed == 0 && job.Status.UncountedTerminatedPods == nil {
return mcfgv1alpha1.MachineOSBuildPrepared, j.pendingConditions()
return mcfgv1.MachineOSBuildPrepared, j.pendingConditions()
}
// The build job is still running till it succeeds or maxes out it retries on failures
if job.Status.Active >= 0 && job.Status.Failed >= 0 && job.Status.Failed < 4 && job.Status.Succeeded == 0 {
return mcfgv1alpha1.MachineOSBuilding, j.runningConditions()
return mcfgv1.MachineOSBuilding, j.runningConditions()
}
if job.Status.Succeeded > 0 {
return mcfgv1alpha1.MachineOSBuildSucceeded, j.succeededConditions()
return mcfgv1.MachineOSBuildSucceeded, j.succeededConditions()
}
// Only return failed if there have been 4 pod failures as the backoffLimit is set to 3
if job.Status.Failed > 3 {
return mcfgv1alpha1.MachineOSBuildFailed, j.failedConditions()
return mcfgv1.MachineOSBuildFailed, j.failedConditions()

}

42 changes: 21 additions & 21 deletions pkg/controller/build/imagebuilder/jobimagebuilder_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
"github.com/openshift/machine-config-operator/pkg/apihelpers"
"github.com/openshift/machine-config-operator/pkg/controller/build/buildrequest"
"github.com/openshift/machine-config-operator/pkg/controller/build/fixtures"
@@ -146,27 +146,27 @@ func assertMachineOSBuildStateMapsToCommonState(ctx context.Context, t *testing.

// These are states where the MachineOSBuild may transition from either these
// states or to a terminal state.
transientBuildStates := map[mcfgv1alpha1.BuildProgress]struct{}{
mcfgv1alpha1.MachineOSBuildPrepared: {},
mcfgv1alpha1.MachineOSBuilding: {},
transientBuildStates := map[mcfgv1.BuildProgress]struct{}{
mcfgv1.MachineOSBuildPrepared: {},
mcfgv1.MachineOSBuilding: {},
}

// A terminal state is one where the MachineOSBuild cannot transition to any
// other state. It is considered the "final" state.
terminalBuildStates := map[mcfgv1alpha1.BuildProgress]struct{}{
mcfgv1alpha1.MachineOSBuildFailed: {},
mcfgv1alpha1.MachineOSBuildSucceeded: {},
mcfgv1alpha1.MachineOSBuildInterrupted: {},
terminalBuildStates := map[mcfgv1.BuildProgress]struct{}{
mcfgv1.MachineOSBuildFailed: {},
mcfgv1.MachineOSBuildSucceeded: {},
mcfgv1.MachineOSBuildInterrupted: {},
}

// Map of the build state to each function that should return true when the
// MachineOSBuild is in that particular state.
mosbStateFuncs := map[mcfgv1alpha1.BuildProgress]func() bool{
mcfgv1alpha1.MachineOSBuildPrepared: mosbState.IsBuildPrepared,
mcfgv1alpha1.MachineOSBuilding: mosbState.IsBuilding,
mcfgv1alpha1.MachineOSBuildFailed: mosbState.IsBuildFailure,
mcfgv1alpha1.MachineOSBuildSucceeded: mosbState.IsBuildSuccess,
mcfgv1alpha1.MachineOSBuildInterrupted: mosbState.IsBuildInterrupted,
mosbStateFuncs := map[mcfgv1.BuildProgress]func() bool{
mcfgv1.MachineOSBuildPrepared: mosbState.IsBuildPrepared,
mcfgv1.MachineOSBuilding: mosbState.IsBuilding,
mcfgv1.MachineOSBuildFailed: mosbState.IsBuildFailure,
mcfgv1.MachineOSBuildSucceeded: mosbState.IsBuildSuccess,
mcfgv1.MachineOSBuildInterrupted: mosbState.IsBuildInterrupted,
}

// Iterate through all of the known states and call the function from the helper library.
@@ -192,11 +192,11 @@ func assertMachineOSBuildStateMapsToCommonState(ctx context.Context, t *testing.
}

func assertObserverCanGetJobStatus(ctx context.Context, t *testing.T, obs ImageBuildObserver, jobPhase string) {
buildprogressToJobPhases := map[mcfgv1alpha1.BuildProgress]string{
mcfgv1alpha1.MachineOSBuildPrepared: jobPending,
mcfgv1alpha1.MachineOSBuilding: jobRunning,
mcfgv1alpha1.MachineOSBuildFailed: jobFailed,
mcfgv1alpha1.MachineOSBuildSucceeded: jobSucceeded,
buildprogressToJobPhases := map[mcfgv1.BuildProgress]string{
mcfgv1.MachineOSBuildPrepared: jobPending,
mcfgv1.MachineOSBuilding: jobRunning,
mcfgv1.MachineOSBuildFailed: jobFailed,
mcfgv1.MachineOSBuildSucceeded: jobSucceeded,
}

buildprogress, err := obs.Status(ctx)
@@ -209,11 +209,11 @@ func assertObserverCanGetJobStatus(ctx context.Context, t *testing.T, obs ImageB

assert.True(t, apihelpers.IsMachineOSBuildConditionTrue(mosbStatus.Conditions, buildprogress))

assert.NotNil(t, mosbStatus.BuilderReference)
assert.NotNil(t, mosbStatus.Builder)

if jobPhase == jobSucceeded {
assert.NotNil(t, mosbStatus.BuildEnd)
assert.Equal(t, "registry.hostname.com/org/repo@sha256:e1992921cba73d9e74e46142eca5946df8a895bfd4419fc8b5c6422d5e7192e6", mosbStatus.FinalImagePushspec)
assert.Equal(t, "registry.hostname.com/org/repo@sha256:e1992921cba73d9e74e46142eca5946df8a895bfd4419fc8b5c6422d5e7192e6", string(mosbStatus.DigestedImagePushSpec))
}

assertMachineOSBuildStateMapsToCommonState(ctx, t, obs)
8 changes: 4 additions & 4 deletions pkg/controller/build/imagebuilder/preparer.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"context"
"fmt"

mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
mcfgclientset "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
"github.com/openshift/machine-config-operator/pkg/controller/build/buildrequest"
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
@@ -22,13 +22,13 @@ import (
// object knows how to destroy all of the objects that it creates. It does so
// by using a specific label query.
type preparerImpl struct {
mosb *mcfgv1alpha1.MachineOSBuild
mosc *mcfgv1alpha1.MachineOSConfig
mosb *mcfgv1.MachineOSBuild
mosc *mcfgv1.MachineOSConfig
kubeclient clientset.Interface
mcfgclient mcfgclientset.Interface
}

func NewPreparer(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1alpha1.MachineOSBuild, mosc *mcfgv1alpha1.MachineOSConfig) Preparer {
func NewPreparer(kubeclient clientset.Interface, mcfgclient mcfgclientset.Interface, mosb *mcfgv1.MachineOSBuild, mosc *mcfgv1.MachineOSConfig) Preparer {
return &preparerImpl{
kubeclient: kubeclient,
mcfgclient: mcfgclient,
19 changes: 9 additions & 10 deletions pkg/controller/build/osbuildcontroller.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import (
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"

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/client-go/machineconfiguration/clientset/versioned/scheme"
"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
@@ -216,22 +215,22 @@ func (ctrl *OSBuildController) enqueueFuncForObject(obj kubeObject, toRun func(c
}

func (ctrl *OSBuildController) addMachineOSBuild(cur interface{}) {
mosb := cur.(*mcfgv1alpha1.MachineOSBuild)
mosb := cur.(*mcfgv1.MachineOSBuild)
ctrl.enqueueFuncForObject(mosb, func(ctx context.Context) error {
return ctrl.buildReconciler.AddMachineOSBuild(ctx, mosb)
})
}

func (ctrl *OSBuildController) updateMachineOSBuild(old, cur interface{}) {
oldMOSB := old.(*mcfgv1alpha1.MachineOSBuild)
curMOSB := cur.(*mcfgv1alpha1.MachineOSBuild)
oldMOSB := old.(*mcfgv1.MachineOSBuild)
curMOSB := cur.(*mcfgv1.MachineOSBuild)
ctrl.enqueueFuncForObject(curMOSB, func(ctx context.Context) error {
return ctrl.buildReconciler.UpdateMachineOSBuild(ctx, oldMOSB, curMOSB)
})
}

func (ctrl *OSBuildController) deleteMachineOSBuild(cur interface{}) {
mosb := cur.(*mcfgv1alpha1.MachineOSBuild)
mosb := cur.(*mcfgv1.MachineOSBuild)
ctrl.enqueueFuncForObject(mosb, func(ctx context.Context) error {
return ctrl.buildReconciler.DeleteMachineOSBuild(ctx, mosb)
})
@@ -261,29 +260,29 @@ func (ctrl *OSBuildController) deleteJob(cur interface{}) {
}

func (ctrl *OSBuildController) addMachineOSConfig(newMOSC interface{}) {
m := newMOSC.(*mcfgv1alpha1.MachineOSConfig).DeepCopy()
m := newMOSC.(*mcfgv1.MachineOSConfig).DeepCopy()
ctrl.enqueueFuncForObject(m, func(ctx context.Context) error {
return ctrl.buildReconciler.AddMachineOSConfig(ctx, m)
})
}

func (ctrl *OSBuildController) updateMachineOSConfig(old, cur interface{}) {
oldMOSC := old.(*mcfgv1alpha1.MachineOSConfig).DeepCopy()
curMOSC := cur.(*mcfgv1alpha1.MachineOSConfig).DeepCopy()
oldMOSC := old.(*mcfgv1.MachineOSConfig).DeepCopy()
curMOSC := cur.(*mcfgv1.MachineOSConfig).DeepCopy()
ctrl.enqueueFuncForObject(curMOSC, func(ctx context.Context) error {
return ctrl.buildReconciler.UpdateMachineOSConfig(ctx, oldMOSC, curMOSC)
})
}

func (ctrl *OSBuildController) deleteMachineOSConfig(cur interface{}) {
mosc, ok := cur.(*mcfgv1alpha1.MachineOSConfig)
mosc, ok := cur.(*mcfgv1.MachineOSConfig)
if !ok {
tombstone, ok := cur.(cache.DeletedFinalStateUnknown)
if !ok {
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", cur))
return
}
mosc, ok = tombstone.Obj.(*mcfgv1alpha1.MachineOSConfig)
mosc, ok = tombstone.Obj.(*mcfgv1.MachineOSConfig)
if !ok {
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a MachineOSConfig %#v", cur))
return
Loading

0 comments on commit cfdda14

Please sign in to comment.