Skip to content

Commit

Permalink
Update HA k0smotron cluster test
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Makhov <[email protected]>
  • Loading branch information
makhov committed Dec 18, 2024
1 parent 0a411d1 commit 810cdf2
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion inttest/ha-controller-etcd/ha_controller_etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ import (
"testing"

"github.com/k0sproject/k0s/inttest/common"
"github.com/k0sproject/k0smotron/inttest/util"
km "github.com/k0sproject/k0smotron/api/k0smotron.io/v1beta1"
"github.com/stretchr/testify/suite"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"

"github.com/k0sproject/k0smotron/inttest/util"
)

type HAControllerEtcdSuite struct {
Expand Down Expand Up @@ -77,6 +83,10 @@ func (s *HAControllerEtcdSuite) TestK0sGetsUp() {
s.Require().NoError(err)
s.Require().NoError(s.WaitForNodeReady(s.K0smotronNode(0), kmcKC))

s.updateK0smotronCluster(s.Context(), rc)
s.Require().NoError(common.WaitForStatefulSet(s.Context(), kc, "kmc-kmc-test", "kmc-test"))
s.Require().NoError(common.WaitForStatefulSet(s.Context(), kc, "kmc-kmc-test-etcd", "kmc-test"))
s.Require().NoError(s.WaitForNodeReady(s.K0smotronNode(0), kmcKC))
}

func TestHAControllerEtcdSuite(t *testing.T) {
Expand Down Expand Up @@ -110,6 +120,7 @@ func (s *HAControllerEtcdSuite) createK0smotronCluster(ctx context.Context, kc *
},
"spec": {
"replicas": 3,
"version": "v1.27.2-k0s.0",
"service":{
"type": "NodePort"
},
Expand All @@ -128,6 +139,26 @@ func (s *HAControllerEtcdSuite) createK0smotronCluster(ctx context.Context, kc *
s.Require().NoError(res.Error())
}

func (s *HAControllerEtcdSuite) updateK0smotronCluster(ctx context.Context, rc *rest.Config) {
crdConfig := *rc
crdConfig.ContentConfig.GroupVersion = &km.GroupVersion
crdConfig.APIPath = "/apis"
crdConfig.NegotiatedSerializer = serializer.NewCodecFactory(scheme.Scheme)
crdConfig.UserAgent = rest.DefaultKubernetesUserAgent()
crdRestClient, err := rest.UnversionedRESTClientFor(&crdConfig)
s.Require().NoError(err)

patch := `[{"op": "replace", "path": "/spec/version", "value": "v1.28.3-k0s.0"}]`
res := crdRestClient.
Patch(types.JSONPatchType).
Resource("clusters").
Name("kmc-test").
Namespace("kmc-test").
Body([]byte(patch)).
Do(ctx)
s.Require().NoError(res.Error())
}

func (s *HAControllerEtcdSuite) getPod(ctx context.Context, kc *kubernetes.Clientset) corev1.Pod {
pods, err := kc.CoreV1().Pods("kmc-test").List(
ctx,
Expand Down

0 comments on commit 810cdf2

Please sign in to comment.