Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[DNM] MCO-1437: MCO-1476: MCO-1477: MCO-1284: Adapt MCO to OCL v1 API #4756

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
ctx.KubeInformerFactory.Core().V1().Nodes(),
ctx.KubeInformerFactory.Core().V1().Pods(),
ctx.TechPreviewInformerFactory.Machineconfiguration().V1alpha1().MachineOSConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().MachineOSConfigs(),
ctx.ConfigInformerFactory.Config().V1().Schedulers(),
ctx.ClientBuilder.KubeClientOrDie("node-update-controller"),
ctx.ClientBuilder.MachineConfigClientOrDie("node-update-controller"),
Expand Down
6 changes: 1 addition & 5 deletions devex/cmd/onclustertesting/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
65 changes: 29 additions & 36 deletions devex/cmd/onclustertesting/machineosconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions devex/cmd/onclustertesting/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions devex/cmd/onclustertesting/teardown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
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]
Expand Down
17 changes: 8 additions & 9 deletions devex/internal/pkg/utils/apiutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(), ""),
}
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/apihelpers/machineosbuild.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package apihelpers

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

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

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

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

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

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

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

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

// IsMachineOSBuildConditionPresentAndEqual returns true when conditionType is present and equal to status.
func IsMachineOSBuildConditionPresentAndEqual(conditions []metav1.Condition, conditionType mcfgv1alpha1.BuildProgress, status metav1.ConditionStatus) bool {
func IsMachineOSBuildConditionPresentAndEqual(conditions []metav1.Condition, conditionType mcfgv1.BuildProgress, status metav1.ConditionStatus) bool {
for _, condition := range conditions {
if mcfgv1alpha1.BuildProgress(condition.Type) == conditionType {
if mcfgv1.BuildProgress(condition.Type) == conditionType {
return condition.Status == status
}
}
Expand Down
Loading