From 8b17be5313b1aeb085b553ce33943278453e688c Mon Sep 17 00:00:00 2001 From: Sergio Regidor Date: Fri, 28 Nov 2025 12:03:46 +0000 Subject: [PATCH] MCO-1999: align extended test code with private repo. Pointers and permissions in lists --- test/extended-priv/configmap.go | 12 +++--- test/extended-priv/controlplanemachineset.go | 16 ++++---- test/extended-priv/events.go | 35 ++++++++--------- .../generic_behaviour_validation.go | 14 +++---- test/extended-priv/machine.go | 10 ++--- test/extended-priv/machineconfigpool.go | 38 +++++++++---------- test/extended-priv/machineosbuild.go | 8 ++-- test/extended-priv/machineosconfig.go | 14 +++---- test/extended-priv/machineset.go | 8 ++-- test/extended-priv/mco.go | 2 +- .../mco_controlplanemachineset.go | 2 +- test/extended-priv/mco_ocb.go | 2 +- test/extended-priv/mco_password.go | 4 +- test/extended-priv/node.go | 26 ++++++------- test/extended-priv/remotefile.go | 4 +- test/extended-priv/resource.go | 4 +- test/extended-priv/util.go | 8 ++-- 17 files changed, 104 insertions(+), 103 deletions(-) diff --git a/test/extended-priv/configmap.go b/test/extended-priv/configmap.go index 187f28f446..13b4eee38a 100644 --- a/test/extended-priv/configmap.go +++ b/test/extended-priv/configmap.go @@ -71,24 +71,24 @@ func (cm *ConfigMap) GetDataValueOrFail(key string) string { return value } -// GetAll returns a []ConfigMap list with all existing pinnedimageset sorted by creation timestamp -func (cml *ConfigMapList) GetAll() ([]ConfigMap, error) { +// GetAll returns a []*ConfigMap list with all existing pinnedimageset sorted by creation timestamp +func (cml *ConfigMapList) GetAll() ([]*ConfigMap, error) { cml.ResourceList.SortByTimestamp() allResources, err := cml.ResourceList.GetAll() if err != nil { return nil, err } - all := make([]ConfigMap, 0, len(allResources)) + all := make([]*ConfigMap, 0, len(allResources)) for _, res := range allResources { - all = append(all, *NewConfigMap(cml.oc, res.namespace, res.name)) + all = append(all, NewConfigMap(cml.oc, res.namespace, res.name)) } return all, nil } -// GetAllOrFail returns a []ConfigMap list with all existing pinnedimageset sorted by creation time, if any error happens it fails the test -func (cml *ConfigMapList) GetAllOrFail() []ConfigMap { +// GetAllOrFail returns a []*ConfigMap list with all existing pinnedimageset sorted by creation time, if any error happens it fails the test +func (cml *ConfigMapList) GetAllOrFail() []*ConfigMap { all, err := cml.GetAll() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing ConfigMap in the cluster") return all diff --git a/test/extended-priv/controlplanemachineset.go b/test/extended-priv/controlplanemachineset.go index 29dec92d75..82e919359b 100644 --- a/test/extended-priv/controlplanemachineset.go +++ b/test/extended-priv/controlplanemachineset.go @@ -263,7 +263,7 @@ func (cpms ControlPlaneMachineSet) SetUserDataSecret(userDataSecretName string) } // GetMachines returns a slice with the machines created for this ControlPlaneMachineSet -func (cpms ControlPlaneMachineSet) GetMachines() ([]Machine, error) { +func (cpms ControlPlaneMachineSet) GetMachines() ([]*Machine, error) { ml := NewMachineList(cpms.oc, cpms.GetNamespace()) ml.ByLabel("machine.openshift.io/cluster-api-machine-role=master") ml.ByLabel("machine.openshift.io/cluster-api-machine-type=master") @@ -272,7 +272,7 @@ func (cpms ControlPlaneMachineSet) GetMachines() ([]Machine, error) { } // GetMachinesOrFail get machines from ControlPlaneMachineSet or fail the test if any error occurred -func (cpms ControlPlaneMachineSet) GetMachinesOrFail() []Machine { +func (cpms ControlPlaneMachineSet) GetMachinesOrFail() []*Machine { ml, err := cpms.GetMachines() o.Expect(err).NotTo(o.HaveOccurred(), "Get machines of ControlPlaneMachineSet %s failed", cpms.GetName()) return ml @@ -304,23 +304,23 @@ func (cpms ControlPlaneMachineSet) GetNodesOrFail() []*Node { return nodes } -// GetAll returns a []ControlPlaneMachineSet list with all existing ControlPlaneMachineSets -func (cpmsl *ControlPlaneMachineSetList) GetAll() ([]ControlPlaneMachineSet, error) { +// GetAll returns a []*ControlPlaneMachineSet list with all existing ControlPlaneMachineSets +func (cpmsl *ControlPlaneMachineSetList) GetAll() ([]*ControlPlaneMachineSet, error) { allCPMSResources, err := cpmsl.ResourceList.GetAll() if err != nil { return nil, err } - allCPMS := make([]ControlPlaneMachineSet, 0, len(allCPMSResources)) + allCPMS := make([]*ControlPlaneMachineSet, 0, len(allCPMSResources)) for _, cpmsRes := range allCPMSResources { - allCPMS = append(allCPMS, *NewControlPlaneMachineSet(cpmsl.oc, cpmsRes.GetNamespace(), cpmsRes.GetName())) + allCPMS = append(allCPMS, NewControlPlaneMachineSet(cpmsl.oc, cpmsRes.GetNamespace(), cpmsRes.GetName())) } return allCPMS, nil } -// GetAllOrFail returns a []ControlPlaneMachineSet list with all existing ControlPlaneMachineSets and fail the test if it is not possible -func (cpmsl *ControlPlaneMachineSetList) GetAllOrFail() []ControlPlaneMachineSet { +// GetAllOrFail returns a []*ControlPlaneMachineSet list with all existing ControlPlaneMachineSets and fail the test if it is not possible +func (cpmsl *ControlPlaneMachineSetList) GetAllOrFail() []*ControlPlaneMachineSet { allCpms, err := cpmsl.GetAll() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing ControlPlaneMachineSets") diff --git a/test/extended-priv/events.go b/test/extended-priv/events.go index ea1a18b4c4..1ccad1b4ab 100644 --- a/test/extended-priv/events.go +++ b/test/extended-priv/events.go @@ -64,18 +64,18 @@ func NewEventList(oc *exutil.CLI, namespace string) *EventList { return &EventList{*NewNamespacedResourceList(oc, "Event", namespace)} } -// GetAll returns a []Event list with all existing events sorted by last occurrence +// GetAll returns a []*Event list with all existing events sorted by last occurrence // the first element will be the most recent one -func (el *EventList) GetAll() ([]Event, error) { +func (el *EventList) GetAll() ([]*Event, error) { el.SortByLastTimestamp() allEventResources, err := el.ResourceList.GetAll() if err != nil { return nil, err } - allEvents := make([]Event, 0, len(allEventResources)) + allEvents := make([]*Event, 0, len(allEventResources)) for _, eventRes := range allEventResources { - allEvents = append(allEvents, *NewEvent(el.oc, eventRes.namespace, eventRes.name)) + allEvents = append(allEvents, NewEvent(el.oc, eventRes.namespace, eventRes.name)) } // We want the first element to be the more recent allEvents = reverseEventsList(allEvents) @@ -100,11 +100,11 @@ func (el *EventList) GetLatest() (*Event, error) { return nil, nil } - return &(allEvents[0]), nil + return allEvents[0], nil } // GetAllEventsSinceEvent returns all events that occurred since a given event (not included) -func (el *EventList) GetAllEventsSinceEvent(sinceEvent *Event) ([]Event, error) { +func (el *EventList) GetAllEventsSinceEvent(sinceEvent *Event) ([]*Event, error) { allEvents, lerr := el.GetAll() if lerr != nil { logger.Errorf("Error getting events %s", lerr) @@ -115,7 +115,7 @@ func (el *EventList) GetAllEventsSinceEvent(sinceEvent *Event) ([]Event, error) return allEvents, nil } - returnEvents := []Event{} + returnEvents := []*Event{} for _, event := range allEvents { if event.name == sinceEvent.name { break @@ -127,7 +127,7 @@ func (el *EventList) GetAllEventsSinceEvent(sinceEvent *Event) ([]Event, error) } // GetAllSince return a list of the events that happened since the provided duration -func (el *EventList) GetAllSince(since time.Time) ([]Event, error) { +func (el *EventList) GetAllSince(since time.Time) ([]*Event, error) { // Remove log noise el.oc.NotShowInfo() defer el.oc.SetShowInfo() @@ -138,7 +138,7 @@ func (el *EventList) GetAllSince(since time.Time) ([]Event, error) { return nil, lerr } - returnEvents := []Event{} + returnEvents := []*Event{} for _, loopEvent := range allEvents { event := loopEvent // this is to make sure that we execute defer in all events, and not only in the last one // Remove log noise @@ -162,7 +162,7 @@ func (el *EventList) GetAllSince(since time.Time) ([]Event, error) { } // from https://github.com/golang/go/wiki/SliceTricks#reversing -func reverseEventsList(a []Event) []Event { +func reverseEventsList(a []*Event) []*Event { for i := len(a)/2 - 1; i >= 0; i-- { opp := len(a) - 1 - i @@ -202,14 +202,15 @@ type haveEventsSequenceMatcher struct { func (matcher *haveEventsSequenceMatcher) Match(actual interface{}) (success bool, err error) { logger.Infof("Start verifying events sequence: %s", matcher.sequence) - events, ok := actual.([]Event) + events, ok := actual.([]*Event) if !ok { - return false, fmt.Errorf("HaveSequence matcher expects a slice of Events in test case %v", g.CurrentSpecReport().FullText()) + return false, fmt.Errorf("HaveSequence matcher expects a slice of *Event in test case %v", g.CurrentSpecReport().FullText()) } // To avoid too many "oc" executions we store the events information in a cached struct list with "lastTimestamp" and "reason" fields. tmpEvents := make([]tmpEvent, len(events)) - for index, event := range events { + for index, loopEvent := range events { + event := loopEvent // this is to make sure that we execute defer in all events, and not only in the last one event.oc.NotShowInfo() defer event.oc.SetShowInfo() @@ -258,14 +259,14 @@ func (matcher *haveEventsSequenceMatcher) Match(actual interface{}) (success boo func (matcher *haveEventsSequenceMatcher) FailureMessage(actual interface{}) (message string) { // The type was already validated in Match, we can safely ignore the error - events, _ := actual.([]Event) + events, _ := actual.([]*Event) var output strings.Builder if len(events) == 0 { output.WriteString("No events in the list\n") } else { - output.WriteString("Expecte events\n") + output.WriteString("Expect events\n") for _, event := range events { output.WriteString(fmt.Sprintf("- %s\n", event)) } @@ -277,10 +278,10 @@ func (matcher *haveEventsSequenceMatcher) FailureMessage(actual interface{}) (me func (matcher *haveEventsSequenceMatcher) NegatedFailureMessage(actual interface{}) (message string) { // The type was already validated in Match, we can safely ignore the error - events, _ := actual.([]Event) + events, _ := actual.([]*Event) var output strings.Builder - output.WriteString("Expecte events\n") + output.WriteString("Expect events\n") for _, event := range events { output.WriteString(fmt.Sprintf("- %s\n", event)) } diff --git a/test/extended-priv/generic_behaviour_validation.go b/test/extended-priv/generic_behaviour_validation.go index 53327fd29e..cc5b959092 100644 --- a/test/extended-priv/generic_behaviour_validation.go +++ b/test/extended-priv/generic_behaviour_validation.go @@ -11,7 +11,7 @@ import ( ) type Checker interface { - Check(checkedNodes ...Node) + Check(checkedNodes ...*Node) } type CommandOutputChecker struct { @@ -21,7 +21,7 @@ type CommandOutputChecker struct { Desc string } -func (cOutChecker CommandOutputChecker) Check(checkedNodes ...Node) { +func (cOutChecker CommandOutputChecker) Check(checkedNodes ...*Node) { msg := "Executing verification commands" if cOutChecker.Desc != "" { msg = cOutChecker.Desc @@ -47,7 +47,7 @@ type RemoteFileChecker struct { Desc string } -func (rfc RemoteFileChecker) Check(checkedNodes ...Node) { +func (rfc RemoteFileChecker) Check(checkedNodes ...*Node) { msg := fmt.Sprintf("Checking file: %s", rfc.FileFullPath) if rfc.Desc != "" { msg = rfc.Desc @@ -65,12 +65,12 @@ func (rfc RemoteFileChecker) Check(checkedNodes ...Node) { } // checkDrainAction checks that the drain action in the node is the expected one (drainSkipped) -func checkDrainAction(drainSkipped bool, node Node, controller *Controller) { +func checkDrainAction(drainSkipped bool, node *Node, controller *Controller) { checkDrainActionWithGomega(drainSkipped, node, controller, o.Default) } // checkDrainActionWithGomega checks that the drain action in the node is the expected one (drainSkipped). It accepts an extra Gomega parameter that allows the function to be used in the Eventually gomega matchers -func checkDrainActionWithGomega(drainExecuted bool, node Node, controller *Controller, gm o.Gomega) { +func checkDrainActionWithGomega(drainExecuted bool, node *Node, controller *Controller, gm o.Gomega) { var ( execDrainLogMsg = "initiating drain" ) @@ -97,12 +97,12 @@ func checkDrainActionWithGomega(drainExecuted bool, node Node, controller *Contr } // checkRebootAction checks that the reboot action in the node is the expected one (rebootSkipped) -func checkRebootAction(rebootExecuted bool, node Node, startTime time.Time) { +func checkRebootAction(rebootExecuted bool, node *Node, startTime time.Time) { checkRebootActionWithGomega(rebootExecuted, node, startTime, o.Default) } // checkRebootActionWithGomega checks that the reboot action in the node is the expected one (rebootSkipped). It accepts an extra Gomega parameter that allows the function to be used in the Eventually gomega matchers -func checkRebootActionWithGomega(rebootExecuted bool, node Node, startTime time.Time, gm o.Gomega) { +func checkRebootActionWithGomega(rebootExecuted bool, node *Node, startTime time.Time, gm o.Gomega) { if rebootExecuted { logger.Infof("Checking that node %s was rebooted", node.GetName()) gm.Expect(node.GetUptime()).Should(o.BeTemporally(">", startTime), diff --git a/test/extended-priv/machine.go b/test/extended-priv/machine.go index 404a219886..fcd0b50e8f 100644 --- a/test/extended-priv/machine.go +++ b/test/extended-priv/machine.go @@ -41,7 +41,7 @@ func (m Machine) GetNode() (*Node, error) { return nil, fmt.Errorf("No node linked to this Machine. Machine: %s", m.GetName()) } - return &(nodes[0]), nil + return nodes[0], nil } // GetNodeOrFail, call GetNode, fail the test if any error occurred @@ -75,16 +75,16 @@ func NewMachineList(oc *exutil.CLI, namespace string) *MachineList { return &MachineList{*NewNamespacedResourceList(oc, MachineFullName, namespace)} } -// GetAll returns a []Machine slice with all existing nodes -func (ml MachineList) GetAll() ([]Machine, error) { +// GetAll returns a []*Machine slice with all existing nodes +func (ml MachineList) GetAll() ([]*Machine, error) { allMResources, err := ml.ResourceList.GetAll() if err != nil { return nil, err } - allMs := make([]Machine, 0, len(allMResources)) + allMs := make([]*Machine, 0, len(allMResources)) for _, mRes := range allMResources { - allMs = append(allMs, *NewMachine(ml.oc, mRes.GetNamespace(), mRes.GetName())) + allMs = append(allMs, NewMachine(ml.oc, mRes.GetNamespace(), mRes.GetName())) } return allMs, nil diff --git a/test/extended-priv/machineconfigpool.go b/test/extended-priv/machineconfigpool.go index e54b410eb4..3e5013f8a8 100644 --- a/test/extended-priv/machineconfigpool.go +++ b/test/extended-priv/machineconfigpool.go @@ -304,7 +304,7 @@ func (mcp *MachineConfigPool) SetWaitingTimeForExtensionsChange() { } // getSelectedNodes returns a list with the nodes that match the .spec.nodeSelector.matchLabels criteria plus the provided extraLabels -func (mcp *MachineConfigPool) getSelectedNodes(extraLabels string) ([]Node, error) { +func (mcp *MachineConfigPool) getSelectedNodes(extraLabels string) ([]*Node, error) { mcp.oc.NotShowInfo() defer mcp.oc.SetShowInfo() @@ -331,7 +331,7 @@ func (mcp *MachineConfigPool) getSelectedNodes(extraLabels string) ([]Node, erro } // GetNodesByLabel returns a list with the nodes that belong to the machine config pool and contain the given labels -func (mcp *MachineConfigPool) GetNodesByLabel(labels string) ([]Node, error) { +func (mcp *MachineConfigPool) GetNodesByLabel(labels string) ([]*Node, error) { mcp.oc.NotShowInfo() defer mcp.oc.SetShowInfo() @@ -340,7 +340,7 @@ func (mcp *MachineConfigPool) GetNodesByLabel(labels string) ([]Node, error) { return nil, err } - returnNodes := []Node{} + returnNodes := []*Node{} for _, item := range nodes { node := item @@ -358,24 +358,24 @@ func (mcp *MachineConfigPool) GetNodesByLabel(labels string) ([]Node, error) { } // GetNodes returns a list with the nodes that belong to the machine config pool, by default, windows nodes will be excluded -func (mcp *MachineConfigPool) GetNodes() ([]Node, error) { +func (mcp *MachineConfigPool) GetNodes() ([]*Node, error) { return mcp.GetNodesByLabel("") } // GetNodesOrFail returns a list with the nodes that belong to the machine config pool and fail the test if any error happened -func (mcp *MachineConfigPool) GetNodesOrFail() []Node { +func (mcp *MachineConfigPool) GetNodesOrFail() []*Node { ns, err := mcp.GetNodes() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Cannot get the nodes in %s MCP", mcp.GetName()) return ns } // GetCoreOsNodes returns a list with the CoreOs nodes that belong to the machine config pool -func (mcp *MachineConfigPool) GetCoreOsNodes() ([]Node, error) { +func (mcp *MachineConfigPool) GetCoreOsNodes() ([]*Node, error) { return mcp.GetNodesByLabel("node.openshift.io/os_id=rhel") } // GetCoreOsNodesOrFail returns a list with the CoreOs nodes that belong to the machine config pool. If any error happens it fails the test. -func (mcp *MachineConfigPool) GetCoreOsNodesOrFail() []Node { +func (mcp *MachineConfigPool) GetCoreOsNodesOrFail() []*Node { ns, err := mcp.GetCoreOsNodes() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Cannot get the coreOS nodes in %s MCP", mcp.GetName()) return ns @@ -383,7 +383,7 @@ func (mcp *MachineConfigPool) GetCoreOsNodesOrFail() []Node { // GetSortedNodes returns a list with the nodes that belong to the machine config pool in the same order used to update them // when a configuration is applied -func (mcp *MachineConfigPool) GetSortedNodes() ([]Node, error) { +func (mcp *MachineConfigPool) GetSortedNodes() ([]*Node, error) { poolNodes, err := mcp.GetNodes() if err != nil { @@ -400,7 +400,7 @@ func (mcp *MachineConfigPool) GetSortedNodes() ([]Node, error) { // GetSortedNodesOrFail returns a list with the nodes that belong to the machine config pool in the same order used to update them // when a configuration is applied. If any error happens while getting the list, then the test is failed. -func (mcp *MachineConfigPool) GetSortedNodesOrFail() []Node { +func (mcp *MachineConfigPool) GetSortedNodesOrFail() []*Node { nodes, err := mcp.GetSortedNodes() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Cannot get the list of nodes that belong to '%s' MCP", mcp.GetName()) @@ -569,7 +569,7 @@ func GetCompactCompatiblePool(oc *exutil.CLI) *MachineConfigPool { var ( wMcp = NewMachineConfigPool(oc.AsAdmin(), MachineConfigPoolWorker) mMcp = NewMachineConfigPool(oc.AsAdmin(), MachineConfigPoolMaster) - mcpList = NewMachineConfigPoolList(oc) + mcpList = NewMachineConfigPoolList(oc.AsAdmin()) ) mcpList.PrintDebugCommand() @@ -586,7 +586,7 @@ func GetCompactCompatiblePool(oc *exutil.CLI) *MachineConfigPool { for _, mcp := range mcpList.GetAllOrFail() { if mcp.IsCustom() && !mcp.IsEmpty() { // All worker pools were moved to cutom pools logger.Infof("Worker pool is empty, but there is a custom pool with nodes. Proposing %s MCP for testing", mcp.GetName()) - return &mcp + return mcp } } @@ -700,27 +700,27 @@ func (mcp MachineConfigPool) GetMOSC() (*MachineOSConfig, error) { if len(moscs) == 0 { return nil, nil } - return &(moscs[0]), nil + return moscs[0], nil } -// GetAll returns a []MachineConfigPool list with all existing machine config pools sorted by creation time -func (mcpl *MachineConfigPoolList) GetAll() ([]MachineConfigPool, error) { +// GetAll returns a []*MachineConfigPool list with all existing machine config pools sorted by creation time +func (mcpl *MachineConfigPoolList) GetAll() ([]*MachineConfigPool, error) { mcpl.ResourceList.SortByTimestamp() allMCPResources, err := mcpl.ResourceList.GetAll() if err != nil { return nil, err } - allMCPs := make([]MachineConfigPool, 0, len(allMCPResources)) + allMCPs := make([]*MachineConfigPool, 0, len(allMCPResources)) for _, mcpRes := range allMCPResources { - allMCPs = append(allMCPs, *NewMachineConfigPool(mcpl.oc, mcpRes.name)) + allMCPs = append(allMCPs, NewMachineConfigPool(mcpl.oc, mcpRes.name)) } return allMCPs, nil } -// GetAllOrFail returns a []MachineConfigPool list with all existing machine config pools sorted by creation time, if any error happens it fails the test -func (mcpl *MachineConfigPoolList) GetAllOrFail() []MachineConfigPool { +// GetAllOrFail returns a []*MachineConfigPool list with all existing machine config pools sorted by creation time, if any error happens it fails the test +func (mcpl *MachineConfigPoolList) GetAllOrFail() []*MachineConfigPool { mcps, err := mcpl.GetAll() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing MCP in the cluster") return mcps @@ -766,7 +766,7 @@ func CreateCustomMCP(oc *exutil.CLI, name string, numNodes int) (*MachineConfigP } // CreateCustomMCPByNodes creates a new MCP containing the nodes provided in the "nodes" parameter -func CreateCustomMCPByNodes(oc *exutil.CLI, name string, nodes []Node) (*MachineConfigPool, error) { +func CreateCustomMCPByNodes(oc *exutil.CLI, name string, nodes []*Node) (*MachineConfigPool, error) { customMcp := NewMachineConfigPool(oc, name) err := NewMCOTemplate(oc, "custom-machine-config-pool.yaml").Create("-p", fmt.Sprintf("NAME=%s", name)) diff --git a/test/extended-priv/machineosbuild.go b/test/extended-priv/machineosbuild.go index 6820ea3585..917171cabc 100644 --- a/test/extended-priv/machineosbuild.go +++ b/test/extended-priv/machineosbuild.go @@ -68,17 +68,17 @@ func (mosb MachineOSBuild) GetJob() (*Job, error) { return NewJob(mosb.GetOC(), jobNamespace, jobName), nil } -// GetAll returns a []MachineOSBuild list with all existing pinnedimageset sorted by creation timestamp -func (mosbl *MachineOSBuildList) GetAll() ([]MachineOSBuild, error) { +// GetAll returns a []*MachineOSBuild list with all existing pinnedimageset sorted by creation timestamp +func (mosbl *MachineOSBuildList) GetAll() ([]*MachineOSBuild, error) { mosbl.ResourceList.SortByTimestamp() allResources, err := mosbl.ResourceList.GetAll() if err != nil { return nil, err } - all := make([]MachineOSBuild, 0, len(allResources)) + all := make([]*MachineOSBuild, 0, len(allResources)) for _, res := range allResources { - all = append(all, *NewMachineOSBuild(mosbl.oc, res.name)) + all = append(all, NewMachineOSBuild(mosbl.oc, res.name)) } return all, nil diff --git a/test/extended-priv/machineosconfig.go b/test/extended-priv/machineosconfig.go index 580cb6be59..0fe4068825 100644 --- a/test/extended-priv/machineosconfig.go +++ b/test/extended-priv/machineosconfig.go @@ -299,7 +299,7 @@ func (mosc MachineOSConfig) GetMachineConfigPool() (*MachineConfigPool, error) { } // GetMachineOSBuildList returns a list of all MOSB linked to this MOSC -func (mosc MachineOSConfig) GetMachineOSBuildList() ([]MachineOSBuild, error) { +func (mosc MachineOSConfig) GetMachineOSBuildList() ([]*MachineOSBuild, error) { mosbList := NewMachineOSBuildList(mosc.GetOC()) mosbList.SetItemsFilter(fmt.Sprintf(`?(@.spec.machineOSConfig.name=="%s")`, mosc.GetName())) return mosbList.GetAll() @@ -345,24 +345,24 @@ func (mosc MachineOSConfig) Rebuild() error { return mosc.Patch("json", `[{"op": "add", "path": "/metadata/annotations/machineconfiguration.openshift.io~1rebuild", "value":""}]`) } -// GetAll returns a []MachineOSConfig list with all existing pinnedimageset sorted by creation timestamp -func (moscl *MachineOSConfigList) GetAll() ([]MachineOSConfig, error) { +// GetAll returns a []*MachineOSConfig list with all existing pinnedimageset sorted by creation timestamp +func (moscl *MachineOSConfigList) GetAll() ([]*MachineOSConfig, error) { moscl.ResourceList.SortByTimestamp() allMOSCResources, err := moscl.ResourceList.GetAll() if err != nil { return nil, err } - allMOSCs := make([]MachineOSConfig, 0, len(allMOSCResources)) + allMOSCs := make([]*MachineOSConfig, 0, len(allMOSCResources)) for _, moscRes := range allMOSCResources { - allMOSCs = append(allMOSCs, *NewMachineOSConfig(moscl.oc, moscRes.name)) + allMOSCs = append(allMOSCs, NewMachineOSConfig(moscl.oc, moscRes.name)) } return allMOSCs, nil } -// GetAllOrFail returns a []MachineOSConfig list with all existing pinnedimageset sorted by creation time, if any error happens it fails the test -func (moscl *MachineOSConfigList) GetAllOrFail() []MachineOSConfig { +// GetAllOrFail returns a []*MachineOSConfig list with all existing pinnedimageset sorted by creation time, if any error happens it fails the test +func (moscl *MachineOSConfigList) GetAllOrFail() []*MachineOSConfig { moscs, err := moscl.GetAll() o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing MachineOSConfig in the cluster") return moscs diff --git a/test/extended-priv/machineset.go b/test/extended-priv/machineset.go index 9ff26b0dea..3fc4c781fa 100644 --- a/test/extended-priv/machineset.go +++ b/test/extended-priv/machineset.go @@ -29,16 +29,16 @@ func NewMachineSetList(oc *exutil.CLI, namespace string) *MachineSetList { return &MachineSetList{*NewNamespacedResourceList(oc, MachineSetFullName, namespace)} } -// GetAll returns a []MachineSet list with all existing MachineSets -func (msl *MachineSetList) GetAll() ([]MachineSet, error) { +// GetAll returns a []*MachineSet list with all existing MachineSets +func (msl *MachineSetList) GetAll() ([]*MachineSet, error) { allMachineSetResources, err := msl.ResourceList.GetAll() if err != nil { return nil, err } - allMachineSets := make([]MachineSet, 0, len(allMachineSetResources)) + allMachineSets := make([]*MachineSet, 0, len(allMachineSetResources)) for _, msRes := range allMachineSetResources { - allMachineSets = append(allMachineSets, *NewMachineSet(msl.oc, msRes.GetNamespace(), msRes.GetName())) + allMachineSets = append(allMachineSets, NewMachineSet(msl.oc, msRes.GetNamespace(), msRes.GetName())) } return allMachineSets, nil diff --git a/test/extended-priv/mco.go b/test/extended-priv/mco.go index 0f30517759..f1d76164bf 100644 --- a/test/extended-priv/mco.go +++ b/test/extended-priv/mco.go @@ -72,7 +72,7 @@ func checkDegraded(mcp *MachineConfigPool, expectedMessage, expectedReason, degr logger.Infof("OK!\n") } -func skipTestIfRHELVersion(node Node, operator, constraintVersion string) { +func skipTestIfRHELVersion(node *Node, operator, constraintVersion string) { actualVersion, err := node.GetRHELVersion() o.Expect(err).NotTo(o.HaveOccurred(), "Error getting RHEL version from node %s", node.GetName()) diff --git a/test/extended-priv/mco_controlplanemachineset.go b/test/extended-priv/mco_controlplanemachineset.go index cd41a02db8..b522fbc69b 100644 --- a/test/extended-priv/mco_controlplanemachineset.go +++ b/test/extended-priv/mco_controlplanemachineset.go @@ -16,7 +16,7 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/disruptive oc = exutil.NewCLI("mco-controlplanemachineset", exutil.KubeConfigPath()) // Common variables cpms *ControlPlaneMachineSet - machines []Machine + machines []*Machine machineConfiguration *MachineConfiguration ) diff --git a/test/extended-priv/mco_ocb.go b/test/extended-priv/mco_ocb.go index f14b74ff93..156dd33924 100644 --- a/test/extended-priv/mco_ocb.go +++ b/test/extended-priv/mco_ocb.go @@ -274,7 +274,7 @@ func testContainerFile(containerFiles []ContainerFile, imageNamespace string, mc } func SkipTestIfOCBIsEnabled(oc *exutil.CLI) { - moscl := NewMachineOSConfigList(oc) + moscl := NewMachineOSConfigList(oc.AsAdmin()) allMosc := moscl.GetAllOrFail() if len(allMosc) != 0 { moscl.PrintDebugCommand() diff --git a/test/extended-priv/mco_password.go b/test/extended-priv/mco_password.go index f0ecf74815..8e0849fcea 100644 --- a/test/extended-priv/mco_password.go +++ b/test/extended-priv/mco_password.go @@ -495,7 +495,7 @@ func GenerateSSHKeyPairOrFail() (privateKey, publicKey string) { return privKey, pubKey } -func checkSSHAccessInNode(node Node, user, privKey string) { +func checkSSHAccessInNode(node *Node, user, privKey string) { tmpPrivKeyPath := "/tmp/tmp-" + exutil.GetRandomString() remotePrivSSH := NewRemoteFile(node, tmpPrivKeyPath) defer func() { @@ -510,7 +510,7 @@ func checkSSHAccessInNode(node Node, user, privKey string) { o.Expect(err).NotTo(o.HaveOccurred(), "Error in the login process using ssh key in node %s:\n %s", node.GetName(), bresp) } -func checkAuthorizedKeyInNode(node Node, keys []string) { +func checkAuthorizedKeyInNode(node *Node, keys []string) { logger.Infof("Checking old file /home/core/.ssh/authorized_keys") rOldAuthorizedFile := NewRemoteFile(node, "/home/core/.ssh/authorized_keys") o.Expect(rOldAuthorizedFile.Fetch()).ShouldNot(o.Succeed(), diff --git a/test/extended-priv/node.go b/test/extended-priv/node.go index 85a0d1ed7b..6c2b01f5c7 100644 --- a/test/extended-priv/node.go +++ b/test/extended-priv/node.go @@ -399,7 +399,7 @@ func (n *Node) GetUptime() (time.Time, error) { } // GetEventsByReasonSince returns a list of all the events with the given reason that are related to this node since the provided date -func (n *Node) GetEventsByReasonSince(since time.Time, reason string) ([]Event, error) { +func (n *Node) GetEventsByReasonSince(since time.Time, reason string) ([]*Event, error) { eventList := NewEventList(n.oc, MachineConfigNamespace) eventList.ByFieldSelector(`reason=` + reason + `,involvedObject.name=` + n.GetName()) @@ -407,7 +407,7 @@ func (n *Node) GetEventsByReasonSince(since time.Time, reason string) ([]Event, } // GetAllEventsSince returns a list of all the events related to this node since the provided date -func (n *Node) GetAllEventsSince(since time.Time) ([]Event, error) { +func (n *Node) GetAllEventsSince(since time.Time) ([]*Event, error) { eventList := NewEventList(n.oc, MachineConfigNamespace) eventList.ByFieldSelector(`involvedObject.name=` + n.GetName()) @@ -415,7 +415,7 @@ func (n *Node) GetAllEventsSince(since time.Time) ([]Event, error) { } // GetAllEventsSinceEvent returns a list of all the events related to this node that occurred after the provided event -func (n *Node) GetAllEventsSinceEvent(since *Event) ([]Event, error) { +func (n *Node) GetAllEventsSinceEvent(since *Event) ([]*Event, error) { eventList := NewEventList(n.oc, MachineConfigNamespace) eventList.ByFieldSelector(`involvedObject.name=` + n.GetName()) @@ -433,7 +433,7 @@ func (n *Node) GetLatestEvent() (*Event, error) { // GetEvents retunrs all the events that happened in this node since IgnoreEventsBeforeNow() method was called. // // If IgnoreEventsBeforeNow() is not called, it returns all existing events for this node. -func (n *Node) GetEvents() ([]Event, error) { +func (n *Node) GetEvents() ([]*Event, error) { return n.GetAllEventsSince(n.eventCheckpoint) } @@ -518,7 +518,7 @@ func (n *Node) GetRHELVersion() (string, error) { // GetPool returns the only pool owning this node func (n *Node) GetPrimaryPool() (*MachineConfigPool, error) { - allMCPs, err := NewMachineConfigPoolList(n.oc).GetAll() + allMCPs, err := NewMachineConfigPoolList(n.oc.AsAdmin()).GetAll() if err != nil { return nil, err } @@ -541,7 +541,7 @@ func (n *Node) GetPrimaryPool() (*MachineConfigPool, error) { // - If the primary pool is nil (not set yet), we set the primary pool (either worker or custom); // - If the primary pool is not nil, we overwrite it only if the primary pool is a worker. if pool.IsMaster() || primaryPool == nil || primaryPool.IsWorker() { - primaryPool = &pool + primaryPool = pool } else if pool.IsCustom() && primaryPool != nil && primaryPool.IsCustom() { // Error condition: the node belongs to 2 custom pools return nil, fmt.Errorf("Forbidden configuration. The node %s belongs to 2 custom pools: %s and %s", @@ -579,29 +579,29 @@ func (n *Node) GetMachineConfigNode() *MachineConfigNode { return NewMachineConfigNode(n.oc.AsAdmin(), n.GetName()) } -// GetAll returns a []Node list with all existing nodes -func (nl *NodeList) GetAll() ([]Node, error) { +// GetAll returns a []*Node list with all existing nodes +func (nl *NodeList) GetAll() ([]*Node, error) { allNodeResources, err := nl.ResourceList.GetAll() if err != nil { return nil, err } - allNodes := make([]Node, 0, len(allNodeResources)) + allNodes := make([]*Node, 0, len(allNodeResources)) for _, nodeRes := range allNodeResources { - allNodes = append(allNodes, *NewNode(nl.oc, nodeRes.name)) + allNodes = append(allNodes, NewNode(nl.oc, nodeRes.name)) } return allNodes, nil } -// GetAllReady returns a []Node list with all ready nodes -func (nl *NodeList) GetAllReady() ([]Node, error) { +// GetAllReady returns a []*Node list with all ready nodes +func (nl *NodeList) GetAllReady() ([]*Node, error) { allNodes, err := nl.GetAll() if err != nil { return nil, err } - readyNodes := make([]Node, 0) + readyNodes := make([]*Node, 0) for _, node := range allNodes { if node.IsReady() { readyNodes = append(readyNodes, node) diff --git a/test/extended-priv/remotefile.go b/test/extended-priv/remotefile.go index 593d3e827c..fd8d5cd294 100644 --- a/test/extended-priv/remotefile.go +++ b/test/extended-priv/remotefile.go @@ -29,14 +29,14 @@ const ( // RemoteFile handles files located remotely in a node type RemoteFile struct { - node Node + node *Node fullPath string statData map[string]string content string } // NewRemoteFile creates a new instance of RemoteFile -func NewRemoteFile(node Node, fullPath string) *RemoteFile { +func NewRemoteFile(node *Node, fullPath string) *RemoteFile { return &RemoteFile{node: node, fullPath: fullPath} } diff --git a/test/extended-priv/resource.go b/test/extended-priv/resource.go index fcd6314892..5744ec810c 100644 --- a/test/extended-priv/resource.go +++ b/test/extended-priv/resource.go @@ -434,12 +434,12 @@ type ResourceList struct { // NewResourceList constructs a ResourceList struct for not-namespaced resources func NewResourceList(oc *exutil.CLI, kind string) *ResourceList { - return &ResourceList{ocGetter{oc.AsAdmin(), kind, "", ""}, []string{}, ""} + return &ResourceList{ocGetter{oc, kind, "", ""}, []string{}, ""} } // NewNamespacedResourceList constructs a ResourceList struct for namespaced resources func NewNamespacedResourceList(oc *exutil.CLI, kind, namespace string) *ResourceList { - return &ResourceList{ocGetter{oc.AsAdmin(), kind, namespace, ""}, []string{}, ""} + return &ResourceList{ocGetter{oc, kind, namespace, ""}, []string{}, ""} } // CleanParams removes the extraparams added by methods like "ByLabel" or "SorBy..." diff --git a/test/extended-priv/util.go b/test/extended-priv/util.go index 9930a7f4c5..ca3c938377 100644 --- a/test/extended-priv/util.go +++ b/test/extended-priv/util.go @@ -111,7 +111,7 @@ func generateTemplateAbsolutePath(fileName string) string { return filepath.Join(fixturesPath, fileName) } -func sortNodeList(nodes []Node) []Node { +func sortNodeList(nodes []*Node) []*Node { sort.Slice(nodes, func(l, r int) bool { lMetadata := JSON(nodes[l].GetOrFail("{.metadata}")) rMetadata := JSON(nodes[r].GetOrFail("{.metadata}")) @@ -159,8 +159,8 @@ func sortNodeList(nodes []Node) []Node { // sortMasterNodeList returns the list of nodes sorted by the order used to updated them in MCO master pool. // // Master pool will use the same order as the rest of the pools, but the node running the operator pod will be the last one to be updated. -func sortMasterNodeList(oc *exutil.CLI, nodes []Node) ([]Node, error) { - masterSortedNodes := []Node{} +func sortMasterNodeList(oc *exutil.CLI, nodes []*Node) ([]*Node, error) { + masterSortedNodes := []*Node{} operatorNode, err := GetOperatorNode(oc) if err != nil { return nil, err @@ -168,7 +168,7 @@ func sortMasterNodeList(oc *exutil.CLI, nodes []Node) ([]Node, error) { logger.Infof("MCO operator pod running in node: %s", operatorNode) - var latestNode Node + var latestNode *Node for _, item := range sortNodeList(nodes) { node := item if node.GetName() == operatorNode.GetName() {