Skip to content

Commit

Permalink
Changing upgrade package structure as a placeholder for supporting both
Browse files Browse the repository at this point in the history
inbox(legacy) and requestor (maintenance OP) upgrade modes

Signed-off-by: Ido Heyvi <[email protected]>
  • Loading branch information
heyvister1 committed Jan 1, 2025
1 parent 0109ebe commit 92e59ee
Show file tree
Hide file tree
Showing 26 changed files with 1,285 additions and 753 deletions.
2 changes: 1 addition & 1 deletion pkg/upgrade/consts.go → pkg/upgrade/common/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package upgrade
package common

const (
// UpgradeStateLabelKeyFmt is the format of the node label key indicating driver upgrade states
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package upgrade
package common

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package upgrade_test
package common_test

import (
"context"

common "github.com/NVIDIA/k8s-operator-libs/pkg/upgrade/common"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/NVIDIA/k8s-operator-libs/pkg/upgrade"
)

var _ = Describe("CordonManager tests", func() {
It("CordonManager should mark a node as schedulable/unschedulable", func() {
ctx := context.TODO()
node := createNode("test-node")

cordonManager := upgrade.NewCordonManager(k8sInterface, log)
cordonManager := common.NewCordonManager(k8sInterface, log)
err := cordonManager.Cordon(ctx, node)
Expect(err).To(Succeed())
Expect(node.Spec.Unschedulable).To(BeTrue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package upgrade
package common

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package upgrade_test
package common_test

import (
"context"
Expand All @@ -26,7 +26,7 @@ import (
"k8s.io/apimachinery/pkg/types"

v1alpha1 "github.com/NVIDIA/k8s-operator-libs/api/upgrade/v1alpha1"
"github.com/NVIDIA/k8s-operator-libs/pkg/upgrade"
common "github.com/NVIDIA/k8s-operator-libs/pkg/upgrade/common"
)

var _ = Describe("DrainManager tests", func() {
Expand All @@ -35,7 +35,7 @@ var _ = Describe("DrainManager tests", func() {

node := createNode("node")

drainManager := upgrade.NewDrainManager(k8sInterface, upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainManager := common.NewDrainManager(k8sInterface, common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainSpec := &v1alpha1.DrainSpec{
Enable: true,
Force: false,
Expand All @@ -44,7 +44,7 @@ var _ = Describe("DrainManager tests", func() {
DeleteEmptyDir: true,
}
nodeArray := []*corev1.Node{node}
err := drainManager.ScheduleNodesDrain(ctx, &upgrade.DrainConfiguration{Nodes: nodeArray, Spec: drainSpec})
err := drainManager.ScheduleNodesDrain(ctx, &common.DrainConfiguration{Nodes: nodeArray, Spec: drainSpec})
Expect(err).To(Succeed())

time.Sleep(time.Second)
Expand All @@ -61,7 +61,7 @@ var _ = Describe("DrainManager tests", func() {
node2 := createNode("node2")
node3 := createNode("node3")

drainManager := upgrade.NewDrainManager(k8sInterface, upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainManager := common.NewDrainManager(k8sInterface, common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainSpec := &v1alpha1.DrainSpec{
Enable: true,
Force: false,
Expand All @@ -70,7 +70,7 @@ var _ = Describe("DrainManager tests", func() {
DeleteEmptyDir: true,
}
nodeArray := []*corev1.Node{node1, node2, node3}
err := drainManager.ScheduleNodesDrain(ctx, &upgrade.DrainConfiguration{Nodes: nodeArray, Spec: drainSpec})
err := drainManager.ScheduleNodesDrain(ctx, &common.DrainConfiguration{Nodes: nodeArray, Spec: drainSpec})
Expect(err).To(Succeed())

time.Sleep(time.Second)
Expand All @@ -93,15 +93,15 @@ var _ = Describe("DrainManager tests", func() {
It("DrainManager should not fail on empty node list", func() {
ctx := context.TODO()

drainManager := upgrade.NewDrainManager(k8sInterface, upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainManager := common.NewDrainManager(k8sInterface, common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainSpec := &v1alpha1.DrainSpec{
Enable: true,
Force: false,
PodSelector: "",
TimeoutSecond: 1,
DeleteEmptyDir: true,
}
err := drainManager.ScheduleNodesDrain(ctx, &upgrade.DrainConfiguration{Nodes: nil, Spec: drainSpec})
err := drainManager.ScheduleNodesDrain(ctx, &common.DrainConfiguration{Nodes: nil, Spec: drainSpec})
Expect(err).To(Succeed())

time.Sleep(time.Second)
Expand All @@ -111,10 +111,10 @@ var _ = Describe("DrainManager tests", func() {

node := createNode("node")

drainManager := upgrade.NewDrainManager(k8sInterface, upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainManager := common.NewDrainManager(k8sInterface, common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)

nodeArray := []*corev1.Node{node}
err := drainManager.ScheduleNodesDrain(ctx, &upgrade.DrainConfiguration{Nodes: nodeArray, Spec: nil})
err := drainManager.ScheduleNodesDrain(ctx, &common.DrainConfiguration{Nodes: nodeArray, Spec: nil})
Expect(err).ToNot(Succeed())

time.Sleep(time.Second)
Expand All @@ -129,10 +129,10 @@ var _ = Describe("DrainManager tests", func() {

node := createNode("node")

drainManager := upgrade.NewDrainManager(k8sInterface, upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainManager := common.NewDrainManager(k8sInterface, common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)

nodeArray := []*corev1.Node{node}
err := drainManager.ScheduleNodesDrain(ctx, &upgrade.DrainConfiguration{Nodes: nodeArray, Spec: &v1alpha1.DrainSpec{}})
err := drainManager.ScheduleNodesDrain(ctx, &common.DrainConfiguration{Nodes: nodeArray, Spec: &v1alpha1.DrainSpec{}})
Expect(err).To(Succeed())

time.Sleep(time.Second)
Expand All @@ -147,11 +147,11 @@ var _ = Describe("DrainManager tests", func() {

node := createNode("node")

drainManager := upgrade.NewDrainManager(k8sInterface, upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)
drainManager := common.NewDrainManager(k8sInterface, common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder), log, eventRecorder)

nodeArray := []*corev1.Node{node}
err := drainManager.ScheduleNodesDrain(
ctx, &upgrade.DrainConfiguration{Nodes: nodeArray, Spec: &v1alpha1.DrainSpec{Enable: false}})
ctx, &common.DrainConfiguration{Nodes: nodeArray, Spec: &v1alpha1.DrainSpec{Enable: false}})
Expect(err).To(Succeed())

time.Sleep(time.Second)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package upgrade
package common

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package upgrade_test
package common_test

import (
"context"
"fmt"

common "github.com/NVIDIA/k8s-operator-libs/pkg/upgrade/common"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"

"github.com/NVIDIA/k8s-operator-libs/pkg/upgrade"
)

var _ = Describe("NodeUpgradeStateProvider tests", func() {
Expand All @@ -38,19 +37,19 @@ var _ = Describe("NodeUpgradeStateProvider tests", func() {
node = createNode(fmt.Sprintf("node-%s", id))
})
It("NodeUpgradeStateProvider should change node upgrade state and retrieve the latest node object", func() {
provider := upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder)
provider := common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder)

err := provider.ChangeNodeUpgradeState(ctx, node, upgrade.UpgradeStateUpgradeRequired)
err := provider.ChangeNodeUpgradeState(ctx, node, common.UpgradeStateUpgradeRequired)
Expect(err).To(Succeed())

node, err = provider.GetNode(ctx, node.Name)
Expect(err).To(Succeed())
Expect(node.Labels[upgrade.GetUpgradeStateLabelKey()]).To(Equal(upgrade.UpgradeStateUpgradeRequired))
Expect(node.Labels[common.GetUpgradeStateLabelKey()]).To(Equal(common.UpgradeStateUpgradeRequired))
})
It("NodeUpgradeStateProvider should change node upgrade annotation and retrieve the latest node object", func() {
provider := upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder)
provider := common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder)

key := upgrade.GetUpgradeInitialStateAnnotationKey()
key := common.GetUpgradeInitialStateAnnotationKey()
err := provider.ChangeNodeUpgradeAnnotation(ctx, node, key, "true")
Expect(err).To(Succeed())

Expand All @@ -59,9 +58,9 @@ var _ = Describe("NodeUpgradeStateProvider tests", func() {
Expect(node.Annotations[key]).To(Equal("true"))
})
It("NodeUpgradeStateProvider should delete node upgrade annotation and retrieve the latest node object", func() {
provider := upgrade.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder)
provider := common.NewNodeUpgradeStateProvider(k8sClient, log, eventRecorder)

key := upgrade.GetUpgradeInitialStateAnnotationKey()
key := common.GetUpgradeInitialStateAnnotationKey()
err := provider.ChangeNodeUpgradeAnnotation(ctx, node, key, "null")
Expect(err).To(Succeed())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package upgrade
package common

import (
"context"
Expand Down
Loading

0 comments on commit 92e59ee

Please sign in to comment.