diff --git a/Containerfile.helpers b/Containerfile.helpers deleted file mode 100644 index 3927b12046..0000000000 --- a/Containerfile.helpers +++ /dev/null @@ -1,28 +0,0 @@ -FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-builder-multi-openshift-4.18 AS fetcher -WORKDIR /oc -RUN < $@.tmp && mv $@.tmp $@ +# Validates that all of the e2e test suites are valid Golang by performing a test compilation. +verify-e2e: $(patsubst %,_verify-e2e-%,$(E2E_SUITES)) + # This was copied from https://github.com/openshift/cluster-image-registry-operator test-e2e: install-go-junit-report set -o pipefail; go test -tags=$(GOTAGS) -failfast -timeout 170m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e/ ./test/e2e-techpreview-shared/ | ./hack/test-with-junit.sh $(@) diff --git a/devex/README.md b/devex/README.md new file mode 100644 index 0000000000..134eef882c --- /dev/null +++ b/devex/README.md @@ -0,0 +1,18 @@ +# devex + +## Background + +This directory contains Golang programs which are most likely to be of use to +fellow OpenShift developers, especially members of the +[machine-config-operator](https://github.com/openshift/machine-config-operator) +team. The helpers found here may be of use to you. They may not. They may +completely break entirely. + +It is worth mentioning that these helpers may get your cluster into a +difficult-to-recover-from state. So do not use these on a production OpenShift +cluster. + +## Installation + +From the repo root, run: `make install-helpers`. Note: You'll periodically have +to update the helpers based upon the current state of the MCO repository. diff --git a/hack/cmd/mcdiff/diff.go b/devex/cmd/mcdiff/diff.go similarity index 100% rename from hack/cmd/mcdiff/diff.go rename to devex/cmd/mcdiff/diff.go diff --git a/hack/cmd/mcdiff/main.go b/devex/cmd/mcdiff/main.go similarity index 100% rename from hack/cmd/mcdiff/main.go rename to devex/cmd/mcdiff/main.go diff --git a/hack/cmd/mco-builder/README.md b/devex/cmd/mco-builder/README.md similarity index 100% rename from hack/cmd/mco-builder/README.md rename to devex/cmd/mco-builder/README.md diff --git a/hack/cmd/mco-builder/helpers.go b/devex/cmd/mco-builder/helpers.go similarity index 100% rename from hack/cmd/mco-builder/helpers.go rename to devex/cmd/mco-builder/helpers.go diff --git a/hack/cmd/mco-builder/imagestream.go b/devex/cmd/mco-builder/imagestream.go similarity index 100% rename from hack/cmd/mco-builder/imagestream.go rename to devex/cmd/mco-builder/imagestream.go diff --git a/hack/cmd/mco-builder/internal/builders/common.go b/devex/cmd/mco-builder/internal/builders/common.go similarity index 96% rename from hack/cmd/mco-builder/internal/builders/common.go rename to devex/cmd/mco-builder/internal/builders/common.go index 020acdf201..0f5d4ba857 100644 --- a/hack/cmd/mco-builder/internal/builders/common.go +++ b/devex/cmd/mco-builder/internal/builders/common.go @@ -6,7 +6,7 @@ import ( "os/exec" "strings" - "github.com/openshift/machine-config-operator/hack/internal/pkg/errors" + "github.com/openshift/machine-config-operator/devex/internal/pkg/errors" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" ) diff --git a/hack/cmd/mco-builder/internal/builders/podman.go b/devex/cmd/mco-builder/internal/builders/podman.go similarity index 96% rename from hack/cmd/mco-builder/internal/builders/podman.go rename to devex/cmd/mco-builder/internal/builders/podman.go index bd54197195..a18d051136 100644 --- a/hack/cmd/mco-builder/internal/builders/podman.go +++ b/devex/cmd/mco-builder/internal/builders/podman.go @@ -5,7 +5,7 @@ import ( "os" "os/exec" - "github.com/openshift/machine-config-operator/hack/internal/pkg/errors" + "github.com/openshift/machine-config-operator/devex/internal/pkg/errors" "k8s.io/klog/v2" ) diff --git a/hack/cmd/mco-builder/local.go b/devex/cmd/mco-builder/local.go similarity index 96% rename from hack/cmd/mco-builder/local.go rename to devex/cmd/mco-builder/local.go index 3b52114996..905b2481b6 100644 --- a/hack/cmd/mco-builder/local.go +++ b/devex/cmd/mco-builder/local.go @@ -9,10 +9,10 @@ import ( "path/filepath" "runtime" - "github.com/openshift/machine-config-operator/hack/cmd/mco-builder/internal/builders" - "github.com/openshift/machine-config-operator/hack/internal/pkg/containers" - "github.com/openshift/machine-config-operator/hack/internal/pkg/rollout" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/cmd/mco-builder/internal/builders" + "github.com/openshift/machine-config-operator/devex/internal/pkg/containers" + "github.com/openshift/machine-config-operator/devex/internal/pkg/rollout" + "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" "github.com/spf13/cobra" diff --git a/hack/cmd/mco-builder/main.go b/devex/cmd/mco-builder/main.go similarity index 100% rename from hack/cmd/mco-builder/main.go rename to devex/cmd/mco-builder/main.go diff --git a/hack/cmd/mco-builder/revert.go b/devex/cmd/mco-builder/revert.go similarity index 93% rename from hack/cmd/mco-builder/revert.go rename to devex/cmd/mco-builder/revert.go index 7267cf47a0..0e43bcbc11 100644 --- a/hack/cmd/mco-builder/revert.go +++ b/devex/cmd/mco-builder/revert.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/openshift/machine-config-operator/hack/internal/pkg/rollout" + "github.com/openshift/machine-config-operator/devex/internal/pkg/rollout" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" diff --git a/hack/cmd/mco-push/README.md b/devex/cmd/mco-push/README.md similarity index 100% rename from hack/cmd/mco-push/README.md rename to devex/cmd/mco-push/README.md diff --git a/hack/cmd/mco-push/main.go b/devex/cmd/mco-push/main.go similarity index 100% rename from hack/cmd/mco-push/main.go rename to devex/cmd/mco-push/main.go diff --git a/hack/cmd/mco-push/replace.go b/devex/cmd/mco-push/replace.go similarity index 91% rename from hack/cmd/mco-push/replace.go rename to devex/cmd/mco-push/replace.go index 35b0d50782..8c06ab024a 100644 --- a/hack/cmd/mco-push/replace.go +++ b/devex/cmd/mco-push/replace.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/openshift/machine-config-operator/hack/internal/pkg/containers" - "github.com/openshift/machine-config-operator/hack/internal/pkg/rollout" + "github.com/openshift/machine-config-operator/devex/internal/pkg/containers" + "github.com/openshift/machine-config-operator/devex/internal/pkg/rollout" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" "k8s.io/klog/v2" diff --git a/hack/cmd/mco-push/restart.go b/devex/cmd/mco-push/restart.go similarity index 91% rename from hack/cmd/mco-push/restart.go rename to devex/cmd/mco-push/restart.go index 73f6bdbdfe..3f06c2f4ca 100644 --- a/hack/cmd/mco-push/restart.go +++ b/devex/cmd/mco-push/restart.go @@ -1,7 +1,7 @@ package main import ( - "github.com/openshift/machine-config-operator/hack/internal/pkg/rollout" + "github.com/openshift/machine-config-operator/devex/internal/pkg/rollout" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" "k8s.io/klog/v2" diff --git a/hack/cmd/mco-push/revert.go b/devex/cmd/mco-push/revert.go similarity index 91% rename from hack/cmd/mco-push/revert.go rename to devex/cmd/mco-push/revert.go index 615fd540a7..5962a3de6a 100644 --- a/hack/cmd/mco-push/revert.go +++ b/devex/cmd/mco-push/revert.go @@ -1,7 +1,7 @@ package main import ( - "github.com/openshift/machine-config-operator/hack/internal/pkg/rollout" + "github.com/openshift/machine-config-operator/devex/internal/pkg/rollout" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" "k8s.io/klog/v2" diff --git a/hack/cmd/onclustertesting/README.md b/devex/cmd/onclustertesting/README.md similarity index 100% rename from hack/cmd/onclustertesting/README.md rename to devex/cmd/onclustertesting/README.md diff --git a/hack/cmd/onclustertesting/build.go b/devex/cmd/onclustertesting/build.go similarity index 97% rename from hack/cmd/onclustertesting/build.go rename to devex/cmd/onclustertesting/build.go index f13212326b..548e579522 100644 --- a/hack/cmd/onclustertesting/build.go +++ b/devex/cmd/onclustertesting/build.go @@ -6,7 +6,7 @@ import ( "os/exec" "path/filepath" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "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" "golang.org/x/sync/errgroup" diff --git a/hack/cmd/onclustertesting/ci.go b/devex/cmd/onclustertesting/ci.go similarity index 91% rename from hack/cmd/onclustertesting/ci.go rename to devex/cmd/onclustertesting/ci.go index fbd54b1e5e..8bb0984c0b 100644 --- a/hack/cmd/onclustertesting/ci.go +++ b/devex/cmd/onclustertesting/ci.go @@ -5,8 +5,8 @@ import ( "fmt" "time" - "github.com/openshift/machine-config-operator/hack/internal/pkg/rollout" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/rollout" + "github.com/openshift/machine-config-operator/devex/internal/pkg/utils" "github.com/openshift/machine-config-operator/test/framework" "golang.org/x/sync/errgroup" apierrs "k8s.io/apimachinery/pkg/api/errors" @@ -156,7 +156,9 @@ func waitForPoolsToComplete(cs *framework.ClientSet, pools []string) error { pool := pool eg.Go(func() error { - return rollout.WaitForMachineConfigPoolUpdateToComplete(cs, time.Minute*30, pool) + // TODO: Figure out why WaitForMachineConfigPoolToComplete() is not + // showing control-plane node status when nodes are considered. + return rollout.WaitForOnlyMachineConfigPoolToComplete(cs, pool, time.Minute*30) }) } diff --git a/hack/cmd/onclustertesting/configmaps.go b/devex/cmd/onclustertesting/configmaps.go similarity index 100% rename from hack/cmd/onclustertesting/configmaps.go rename to devex/cmd/onclustertesting/configmaps.go diff --git a/hack/cmd/onclustertesting/featuregate.go b/devex/cmd/onclustertesting/featuregate.go similarity index 100% rename from hack/cmd/onclustertesting/featuregate.go rename to devex/cmd/onclustertesting/featuregate.go diff --git a/hack/cmd/onclustertesting/helpers.go b/devex/cmd/onclustertesting/helpers.go similarity index 99% rename from hack/cmd/onclustertesting/helpers.go rename to devex/cmd/onclustertesting/helpers.go index 0f234efbc7..7f5e643a25 100644 --- a/hack/cmd/onclustertesting/helpers.go +++ b/devex/cmd/onclustertesting/helpers.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/openshift/machine-config-operator/hack/cmd/onclustertesting/internal/legacycmds" + "github.com/openshift/machine-config-operator/devex/cmd/onclustertesting/internal/legacycmds" "github.com/openshift/machine-config-operator/test/framework" "github.com/openshift/machine-config-operator/test/helpers" "golang.org/x/sync/errgroup" diff --git a/hack/cmd/onclustertesting/imagestream.go b/devex/cmd/onclustertesting/imagestream.go similarity index 100% rename from hack/cmd/onclustertesting/imagestream.go rename to devex/cmd/onclustertesting/imagestream.go diff --git a/hack/cmd/onclustertesting/internal/legacycmds/clearstatus.go b/devex/cmd/onclustertesting/internal/legacycmds/clearstatus.go similarity index 96% rename from hack/cmd/onclustertesting/internal/legacycmds/clearstatus.go rename to devex/cmd/onclustertesting/internal/legacycmds/clearstatus.go index f95d9c7975..d98572606a 100644 --- a/hack/cmd/onclustertesting/internal/legacycmds/clearstatus.go +++ b/devex/cmd/onclustertesting/internal/legacycmds/clearstatus.go @@ -5,7 +5,7 @@ import ( "fmt" mcfgv1 "github.com/openshift/api/machineconfiguration/v1" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/utils" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/hack/cmd/onclustertesting/internal/legacycmds/extract.go b/devex/cmd/onclustertesting/internal/legacycmds/extract.go similarity index 97% rename from hack/cmd/onclustertesting/internal/legacycmds/extract.go rename to devex/cmd/onclustertesting/internal/legacycmds/extract.go index 7792e4fafc..623747cb41 100644 --- a/hack/cmd/onclustertesting/internal/legacycmds/extract.go +++ b/devex/cmd/onclustertesting/internal/legacycmds/extract.go @@ -6,7 +6,7 @@ import ( "os" "path/filepath" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "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" "github.com/spf13/cobra" diff --git a/hack/cmd/onclustertesting/internal/legacycmds/legacycmds.go b/devex/cmd/onclustertesting/internal/legacycmds/legacycmds.go similarity index 100% rename from hack/cmd/onclustertesting/internal/legacycmds/legacycmds.go rename to devex/cmd/onclustertesting/internal/legacycmds/legacycmds.go diff --git a/hack/cmd/onclustertesting/internal/legacycmds/machineconfig.go b/devex/cmd/onclustertesting/internal/legacycmds/machineconfig.go similarity index 98% rename from hack/cmd/onclustertesting/internal/legacycmds/machineconfig.go rename to devex/cmd/onclustertesting/internal/legacycmds/machineconfig.go index 09d291a056..d2c1d9781e 100644 --- a/hack/cmd/onclustertesting/internal/legacycmds/machineconfig.go +++ b/devex/cmd/onclustertesting/internal/legacycmds/machineconfig.go @@ -7,7 +7,7 @@ import ( "path/filepath" "github.com/ghodss/yaml" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/utils" ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common" ign3types "github.com/coreos/ignition/v2/config/v3_4/types" diff --git a/hack/cmd/onclustertesting/internal/legacycmds/setimage.go b/devex/cmd/onclustertesting/internal/legacycmds/setimage.go similarity index 97% rename from hack/cmd/onclustertesting/internal/legacycmds/setimage.go rename to devex/cmd/onclustertesting/internal/legacycmds/setimage.go index bc3256cd17..2b2b207d8d 100644 --- a/hack/cmd/onclustertesting/internal/legacycmds/setimage.go +++ b/devex/cmd/onclustertesting/internal/legacycmds/setimage.go @@ -5,7 +5,7 @@ import ( "fmt" mcfgv1 "github.com/openshift/api/machineconfiguration/v1" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "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" "github.com/spf13/cobra" diff --git a/hack/cmd/onclustertesting/internal/legacycmds/setstatus.go b/devex/cmd/onclustertesting/internal/legacycmds/setstatus.go similarity index 97% rename from hack/cmd/onclustertesting/internal/legacycmds/setstatus.go rename to devex/cmd/onclustertesting/internal/legacycmds/setstatus.go index 10f13f4657..721a52a1e1 100644 --- a/hack/cmd/onclustertesting/internal/legacycmds/setstatus.go +++ b/devex/cmd/onclustertesting/internal/legacycmds/setstatus.go @@ -4,7 +4,7 @@ import ( "context" mcfgv1 "github.com/openshift/api/machineconfiguration/v1" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/utils" "github.com/openshift/machine-config-operator/pkg/apihelpers" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" diff --git a/hack/cmd/onclustertesting/legacycmds.go b/devex/cmd/onclustertesting/legacycmds.go similarity index 85% rename from hack/cmd/onclustertesting/legacycmds.go rename to devex/cmd/onclustertesting/legacycmds.go index 800311ffeb..3ab43e8df7 100644 --- a/hack/cmd/onclustertesting/legacycmds.go +++ b/devex/cmd/onclustertesting/legacycmds.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/openshift/machine-config-operator/hack/cmd/onclustertesting/internal/legacycmds" + "github.com/openshift/machine-config-operator/devex/cmd/onclustertesting/internal/legacycmds" "github.com/spf13/cobra" ) diff --git a/hack/cmd/onclustertesting/machineosconfigs.go b/devex/cmd/onclustertesting/machineosconfigs.go similarity index 98% rename from hack/cmd/onclustertesting/machineosconfigs.go rename to devex/cmd/onclustertesting/machineosconfigs.go index 740f53d9f4..82d154de44 100644 --- a/hack/cmd/onclustertesting/machineosconfigs.go +++ b/devex/cmd/onclustertesting/machineosconfigs.go @@ -8,7 +8,7 @@ import ( 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" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "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" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/hack/cmd/onclustertesting/main.go b/devex/cmd/onclustertesting/main.go similarity index 100% rename from hack/cmd/onclustertesting/main.go rename to devex/cmd/onclustertesting/main.go diff --git a/hack/cmd/onclustertesting/optin.go b/devex/cmd/onclustertesting/optin.go similarity index 97% rename from hack/cmd/onclustertesting/optin.go rename to devex/cmd/onclustertesting/optin.go index b3e5ab4329..27ff73e19e 100644 --- a/hack/cmd/onclustertesting/optin.go +++ b/devex/cmd/onclustertesting/optin.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/utils" "github.com/openshift/machine-config-operator/test/framework" "github.com/openshift/machine-config-operator/test/helpers" "github.com/spf13/cobra" diff --git a/hack/cmd/onclustertesting/optout.go b/devex/cmd/onclustertesting/optout.go similarity index 96% rename from hack/cmd/onclustertesting/optout.go rename to devex/cmd/onclustertesting/optout.go index 2d6820d65a..3487e69888 100644 --- a/hack/cmd/onclustertesting/optout.go +++ b/devex/cmd/onclustertesting/optout.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/utils" "github.com/openshift/machine-config-operator/test/framework" "github.com/openshift/machine-config-operator/test/helpers" "github.com/spf13/cobra" diff --git a/hack/cmd/onclustertesting/opts.go b/devex/cmd/onclustertesting/opts.go similarity index 100% rename from hack/cmd/onclustertesting/opts.go rename to devex/cmd/onclustertesting/opts.go diff --git a/hack/cmd/onclustertesting/secrets.go b/devex/cmd/onclustertesting/secrets.go similarity index 99% rename from hack/cmd/onclustertesting/secrets.go rename to devex/cmd/onclustertesting/secrets.go index 91a3f9c45f..9aeed15915 100644 --- a/hack/cmd/onclustertesting/secrets.go +++ b/devex/cmd/onclustertesting/secrets.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/ghodss/yaml" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "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" "github.com/openshift/machine-config-operator/test/helpers" diff --git a/hack/cmd/onclustertesting/setup.go b/devex/cmd/onclustertesting/setup.go similarity index 99% rename from hack/cmd/onclustertesting/setup.go rename to devex/cmd/onclustertesting/setup.go index 7ed8457136..f1ff1afc64 100644 --- a/hack/cmd/onclustertesting/setup.go +++ b/devex/cmd/onclustertesting/setup.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "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" "github.com/spf13/cobra" diff --git a/hack/cmd/onclustertesting/teardown.go b/devex/cmd/onclustertesting/teardown.go similarity index 96% rename from hack/cmd/onclustertesting/teardown.go rename to devex/cmd/onclustertesting/teardown.go index d39c813ad5..5faf541856 100644 --- a/hack/cmd/onclustertesting/teardown.go +++ b/devex/cmd/onclustertesting/teardown.go @@ -3,7 +3,7 @@ package main import ( "context" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/utils" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" apierrs "k8s.io/apimachinery/pkg/api/errors" diff --git a/hack/cmd/run-on-all-nodes/README.md b/devex/cmd/run-on-all-nodes/README.md similarity index 100% rename from hack/cmd/run-on-all-nodes/README.md rename to devex/cmd/run-on-all-nodes/README.md diff --git a/hack/cmd/run-on-all-nodes/main.go b/devex/cmd/run-on-all-nodes/main.go similarity index 98% rename from hack/cmd/run-on-all-nodes/main.go rename to devex/cmd/run-on-all-nodes/main.go index 7f03406f0c..c84135871d 100644 --- a/hack/cmd/run-on-all-nodes/main.go +++ b/devex/cmd/run-on-all-nodes/main.go @@ -17,7 +17,7 @@ import ( "golang.org/x/sync/errgroup" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/utils" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" aggerrs "k8s.io/apimachinery/pkg/util/errors" diff --git a/hack/cmd/run-on-all-nodes/output.go b/devex/cmd/run-on-all-nodes/output.go similarity index 100% rename from hack/cmd/run-on-all-nodes/output.go rename to devex/cmd/run-on-all-nodes/output.go diff --git a/hack/cmd/wait-for-mcp/README.md b/devex/cmd/wait-for-mcp/README.md similarity index 100% rename from hack/cmd/wait-for-mcp/README.md rename to devex/cmd/wait-for-mcp/README.md diff --git a/hack/cmd/wait-for-mcp/main.go b/devex/cmd/wait-for-mcp/main.go similarity index 93% rename from hack/cmd/wait-for-mcp/main.go rename to devex/cmd/wait-for-mcp/main.go index 30967ee4dd..097dff982a 100644 --- a/hack/cmd/wait-for-mcp/main.go +++ b/devex/cmd/wait-for-mcp/main.go @@ -4,7 +4,7 @@ import ( "os" "time" - "github.com/openshift/machine-config-operator/hack/internal/pkg/rollout" + "github.com/openshift/machine-config-operator/devex/internal/pkg/rollout" "github.com/openshift/machine-config-operator/test/framework" "github.com/spf13/cobra" "k8s.io/component-base/cli" diff --git a/hack/internal/pkg/containers/containers.go b/devex/internal/pkg/containers/containers.go similarity index 100% rename from hack/internal/pkg/containers/containers.go rename to devex/internal/pkg/containers/containers.go diff --git a/hack/internal/pkg/containers/containers_test.go b/devex/internal/pkg/containers/containers_test.go similarity index 100% rename from hack/internal/pkg/containers/containers_test.go rename to devex/internal/pkg/containers/containers_test.go diff --git a/hack/internal/pkg/errors/exec.go b/devex/internal/pkg/errors/exec.go similarity index 100% rename from hack/internal/pkg/errors/exec.go rename to devex/internal/pkg/errors/exec.go diff --git a/devex/internal/pkg/errors/retryable.go b/devex/internal/pkg/errors/retryable.go new file mode 100644 index 0000000000..326d0c8d78 --- /dev/null +++ b/devex/internal/pkg/errors/retryable.go @@ -0,0 +1,76 @@ +package errors + +import "time" + +type Retryer interface { + Clear() + IsReached() bool + Current() interface{} + IsEmpty() bool +} + +type timeRetryer struct { + threshold time.Duration + start *time.Time +} + +func NewTimeRetryer(threshold time.Duration) Retryer { + return &timeRetryer{ + threshold: threshold, + } +} + +func (t *timeRetryer) IsEmpty() bool { + return t.start == nil +} + +func (t *timeRetryer) Current() interface{} { + return t.start +} + +func (t *timeRetryer) IsReached() bool { + if t.start == nil { + now := time.Now() + t.start = &now + } + + return time.Since(*t.start) >= t.threshold +} + +func (t *timeRetryer) Clear() { + t.start = nil +} + +type maxAttemptRetryer struct { + threshold int + start *int +} + +func NewMaxAttemptRetryer(threshold int) Retryer { + return &maxAttemptRetryer{ + threshold: threshold, + } +} + +func (m *maxAttemptRetryer) IsEmpty() bool { + return m.start == nil +} + +func (m *maxAttemptRetryer) Current() interface{} { + return m.start +} + +func (m *maxAttemptRetryer) IsReached() bool { + if m.start == nil { + start := 0 + m.start = &start + } + + *m.start++ + + return *m.start > m.threshold +} + +func (m *maxAttemptRetryer) Clear() { + m.start = nil +} diff --git a/devex/internal/pkg/errors/retryable_test.go b/devex/internal/pkg/errors/retryable_test.go new file mode 100644 index 0000000000..042837d5c6 --- /dev/null +++ b/devex/internal/pkg/errors/retryable_test.go @@ -0,0 +1,63 @@ +package errors + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestMaxCountRetryable(t *testing.T) { + t.Parallel() + + mar := NewMaxAttemptRetryer(10) + + assert.Nil(t, mar.Current()) + + innerTestLoop := func() { + for i := 0; i <= 10; i++ { + if i < 10 { + assert.False(t, mar.IsReached()) + } else { + assert.True(t, mar.IsReached()) + } + + current := mar.Current().(*int) + assert.Equal(t, i+1, *current) + } + } + + for i := 0; i <= 10; i++ { + innerTestLoop() + assert.NotNil(t, mar.Current()) + assert.False(t, mar.IsEmpty()) + mar.Clear() + assert.Nil(t, mar.Current()) + assert.True(t, mar.IsEmpty()) + } +} + +func TestTimeRetryable(t *testing.T) { + t.Parallel() + + tr := NewTimeRetryer(time.Millisecond) + + innerTestLoop := func() { + for i := 0; i <= 10; i++ { + assert.False(t, tr.IsReached()) + assert.NotNil(t, tr.Current()) + assert.False(t, tr.IsEmpty()) + } + } + + for i := 0; i <= 10; i++ { + innerTestLoop() + time.Sleep(time.Millisecond) + assert.True(t, tr.IsReached()) + assert.NotNil(t, tr.Current()) + assert.False(t, tr.IsEmpty()) + tr.Clear() + assert.Nil(t, tr.Current()) + assert.True(t, tr.IsEmpty()) + } +} diff --git a/hack/internal/pkg/releasecontroller/releasecontroller.go b/devex/internal/pkg/releasecontroller/releasecontroller.go similarity index 100% rename from hack/internal/pkg/releasecontroller/releasecontroller.go rename to devex/internal/pkg/releasecontroller/releasecontroller.go diff --git a/hack/internal/pkg/releasecontroller/releasecontrollertypes.go b/devex/internal/pkg/releasecontroller/releasecontrollertypes.go similarity index 100% rename from hack/internal/pkg/releasecontroller/releasecontrollertypes.go rename to devex/internal/pkg/releasecontroller/releasecontrollertypes.go diff --git a/hack/internal/pkg/releasecontroller/releaseinfo.go b/devex/internal/pkg/releasecontroller/releaseinfo.go similarity index 100% rename from hack/internal/pkg/releasecontroller/releaseinfo.go rename to devex/internal/pkg/releasecontroller/releaseinfo.go diff --git a/hack/internal/pkg/rollout/componentstatus.go b/devex/internal/pkg/rollout/componentstatus.go similarity index 100% rename from hack/internal/pkg/rollout/componentstatus.go rename to devex/internal/pkg/rollout/componentstatus.go diff --git a/hack/internal/pkg/rollout/external.go b/devex/internal/pkg/rollout/external.go similarity index 96% rename from hack/internal/pkg/rollout/external.go rename to devex/internal/pkg/rollout/external.go index b1dba4a4b5..86302d5cbf 100644 --- a/hack/internal/pkg/rollout/external.go +++ b/devex/internal/pkg/rollout/external.go @@ -6,8 +6,8 @@ import ( "os/exec" routeClient "github.com/openshift/client-go/route/clientset/versioned" - "github.com/openshift/machine-config-operator/hack/internal/pkg/errors" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + "github.com/openshift/machine-config-operator/devex/internal/pkg/errors" + "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" apierrs "k8s.io/apimachinery/pkg/api/errors" diff --git a/hack/internal/pkg/rollout/machineconfigpool.go b/devex/internal/pkg/rollout/machineconfigpool.go similarity index 65% rename from hack/internal/pkg/rollout/machineconfigpool.go rename to devex/internal/pkg/rollout/machineconfigpool.go index aae5511af6..bff145d60a 100644 --- a/hack/internal/pkg/rollout/machineconfigpool.go +++ b/devex/internal/pkg/rollout/machineconfigpool.go @@ -2,12 +2,15 @@ package rollout import ( "context" + "errors" "fmt" + "strings" "time" mcfgv1 "github.com/openshift/api/machineconfiguration/v1" mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1" - "github.com/openshift/machine-config-operator/hack/internal/pkg/utils" + 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" daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants" "github.com/openshift/machine-config-operator/test/framework" @@ -21,6 +24,7 @@ import ( ) var pollInterval = time.Second +var retryableErrThreshold = time.Minute func WaitForMachineConfigPoolsToComplete(cs *framework.ClientSet, poolNames []string, timeout time.Duration) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) @@ -97,6 +101,20 @@ func WaitForAllMachineConfigPoolsToComplete(cs *framework.ClientSet, timeout tim return err } +// Waits for the MachineConfigPool to complete. This does not consider +// individual node state and does not provide progress output. +func WaitForOnlyMachineConfigPoolToComplete(cs *framework.ClientSet, poolName string, timeout time.Duration) error { + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + // Wait for the pool to begin updating. + if err := waitForMachineConfigPoolToStart(ctx, cs, poolName); err != nil { + return fmt.Errorf("pool %s did not start updating: %w", poolName, err) + } + + return waitForMachineConfigPoolToComplete(ctx, cs, poolName) +} + func WaitForMachineConfigPoolToComplete(cs *framework.ClientSet, poolName string, timeout time.Duration) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -121,12 +139,20 @@ func waitForMachineConfigPoolsToCompleteWithContext(ctx context.Context, cs *fra func waitForMachineConfigPoolToStart(ctx context.Context, cs *framework.ClientSet, poolName string) error { start := time.Now() + retryer := errhelpers.NewTimeRetryer(retryableErrThreshold) + return wait.PollUntilContextCancel(ctx, pollInterval, true, func(ctx context.Context) (bool, error) { mcp, err := cs.MachineConfigPools().Get(ctx, poolName, metav1.GetOptions{}) + + shouldContinue, err := handleQueryErr(err, retryer) if err != nil { return false, err } + if !shouldContinue { + return false, nil + } + if apihelpers.IsMachineConfigPoolConditionTrue(mcp.Status.Conditions, mcfgv1.MachineConfigPoolUpdating) { klog.Infof("MachineConfigPool %s began updating after %s", mcp.Name, time.Since(start)) return true, nil @@ -153,12 +179,30 @@ func waitForMachineConfigPoolAndNodesToComplete(ctx context.Context, cs *framewo func waitForMachineConfigPoolToComplete(ctx context.Context, cs *framework.ClientSet, poolName string) error { start := time.Now() + initial, err := cs.MachineConfigPools().Get(ctx, poolName, metav1.GetOptions{}) + if err != nil { + return err + } + + retryer := errhelpers.NewTimeRetryer(retryableErrThreshold) + return wait.PollUntilContextCancel(ctx, pollInterval, true, func(ctx context.Context) (bool, error) { mcp, err := cs.MachineConfigPools().Get(ctx, poolName, metav1.GetOptions{}) + + shouldContinue, err := handleQueryErr(err, retryer) if err != nil { return false, err } + if !shouldContinue { + return false, nil + } + + if hasMachineConfigPoolStatusChanged(initial, mcp) { + logMCPChange(initial, mcp, start) + initial = mcp + } + if apihelpers.IsMachineConfigPoolConditionTrue(mcp.Status.Conditions, mcfgv1.MachineConfigPoolUpdated) { klog.Infof("MachineConfigPool %s finished updating after %s", mcp.Name, time.Since(start)) return true, nil @@ -168,6 +212,88 @@ func waitForMachineConfigPoolToComplete(ctx context.Context, cs *framework.Clien }) } +// Determines if the API error is retryable and ensures we can only retry for a +// finite amount of time. If the error keeps occurring after the given +// threshold, it will return nil. Returns a boolean indicating whether to +// continue from the current point and an error in the event that it is either +// retryable or the threshold has been met. +func handleQueryErr(err error, retryer errhelpers.Retryer) (bool, error) { + if err == nil { + if !retryer.IsEmpty() { + // If error is nil when it was previously not nil, clear the retryer and + // continue. + klog.Infof("The transient error is no longer occurring") + retryer.Clear() + } + + // If no error was encountered, continue as usual. + return true, nil + } + + // If the error is not retryable, stop here. + if !isRetryableErr(err) { + return false, err + } + + // If the retryer is empty and we've encountered an error, log the error. + if retryer.IsEmpty() { + klog.Infof("An error has occurred, will retry for %s or until the error is no longer encountered", retryableErrThreshold) + klog.Warning(err) + } + + // This checks whether the retryer has reached the limit. If the retryer is + // empty, it will populate itself before retrying. + if retryer.IsReached() { + // If no change after our threshold, we stop here. + klog.Infof("Threshold %s reached", retryableErrThreshold) + klog.Warning(err) + return false, err + } + + // At this point, we have a retryable error and know that we can try again. + return false, nil +} + +// Logs the detected MachineConfigPool change. +func logMCPChange(initial, current *mcfgv1.MachineConfigPool, start time.Time) { + changes := []string{ + fmt.Sprintf("MachineConfigPool %s has changed:", initial.Name), + fmt.Sprintf("Degraded: %d -> %d,", initial.Status.DegradedMachineCount, current.Status.DegradedMachineCount), + fmt.Sprintf("Machines: %d -> %d,", initial.Status.MachineCount, current.Status.MachineCount), + fmt.Sprintf("Ready: %d -> %d,", initial.Status.ReadyMachineCount, current.Status.ReadyMachineCount), + fmt.Sprintf("Unavailable: %d -> %d,", initial.Status.UnavailableMachineCount, current.Status.UnavailableMachineCount), + fmt.Sprintf("Updated: %d -> %d", initial.Status.UpdatedMachineCount, current.Status.UpdatedMachineCount), + fmt.Sprintf("after %s", time.Since(start)), + } + + klog.Info(strings.Join(changes, " ")) +} + +// Determines if the MachineConfigPool status has changed by examining the various machine counts. +func hasMachineConfigPoolStatusChanged(initial, current *mcfgv1.MachineConfigPool) bool { + if initial.Status.DegradedMachineCount != current.Status.DegradedMachineCount { + return true + } + + if initial.Status.MachineCount != current.Status.MachineCount { + return true + } + + if initial.Status.ReadyMachineCount != current.Status.ReadyMachineCount { + return true + } + + if initial.Status.UnavailableMachineCount != current.Status.UnavailableMachineCount { + return true + } + + if initial.Status.UpdatedMachineCount != current.Status.UpdatedMachineCount { + return true + } + + return false +} + func waitForNodesToComplete(ctx context.Context, cs *framework.ClientSet, poolName string) error { doneNodes := sets.New[string]() nodesForPool := sets.New[string]() @@ -202,15 +328,22 @@ func waitForNodesToComplete(ctx context.Context, cs *framework.ClientSet, poolNa klog.Infof("No MachineOSConfig found, will only consider MachineConfigs") } + retryer := errhelpers.NewTimeRetryer(retryableErrThreshold) + return wait.PollUntilContextCancel(ctx, pollInterval, true, func(ctx context.Context) (bool, error) { nodes, err := cs.CoreV1Interface.Nodes().List(ctx, metav1.ListOptions{ LabelSelector: fmt.Sprintf("node-role.kubernetes.io/%s", poolName), }) + shouldContinue, err := handleQueryErr(err, retryer) if err != nil { return false, err } + if !shouldContinue { + return false, nil + } + for _, node := range nodes.Items { node := node @@ -246,6 +379,21 @@ func waitForNodesToComplete(ctx context.Context, cs *framework.ClientSet, poolNa }) } +// Determines if an error is retryable. Currently, that means whether the +// context has been canceled or the deadline has been exceeded. In either of +// those scenarios, we cannot retry. +func isRetryableErr(err error) bool { + if errors.Is(err, context.Canceled) { + return false + } + + if errors.Is(err, context.DeadlineExceeded) { + return false + } + + return true +} + func getMachineConfigPoolNames(ctx context.Context, cs *framework.ClientSet) ([]string, error) { pools, err := cs.MachineconfigurationV1Interface.MachineConfigPools().List(ctx, metav1.ListOptions{}) if err != nil { diff --git a/devex/internal/pkg/rollout/machineconfigpool_test.go b/devex/internal/pkg/rollout/machineconfigpool_test.go new file mode 100644 index 0000000000..46dbe8a091 --- /dev/null +++ b/devex/internal/pkg/rollout/machineconfigpool_test.go @@ -0,0 +1,74 @@ +package rollout + +import ( + "context" + "fmt" + "testing" + + errhelpers "github.com/openshift/machine-config-operator/devex/internal/pkg/errors" + "github.com/stretchr/testify/assert" +) + +func TestHandleQueryErr(t *testing.T) { + testCases := []struct { + name string + err error + errExpected bool + expected bool + thresholdReached bool + }{ + { + name: "no error", + errExpected: false, + expected: true, + }, + { + name: "retryable error - threshold not reached", + errExpected: false, + err: fmt.Errorf("retryable"), + expected: false, + }, + { + name: "retryable error - threshold reached", + errExpected: true, + err: fmt.Errorf("retryable"), + expected: false, + thresholdReached: true, + }, + { + name: "non-retryable error", + errExpected: true, + err: context.Canceled, + expected: false, + }, + { + name: "nil error clears threshold", + errExpected: false, + err: nil, + expected: true, + thresholdReached: true, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + retryer := errhelpers.NewMaxAttemptRetryer(1) + + if testCase.thresholdReached { + assert.True(t, retryer.IsEmpty()) + assert.False(t, retryer.IsReached()) + assert.False(t, retryer.IsEmpty()) + assert.True(t, retryer.IsReached()) + } + + shouldContinue, err := handleQueryErr(testCase.err, retryer) + if testCase.errExpected { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + + assert.Equal(t, testCase.expected, shouldContinue) + }) + } +} diff --git a/hack/internal/pkg/rollout/nodeimage.go b/devex/internal/pkg/rollout/nodeimage.go similarity index 100% rename from hack/internal/pkg/rollout/nodeimage.go rename to devex/internal/pkg/rollout/nodeimage.go diff --git a/hack/internal/pkg/rollout/rollout.go b/devex/internal/pkg/rollout/rollout.go similarity index 99% rename from hack/internal/pkg/rollout/rollout.go rename to devex/internal/pkg/rollout/rollout.go index 4a252120a2..382b4de080 100644 --- a/hack/internal/pkg/rollout/rollout.go +++ b/devex/internal/pkg/rollout/rollout.go @@ -8,7 +8,7 @@ import ( "golang.org/x/sync/errgroup" - "github.com/openshift/machine-config-operator/hack/internal/pkg/releasecontroller" + "github.com/openshift/machine-config-operator/devex/internal/pkg/releasecontroller" "github.com/openshift/machine-config-operator/test/framework" "k8s.io/client-go/util/retry" "k8s.io/klog/v2" diff --git a/hack/internal/pkg/utils/apiutils.go b/devex/internal/pkg/utils/apiutils.go similarity index 100% rename from hack/internal/pkg/utils/apiutils.go rename to devex/internal/pkg/utils/apiutils.go diff --git a/hack/internal/pkg/utils/clone.go b/devex/internal/pkg/utils/clone.go similarity index 100% rename from hack/internal/pkg/utils/clone.go rename to devex/internal/pkg/utils/clone.go diff --git a/hack/internal/pkg/utils/utils.go b/devex/internal/pkg/utils/utils.go similarity index 100% rename from hack/internal/pkg/utils/utils.go rename to devex/internal/pkg/utils/utils.go diff --git a/hack/cluster-push-prep.sh b/hack/cluster-push-prep.sh deleted file mode 100755 index eba362cf23..0000000000 --- a/hack/cluster-push-prep.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -# Scale the CVO down and set up podman with a secret ready to push -# to the machine-config-operator namespace. - -# Assumptions: You have set KUBECONFIG to point to your local cluster, -# and you have exposed the registry via e.g. -# https://github.com/openshift/installer/issues/411#issuecomment-445165262 - -set -xeuo pipefail - -oc -n openshift-cluster-version scale --replicas=0 deploy/cluster-version-operator -if ! oc get -n openshift-image-registry route/image-registry &>/dev/null; then - oc expose -n openshift-image-registry svc/image-registry -fi -oc patch -n openshift-image-registry route/image-registry -p '{"spec": {"tls": {"insecureEdgeTerminationPolicy": "Redirect", "termination": "reencrypt"}}}' -registry=$(oc get -n openshift-image-registry -o json route/image-registry | jq -r ".spec.host") -if ! curl -k --head https://"${registry}" >/dev/null; then - if ! grep -q "${registry}" /etc/hosts; then - set +x - echo "error: Failed to contact the registry" - echo "The problem may be DNS; you can e.g. add the registry to your /etc/hosts - as root run:" - echo " echo 127.0.0.1 ${registry} >> /etc/hosts" - exit 1 - fi -fi - -# And allow everything to pull from our namespace -oc -n openshift-machine-config-operator policy add-role-to-group registry-viewer system:anonymous diff --git a/hack/cluster-push.sh b/hack/cluster-push.sh deleted file mode 100755 index 437f07f925..0000000000 --- a/hack/cluster-push.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bash - -# Build the MCO image and push it to the cluster registry, -# then directly patch the deployments/daemonsets to use that image. -# This is generally faster than building a new release image and -# upgrading to it, but also consequently doesn't work the same way as production -# upgrades work. -# -# To use this, you must first run `cluster-push-prep.sh` (once) for your cluster. -# -# Assumptions: You have set KUBECONFIG to point to your cluster. - -set -xeuo pipefail - -do_build=1 -if [ "${1:-}" = "-n" ]; then - do_build=0 -fi - -registry=$(oc get -n openshift-image-registry -o json route/image-registry | jq -r ".spec.host") -curl -k --head https://"${registry}" >/dev/null - -imgname=machine-config-operator -LOCAL_IMGNAME=localhost/${imgname}:latest -REMOTE_IMGNAME=openshift-machine-config-operator/${imgname} -if [ "${do_build}" = 1 ]; then - ./hack/build-image -fi -builder_secretid=$(oc get -n openshift-machine-config-operator secret | egrep '^builder-token-'| head -1 | cut -f 1 -d ' ') -secret="$(oc get -n openshift-machine-config-operator -o json secret/${builder_secretid} | jq -r '.data.token' | base64 -d)" - -if [[ "${podman:-}" =~ "docker" ]]; then - imgstorage="docker-daemon:" -else - imgstorage="containers-storage:" -fi -skopeo copy --dest-tls-verify=false --dest-creds unused:${secret} "${imgstorage}${LOCAL_IMGNAME}" "docker://${registry}/${REMOTE_IMGNAME}" - -digest=$(skopeo inspect --creds unused:${secret} --tls-verify=false docker://${registry}/${REMOTE_IMGNAME} | jq -r .Digest) -imageid=${REMOTE_IMGNAME}@${digest} - -oc project openshift-machine-config-operator - -IN_CLUSTER_NAME=image-registry.openshift-image-registry.svc:5000/${imageid} - -# Scale down the operator now to avoid it racing with our update. -oc scale --replicas=0 deploy/machine-config-operator - -# Patch the images.json -tmpf=$(mktemp) -oc get -o json configmap/machine-config-operator-images > ${tmpf} -outf=$(mktemp) -python3 > ${outf} <${patch} < /dev/null && pwd ) - -# shellcheck disable=SC1091 -source "$SCRIPT_DIR/lib" - -copy_mcd_to_disk() { - pod="$1" - - oc debug \ - -n "$MCO_NAMESPACE" \ - -c "$MCD_CONTAINER_NAME" \ - --one-container=true \ - "pod/$pod" -- cp -v /usr/bin/machine-config-daemon "$ROOTFS_MCD_PATH" -} - -main() { - # Disable the cluster version operator - # --replicas 1 out-of-the-box - oc scale --replicas 0 -n openshift-cluster-version deployments/cluster-version-operator - - # Disable the MCO - # --replicas 1 out-of-the-box - oc scale --replicas 0 -n "$MCO_NAMESPACE" deployments/machine-config-operator - - # Copy the MCD from the container to rootfs first to avoid startup issues - echo "Copy MCD from container to /rootfs" - mcd_pods="$(oc get pods -n "$MCO_NAMESPACE" -l 'k8s-app=machine-config-daemon' -o go-template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')" - for pod in $mcd_pods; do - copy_mcd_to_disk "$pod" & - done - - echo "Waiting for copies to finish..." - wait - echo "Done" - - # Now we modify the MCD daemonset to copy the MCD binary from rootfs and run it - # Note: This was originally done with a read, however read exits with code 1. - patch="$(/bin/cat <<- EOM -spec: - template: - spec: - containers: - - args: - - -c - - "sha256sum $ROOTFS_MCD_PATH && cp $ROOTFS_MCD_PATH /usr/local/bin/machine-config-daemon && /usr/local/bin/machine-config-daemon start -v 4" - command: ["/bin/bash"] - name: machine-config-daemon -EOM -)" - - echo "Modifying the MCD daemonset" - - # Apply the modifications - oc patch \ - daemonset/machine-config-daemon \ - -n "$MCO_NAMESPACE" \ - --patch="$patch" - - # Wait for the updated daemonset to roll out - oc rollout status -n "$MCO_NAMESPACE" -w "$MCD_DAEMONSET" -} - -can_run && main diff --git a/hack/push-image.sh b/hack/push-image.sh deleted file mode 100755 index 0188cd30a1..0000000000 --- a/hack/push-image.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -REPO=${REPO:-"openshift"} - -# Push mco image to REPO requested -exec podman push "localhost/machine-config-operator:latest" "${REPO}/origin-machine-config-operator:latest" diff --git a/hack/push-to-mcd-pods.sh b/hack/push-to-mcd-pods.sh deleted file mode 100755 index ebe703399d..0000000000 --- a/hack/push-to-mcd-pods.sh +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env bash - -target_mcd_pod="$1" - -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -# shellcheck disable=SC1091 -source "$SCRIPT_DIR/lib" - -copy_binary() { - local -r pod="$1" - local -r bin_path="$2" - - echo "Copying to $pod..." - oc cp -n "$MCO_NAMESPACE" -c "$MCD_CONTAINER_NAME" "$bin_path" "$pod:$ROOTFS_MCD_PATH" -} - -push_binary_to_pod() { - local -r pod="$1" - local -r bin_path="$2" - - local -r local_bin_sha256sum="$(sha256sum "$bin_path" | awk '{print $1;}')" - - # Check if we have the file on the pod in question - oc rsh -n "$MCO_NAMESPACE" -c "$MCD_CONTAINER_NAME" "pod/$pod" sha256sum "$ROOTFS_MCD_PATH" - local -r has_file_retval="$?" - - # We don't have the file, so lets copy it - if [ "$has_file_retval" -ne 0 ]; then - echo "Binary not found on $pod" - copy_binary "$pod" "$bin_path" - return - fi - - local -r remote_bin_sha256sum="$(oc rsh -n "$MCO_NAMESPACE" -c "$MCD_CONTAINER_NAME" "pod/$pod" sha256sum "$ROOTFS_MCD_PATH" | awk '{print $1;}')" - - if [[ "$local_bin_sha256sum" == "$remote_bin_sha256sum" ]]; then - echo "Skipping copy to $pod, binary $ROOTFS_MCD_PATH with equal checksum found: $local_bin_sha256sum" - return - fi - - echo "Local: $local_bin_sha256sum, Remote ($pod): $remote_bin_sha256sum" - copy_binary "$pod" "$bin_path" "$ROOTFS_MCD_PATH" -} - -push_binary_to_all_pods() { - local -r bin_path="$1" - - # Get our target MCD pods - echo "Getting MCD pods" - mcd_pods="$(oc get pods -n "$MCO_NAMESPACE" -l 'k8s-app=machine-config-daemon' -o go-template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')" - - # Concurrently copy the built binary to all MCD pods for speed. - for pod in $mcd_pods; do - push_binary_to_pod "$pod" "$bin_path" & - done - - # Wait for all the copy jobs to complete since we don't block for each one. - wait - - # Restart the MCD pods - oc rollout restart -n "$MCO_NAMESPACE" "$MCD_DAEMONSET" -} - -main() { - # Heterogeneous clusters are targeted for OCP 4.11, so this will need to change eventually. - # - # Ideas: - # - Get all individual arches and build for each of those concurrently. - # - Get a list of MCD pods on nodes and get the arch for each of the nodes just before copying. - - # Gets the architecture and operating system of the first node in the list, e.g., amd64\tlinux - local -r node_info="$(oc get nodes -o go-template='{{(index .items 0).status.nodeInfo.architecture}}{{"\t"}}{{(index .items 0).status.nodeInfo.operatingSystem}}')" - local -r cluster_arch="$(echo "$node_info" | cut -f1)" - - # Not really needed, but lets not make assumptions :) - local -r cluster_os="$(echo "$node_info" | cut -f2)" - - echo "Detected cluster arch / OS: $cluster_arch/$cluster_os" - - echo "Building MCD binary..." - # Need to set both GOOS / GOARCH on Mac otherwise the built binaries will be - # compiled for a Darwin target instead. - # - # Set WHAT to only build the MCD since that's the only component we're - # interested in at this time. - GOOS="$cluster_os" GOARCH="$cluster_arch" WHAT=machine-config-daemon "$SCRIPT_DIR/build-go.sh" - compile_retval="$?" - if [ $compile_retval -ne 0 ]; then - echo "Compilation failed!" - return $compile_retval - fi - - local -r bin_path="./_output/$cluster_os/$cluster_arch/machine-config-daemon" - - # Get the hash of our MCD binary; useful to compare to the startup value in the MCD pod logs - sha256sum "$bin_path" - - if [ -z "$target_mcd_pod" ]; then - # We're not targeting a specific pod, so push the binary to all MCD pods - echo "Will copy to all MCD pods..." - push_binary_to_all_pods "$bin_path" - else - # We're targeting a specific pod, so only push the binary to that pod - echo "Pod $target_mcd_pod specified, will only copy to this pod..." - push_binary_to_pod "$target_mcd_pod" "$bin_path" - - # Delete the pod to force pod re-creation so the new binary will be used. - oc delete -n "$MCO_NAMESPACE" "pod/$target_mcd_pod" - fi - - # Wait for the MCD to finish restarting (not strictly required, but doesn't hurt) - echo "Waiting for MCD daemonsets to restart" - oc rollout status -w -n "$MCO_NAMESPACE" "$MCD_DAEMONSET" - - echo "Current MCD Pods:" - "$SCRIPT_DIR/get-mcd-nodes.py" -} - -can_run && main diff --git a/hack/test-unit.sh b/hack/test-unit.sh index d89d3499dd..a15bd37109 100755 --- a/hack/test-unit.sh +++ b/hack/test-unit.sh @@ -17,7 +17,7 @@ COVERAGE_REPORT="mco-unit-test-coverage.out" function run_tests() { test_opts=("$@") - CGO_ENABLED=0 go test "${test_opts[@]}" -tags="$GOTAGS" './hack/...' './cmd/...' './pkg/...' './lib/...' './test/helpers/...' | ./hack/test-with-junit.sh "$MAKEFILE_TARGET" + CGO_ENABLED=0 go test "${test_opts[@]}" -tags="$GOTAGS" './devex/...' './cmd/...' './pkg/...' './lib/...' './test/helpers/...' | ./hack/test-with-junit.sh "$MAKEFILE_TARGET" } function run_tests_with_coverage() {