Files
my-rook-config/pkg/operator/ceph/cluster/osd/status_test.go
T
dependabot[bot] 3c51e808f2 build(deps): bump the k8s-dependencies group with 6 updates
Bumps the k8s-dependencies group with 6 updates:

| Package | From | To |
| --- | --- | --- |
| [k8s.io/api](https://github.com/kubernetes/api) | `0.34.2` | `0.34.3` |
| [k8s.io/apiextensions-apiserver](https://github.com/kubernetes/apiextensions-apiserver) | `0.34.2` | `0.34.3` |
| [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) | `0.34.2` | `0.34.3` |
| [k8s.io/cli-runtime](https://github.com/kubernetes/cli-runtime) | `0.34.2` | `0.34.3` |
| [k8s.io/client-go](https://github.com/kubernetes/client-go) | `0.34.2` | `0.34.3` |
| [k8s.io/cloud-provider](https://github.com/kubernetes/cloud-provider) | `0.34.2` | `0.34.3` |

Updates `k8s.io/api` from 0.34.2 to 0.34.3
- [Commits](https://github.com/kubernetes/api/compare/v0.34.2...v0.34.3)

Updates `k8s.io/apiextensions-apiserver` from 0.34.2 to 0.34.3
- [Release notes](https://github.com/kubernetes/apiextensions-apiserver/releases)
- [Commits](https://github.com/kubernetes/apiextensions-apiserver/compare/v0.34.2...v0.34.3)

Updates `k8s.io/apimachinery` from 0.34.2 to 0.34.3
- [Commits](https://github.com/kubernetes/apimachinery/compare/v0.34.2...v0.34.3)

Updates `k8s.io/cli-runtime` from 0.34.2 to 0.34.3
- [Commits](https://github.com/kubernetes/cli-runtime/compare/v0.34.2...v0.34.3)

Updates `k8s.io/client-go` from 0.34.2 to 0.34.3
- [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kubernetes/client-go/compare/v0.34.2...v0.34.3)

Updates `k8s.io/cloud-provider` from 0.34.2 to 0.34.3
- [Commits](https://github.com/kubernetes/cloud-provider/compare/v0.34.2...v0.34.3)

---
updated-dependencies:
- dependency-name: k8s.io/api
  dependency-version: 0.34.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s-dependencies
- dependency-name: k8s.io/apiextensions-apiserver
  dependency-version: 0.34.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s-dependencies
- dependency-name: k8s.io/apimachinery
  dependency-version: 0.34.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s-dependencies
- dependency-name: k8s.io/cli-runtime
  dependency-version: 0.34.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s-dependencies
- dependency-name: k8s.io/client-go
  dependency-version: 0.34.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s-dependencies
- dependency-name: k8s.io/cloud-provider
  dependency-version: 0.34.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-07 07:59:21 -07:00

131 lines
4.6 KiB
Go

/*
Copyright 2018 The Rook Authors. All rights reserved.
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 osd
import (
"context"
"encoding/json"
"fmt"
"testing"
"time"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/clusterd"
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
cephver "github.com/rook/rook/pkg/operator/ceph/version"
"github.com/rook/rook/pkg/operator/k8sutil"
exectest "github.com/rook/rook/pkg/util/exec/test"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes/fake"
)
func TestOrchestrationStatus(t *testing.T) {
ctx := context.TODO()
clientset := fake.NewClientset()
clusterInfo := &cephclient.ClusterInfo{
Namespace: "ns",
CephVersion: cephver.Squid,
}
context := &clusterd.Context{Clientset: clientset, ConfigDir: "/var/lib/rook", Executor: &exectest.MockExecutor{}}
spec := cephv1.ClusterSpec{}
c := New(context, clusterInfo, spec, "myversion")
ownerInfo := cephclient.NewMinimumOwnerInfoWithOwnerRef()
kv := k8sutil.NewConfigMapKVStore(c.clusterInfo.Namespace, clientset, ownerInfo)
nodeName := "mynode"
cmName := fmt.Sprintf(orchestrationStatusMapName, nodeName)
// status map should not exist yet
_, err := c.context.Clientset.CoreV1().ConfigMaps(c.clusterInfo.Namespace).Get(ctx, cmName, metav1.GetOptions{})
assert.True(t, errors.IsNotFound(err))
// update the status map with some status
status := OrchestrationStatus{Status: OrchestrationStatusOrchestrating, Message: "doing work"}
UpdateNodeOrPVCStatus(ctx, kv, nodeName, status)
// retrieve the status and verify it
statusMap, err := c.context.Clientset.CoreV1().ConfigMaps(c.clusterInfo.Namespace).Get(ctx, cmName, metav1.GetOptions{})
assert.Nil(t, err)
assert.NotNil(t, statusMap)
retrievedStatus := parseOrchestrationStatus(statusMap.Data)
assert.NotNil(t, retrievedStatus)
assert.Equal(t, status, *retrievedStatus)
}
func mockNodeOrchestrationCompletion(c *Cluster, nodeName string, statusMapWatcher *watch.FakeWatcher) {
ctx := context.TODO()
// if no valid osd node, don't need to check its status, return immediately
if len(c.spec.Storage.Nodes) == 0 {
return
}
for {
// wait for the node's orchestration status to change to "starting"
cmName := statusConfigMapName(nodeName)
cm, err := c.context.Clientset.CoreV1().ConfigMaps(c.clusterInfo.Namespace).Get(ctx, cmName, metav1.GetOptions{})
if err == nil {
status := parseOrchestrationStatus(cm.Data)
if status != nil && status.Status == OrchestrationStatusStarting {
// the node has started orchestration, simulate its completion now by performing 2 tasks:
// 1) update the config map manually (which doesn't trigger a watch event, see https://github.com/kubernetes/kubernetes/issues/54075#issuecomment-337298950)
status = &OrchestrationStatus{
OSDs: []OSDInfo{
{
ID: 1,
UUID: "000000-0000-00000001",
Cluster: "rook",
CVMode: "raw",
BlockPath: "/dev/some/path",
},
},
Status: OrchestrationStatusCompleted,
}
UpdateNodeOrPVCStatus(ctx, c.kv, nodeName, *status)
// 2) call modify on the fake watcher so a watch event will get triggered
s, _ := json.Marshal(status)
cm.Data[orchestrationStatusKey] = string(s)
statusMapWatcher.Modify(cm)
break
} else {
logger.Debugf("waiting for node %s orchestration to start. status: %+v", nodeName, *status)
}
} else {
logger.Warningf("failed to get node %s orchestration status, will try again: %+v", nodeName, err)
}
<-time.After(50 * time.Millisecond)
}
}
func waitForOrchestrationCompletion(c *Cluster, nodeName string, startCompleted *bool) {
ctx := context.TODO()
for {
if *startCompleted {
break
}
cmName := statusConfigMapName(nodeName)
cm, err := c.context.Clientset.CoreV1().ConfigMaps(c.clusterInfo.Namespace).Get(ctx, cmName, metav1.GetOptions{})
if err == nil {
status := parseOrchestrationStatus(cm.Data)
if status != nil {
logger.Debugf("start has not completed, status is %+v", status)
}
}
<-time.After(50 * time.Millisecond)
}
}