github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/caas/kubernetes/provider/resources_test.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package provider_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 "github.com/juju/version/v2" 9 "go.uber.org/mock/gomock" 10 gc "gopkg.in/check.v1" 11 apps "k8s.io/api/apps/v1" 12 core "k8s.io/api/core/v1" 13 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 14 15 "github.com/juju/juju/environs/context" 16 "github.com/juju/juju/testing" 17 ) 18 19 var _ = gc.Suite(&ResourcesSuite{}) 20 21 type ResourcesSuite struct { 22 BaseSuite 23 } 24 25 func (s *ResourcesSuite) TestAdoptResources(c *gc.C) { 26 ctrl := s.setupController(c) 27 defer ctrl.Finish() 28 29 modelSelector := "juju-model-uuid==" + testing.ModelTag.Id() 30 31 gomock.InOrder( 32 s.mockPods.EXPECT().List(gomock.Any(), v1.ListOptions{LabelSelector: modelSelector}). 33 Return(&core.PodList{Items: []core.Pod{ 34 {ObjectMeta: v1.ObjectMeta{Labels: map[string]string{}}}, 35 }}, nil), 36 s.mockPods.EXPECT().Update(gomock.Any(), &core.Pod{ObjectMeta: v1.ObjectMeta{ 37 Labels: map[string]string{"juju-controller-uuid": "uuid"}}}, v1.UpdateOptions{}). 38 Return(nil, nil), 39 40 s.mockPersistentVolumeClaims.EXPECT().List(gomock.Any(), v1.ListOptions{LabelSelector: modelSelector}). 41 Return(&core.PersistentVolumeClaimList{Items: []core.PersistentVolumeClaim{ 42 {ObjectMeta: v1.ObjectMeta{Labels: map[string]string{}}}, 43 }}, nil), 44 s.mockPersistentVolumeClaims.EXPECT().Update(gomock.Any(), &core.PersistentVolumeClaim{ObjectMeta: v1.ObjectMeta{ 45 Labels: map[string]string{"juju-controller-uuid": "uuid"}}}, v1.UpdateOptions{}). 46 Return(nil, nil), 47 48 s.mockPersistentVolumes.EXPECT().List(gomock.Any(), v1.ListOptions{LabelSelector: modelSelector}). 49 Return(&core.PersistentVolumeList{Items: []core.PersistentVolume{ 50 {ObjectMeta: v1.ObjectMeta{Labels: map[string]string{}}}, 51 }}, nil), 52 s.mockPersistentVolumes.EXPECT().Update(gomock.Any(), &core.PersistentVolume{ObjectMeta: v1.ObjectMeta{ 53 Labels: map[string]string{"juju-controller-uuid": "uuid"}}}, v1.UpdateOptions{}). 54 Return(nil, nil), 55 56 s.mockStatefulSets.EXPECT().List(gomock.Any(), v1.ListOptions{LabelSelector: modelSelector}). 57 Return(&apps.StatefulSetList{Items: []apps.StatefulSet{ 58 {ObjectMeta: v1.ObjectMeta{Labels: map[string]string{}}}, 59 }}, nil), 60 s.mockStatefulSets.EXPECT().Update(gomock.Any(), &apps.StatefulSet{ObjectMeta: v1.ObjectMeta{ 61 Labels: map[string]string{"juju-controller-uuid": "uuid"}}}, v1.UpdateOptions{}). 62 Return(nil, nil), 63 64 s.mockDeployments.EXPECT().List(gomock.Any(), v1.ListOptions{LabelSelector: modelSelector}). 65 Return(&apps.DeploymentList{Items: []apps.Deployment{ 66 {ObjectMeta: v1.ObjectMeta{Labels: map[string]string{}}}, 67 }}, nil), 68 s.mockDeployments.EXPECT().Update(gomock.Any(), &apps.Deployment{ObjectMeta: v1.ObjectMeta{ 69 Labels: map[string]string{"juju-controller-uuid": "uuid"}}}, v1.UpdateOptions{}). 70 Return(nil, nil), 71 ) 72 73 err := s.broker.AdoptResources(context.NewEmptyCloudCallContext(), "uuid", version.MustParse("1.2.3")) 74 c.Assert(err, jc.ErrorIsNil) 75 }