Skip to content

Commit

Permalink
Add GetType for components (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
l0kix2 authored Apr 16, 2024
1 parent 19fecad commit 2f777e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy"
"github.com/ytsaurus/yt-k8s-operator/pkg/consts"
"github.com/ytsaurus/yt-k8s-operator/pkg/labeller"
)

Expand Down Expand Up @@ -47,6 +48,7 @@ type Component interface {
Sync(ctx context.Context) error
Status(ctx context.Context) (ComponentStatus, error)
GetName() string
GetType() consts.ComponentType
SetReadyCondition(status ComponentStatus)

// TODO(nadya73): refactor it
Expand Down
22 changes: 16 additions & 6 deletions pkg/components/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/ytsaurus/yt-k8s-operator/pkg/consts"
mock_yt "github.com/ytsaurus/yt-k8s-operator/pkg/mock"
)

Expand All @@ -31,12 +32,17 @@ var _ = BeforeSuite(func() {
})

type FakeComponent struct {
name string
status ComponentStatus
name string
compType consts.ComponentType
status ComponentStatus
}

func NewFakeComponent(name string) *FakeComponent {
return &FakeComponent{name: name, status: SimpleStatus(SyncStatusReady)}
func NewFakeComponent(name string, compType consts.ComponentType) *FakeComponent {
return &FakeComponent{
name: name,
compType: compType,
status: SimpleStatus(SyncStatusReady),
}
}

func (fc *FakeComponent) IsUpdatable() bool {
Expand All @@ -63,6 +69,10 @@ func (fc *FakeComponent) GetName() string {
return fc.name
}

func (fc *FakeComponent) GetType() consts.ComponentType {
return fc.compType
}

func (fc *FakeComponent) SetReadyCondition(status ComponentStatus) {}

type FakeServer struct {
Expand Down Expand Up @@ -132,7 +142,7 @@ type FakeYtsaurusClient struct {

func NewFakeYtsaurusClient(client *mock_yt.MockClient) *FakeYtsaurusClient {
return &FakeYtsaurusClient{
FakeComponent: *NewFakeComponent("ytsaurus_client"),
FakeComponent: *NewFakeComponent("ytsaurus_client", consts.YtsaurusClientType),
client: client,
}
}
Expand All @@ -145,6 +155,6 @@ func (fyc *FakeYtsaurusClient) SetStatus(status ComponentStatus) {
fyc.status = status
}

func (fc *FakeYtsaurusClient) IsUpdatable() bool {
func (fyc *FakeYtsaurusClient) IsUpdatable() bool {
return false
}

0 comments on commit 2f777e3

Please sign in to comment.