Skip to content

Commit

Permalink
Merge pull request #4110 from cheesesashimi/zzlotnik/fix-e2e-gcp-op-l…
Browse files Browse the repository at this point in the history
…ayering-job

OCPBUGS-26605: use machine client instead of oc for teardown
  • Loading branch information
openshift-merge-bot[bot] committed Jan 15, 2024
2 parents 81b767c + 66004cd commit 1fe4220
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/e2e-layering/onclusterbuild_test.go
Expand Up @@ -100,7 +100,7 @@ func TestOnClusterBuildRollsOutImage(t *testing.T) {
cs := framework.NewClientSet("")
node := helpers.GetRandomNode(t, cs, "worker")
t.Cleanup(makeIdempotentAndRegister(t, func() {
helpers.DeleteNodeAndMachine(t, node)
helpers.DeleteNodeAndMachine(t, cs, node)
}))
helpers.LabelNode(t, cs, node, helpers.MCPNameToRole(layeredMCPName))
helpers.WaitForNodeImageChange(t, cs, node, imagePullspec)
Expand Down
8 changes: 8 additions & 0 deletions test/framework/clientset.go
Expand Up @@ -27,6 +27,12 @@ type ClientSet struct {
clientbuildv1.BuildV1Interface
clientimagev1.ImageV1Interface
kubeconfig string
config *rest.Config
}

// Allows the instantiation of additional clients with the same config.
func (cs *ClientSet) GetRestConfig() *rest.Config {
return cs.config
}

func (cs *ClientSet) GetKubeconfig() (string, error) {
Expand Down Expand Up @@ -59,6 +65,7 @@ func NewClientSet(kubeconfig string) *ClientSet {

cs := NewClientSetFromConfig(config)
cs.kubeconfig = kubeconfig
cs.config = config
return cs
}

Expand All @@ -73,5 +80,6 @@ func NewClientSetFromConfig(config *rest.Config) *ClientSet {
OperatorV1alpha1Interface: clientoperatorsv1alpha1.NewForConfigOrDie(config),
BuildV1Interface: clientbuildv1.NewForConfigOrDie(config),
ImageV1Interface: clientimagev1.NewForConfigOrDie(config),
config: config,
}
}
18 changes: 14 additions & 4 deletions test/helpers/utils.go
Expand Up @@ -21,6 +21,7 @@ import (
ign3types "github.com/coreos/ignition/v2/config/v3_4/types"
"github.com/davecgh/go-spew/spew"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
machineClientv1beta1 "github.com/openshift/client-go/machine/clientset/versioned/typed/machine/v1beta1"
"github.com/openshift/machine-config-operator/pkg/apihelpers"
"github.com/openshift/machine-config-operator/pkg/daemon/constants"
"github.com/openshift/machine-config-operator/pkg/daemon/osrelease"
Expand Down Expand Up @@ -1086,14 +1087,23 @@ func dumpPool(pool *mcfgv1.MachineConfigPool, silentNil bool) string {
// the Machine API will provision a replacement node. For example, the
// e2e-layering tests cannot cleanly undo layering at this time, so we destroy
// the node / machine.
func DeleteNodeAndMachine(t *testing.T, node corev1.Node) {
func DeleteNodeAndMachine(t *testing.T, cs *framework.ClientSet, node corev1.Node) {
machineAPINamespace := "openshift-machine-api"
machineID := strings.ReplaceAll(node.Annotations["machine.openshift.io/machine"], machineAPINamespace+"/", "")

deleteMachineCmd := exec.Command("oc", "delete", "--wait=false", fmt.Sprintf("machine/%s", machineID), "-n", machineAPINamespace)
ctx := context.Background()

deleteNodeCmd := exec.Command("oc", "delete", "--wait=false", fmt.Sprintf("node/%s", node.Name))
machineClient := machineClientv1beta1.NewForConfigOrDie(cs.GetRestConfig())

t.Logf("Deleting machine %s / node %s", machineID, node.Name)
require.NoError(t, aggerrs.AggregateGoroutines(deleteMachineCmd.Run, deleteNodeCmd.Run))

delErr := aggerrs.AggregateGoroutines(
func() error {
return machineClient.Machines(machineAPINamespace).Delete(ctx, machineID, metav1.DeleteOptions{})
},
func() error {
return cs.CoreV1Interface.Nodes().Delete(ctx, node.Name, metav1.DeleteOptions{})
})

require.NoError(t, delErr)
}

0 comments on commit 1fe4220

Please sign in to comment.