Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

TEST Scale down doc #683

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions deployment/network-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,6 @@ These limitations will be addressed in future releases.
> __NOTE__: changes which were made directly in NicClusterPolicy CR (e.g. with `kubectl edit`)
> will be overwritten by Helm upgrade

### Temporary disable network-operator

This step is required to prevent the old network-operator version to handle the updated NicClusterPolicy CR. This
limitation will be removed in future network-operator releases.

```
kubectl scale deployment --replicas=0 -n network-operator network-operator
```

You have to wait for network-operator POD to remove before proceeding.

> __NOTE__: network-operator will be automatically enabled by helm upgrade command,
> you don't need to enable it manually

### Apply Helm chart update

```
Expand Down
68 changes: 68 additions & 0 deletions pkg/migrate/migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
2023 NVIDIA CORPORATION & AFFILIATES

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package migrate

import (
goctx "context"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/Mellanox/network-operator/pkg/consts"
)

//nolint:dupl
var _ = Describe("Migrate", func() {
AfterEach(func() {
cm := &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: namespaceName, Name: nvIPAMcmName}}
_ = k8sClient.Delete(goctx.Background(), cm)
})
It("should remove annotation on NVIPAM CM", func() {
createConfigMap(true)
err := Migrate(goctx.Background(), testLog, k8sClient)
Expect(err).NotTo(HaveOccurred())
cm := &corev1.ConfigMap{}
err = k8sClient.Get(goctx.Background(),
types.NamespacedName{Namespace: namespaceName, Name: nvIPAMcmName}, cm)
Expect(err).NotTo(HaveOccurred())
_, ok := cm.Labels[consts.StateLabel]
Expect(ok).To(BeFalse())
})
It("should not fail if state label does not exists", func() {
createConfigMap(false)
err := Migrate(goctx.Background(), testLog, k8sClient)
Expect(err).NotTo(HaveOccurred())
})
It("should not fail if NVIPAM CM does not exists", func() {
err := Migrate(goctx.Background(), testLog, k8sClient)
Expect(err).NotTo(HaveOccurred())
})
})

func createConfigMap(addLabel bool) {
cm := &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: namespaceName, Name: nvIPAMcmName}}
if addLabel {
cm.Labels = make(map[string]string)
cm.Labels[consts.StateLabel] = "state-nv-ipam-cni"
}
err := k8sClient.Create(goctx.Background(), cm)
Expect(err).NotTo(HaveOccurred())
}
84 changes: 84 additions & 0 deletions pkg/migrate/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
2023 NVIDIA CORPORATION & AFFILIATES

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package migrate

import (
"context"
"testing"
"time"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.

const (
timeout = time.Second * 10
interval = time.Millisecond * 250
namespaceName = "nvidia-network-operator"
nvIPAMcmName = "nvidia-k8s-ipam-config"
)

var k8sClient client.Client
var testEnv *envtest.Environment
var testLog logr.Logger

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecs(t, "Migrate Suite")
}

var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
testLog = logf.Log.WithName("test-log").WithName("setup")

By("bootstrapping test environment")

testEnv = &envtest.Environment{}

cfg, err := testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())

ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{
Name: namespaceName,
}}
err = k8sClient.Create(context.Background(), ns)
Expect(err).NotTo(HaveOccurred())
})

var _ = AfterSuite(func() {
By("tearing down the test environment")
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})
Loading