Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
wilwell committed Feb 6, 2025
1 parent fa0e7ca commit 3fce632
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 44 deletions.
6 changes: 3 additions & 3 deletions api/v1/ytsaurus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,11 @@ const (

type ComponentUpdateSelector struct {
//+optional
ComponentType consts.ComponentType `json:"componentType,omitempty"`
Type consts.ComponentType `json:"type,omitempty"`
//+optional
ComponentGroup consts.ComponentGroup `json:"componentGroup,omitempty"`
Group consts.ComponentGroup `json:"group,omitempty"`
//+optional
ComponentName string `json:"componentName,omitempty"`
Name string `json:"name,omitempty"`

// TODO(#325): Add rolling options
}
Expand Down
6 changes: 3 additions & 3 deletions config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39577,11 +39577,11 @@ spec:
the update process.
items:
properties:
componentGroup:
group:
type: string
componentName:
name:
type: string
componentType:
type:
type: string
type: object
type: array
Expand Down
36 changes: 16 additions & 20 deletions controllers/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,20 @@ import (

func canUpdateComponent(selectors []ytv1.ComponentUpdateSelector, component ytv1.Component) bool {
for _, selector := range selectors {
if selector.ComponentName != "" {
if selector.ComponentName == component.Name {
if selector.Name != "" {
if selector.Name == component.Name {
return true
}
} else if selector.ComponentType != "" {
if selector.ComponentType == component.Type {
} else if selector.Type != "" {
if selector.Type == component.Type {
return true
}
} else {
switch selector.ComponentGroup {
switch selector.Group {
case consts.ComponentGroupEverything:
return true
case consts.ComponentGroupNothing:
return false
case consts.ComponentGroupStateful:
if component.Type != consts.MasterType {
return true
}
case consts.ComponentGroupStateless:
if component.Type != consts.DataNodeType && component.Type != consts.TabletNodeType && component.Type != consts.MasterType {
return true
Expand Down Expand Up @@ -75,7 +71,7 @@ func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Co
return nil, "All components are uptodate"
}

if len(configuredSelectors) == 1 && configuredSelectors[0].ComponentGroup == consts.ComponentGroupEverything {
if len(configuredSelectors) == 1 && configuredSelectors[0].Group == consts.ComponentGroupEverything {
if needFullUpdate(needUpdate) {
// Here we update not only components that are not up-to-date, but all cluster.
return convertToComponent(allComponents), ""
Expand All @@ -87,7 +83,7 @@ func chooseUpdatingComponents(spec ytv1.YtsaurusSpec, needUpdate []components.Co
}

func needFullUpdate(needUpdate []components.Component) bool {
statelessSelector := []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupStateless}}
statelessSelector := []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupStateless}}
for _, comp := range needUpdate {
component := ytv1.Component{
Name: comp.GetName(),
Expand All @@ -109,27 +105,27 @@ func getEffectiveSelectors(spec ytv1.YtsaurusSpec) []ytv1.ComponentUpdateSelecto
if spec.UpdateSelector != ytv1.UpdateSelectorUnspecified {
switch spec.UpdateSelector {
case ytv1.UpdateSelectorNothing:
return []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupNothing}}
return []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupNothing}}
case ytv1.UpdateSelectorMasterOnly:
return []ytv1.ComponentUpdateSelector{{ComponentType: consts.MasterType}}
return []ytv1.ComponentUpdateSelector{{Type: consts.MasterType}}
case ytv1.UpdateSelectorDataNodesOnly:
return []ytv1.ComponentUpdateSelector{{ComponentType: consts.DataNodeType}}
return []ytv1.ComponentUpdateSelector{{Type: consts.DataNodeType}}
case ytv1.UpdateSelectorTabletNodesOnly:
return []ytv1.ComponentUpdateSelector{{ComponentType: consts.TabletNodeType}}
return []ytv1.ComponentUpdateSelector{{Type: consts.TabletNodeType}}
case ytv1.UpdateSelectorExecNodesOnly:
return []ytv1.ComponentUpdateSelector{{ComponentType: consts.ExecNodeType}}
return []ytv1.ComponentUpdateSelector{{Type: consts.ExecNodeType}}
case ytv1.UpdateSelectorStatelessOnly:
return []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupStateless}}
return []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupStateless}}
case ytv1.UpdateSelectorEverything:
return []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupEverything}}
return []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupEverything}}
}
}

if spec.EnableFullUpdate {
return []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupEverything}}
return []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupEverything}}
}

return []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupStateless}}
return []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupStateless}}
}

func convertToComponent(components []components.Component) []ytv1.Component {
Expand Down
6 changes: 3 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `componentType` _[ComponentType](#componenttype)_ | | | |
| `componentGroup` _[ComponentGroup](#componentgroup)_ | | | |
| `componentName` _string_ | | | |
| `type` _[ComponentType](#componenttype)_ | | | |
| `group` _[ComponentGroup](#componentgroup)_ | | | |
| `name` _string_ | | | |


#### ControllerAgentsSpec
Expand Down
4 changes: 1 addition & 3 deletions pkg/consts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ type ComponentGroup string

const (
// ComponentGroupStateless group contains only stateless components (not master, data nodes, tablet nodes)
ComponentGroupStateless ComponentGroup = "Stateless"
// ComponentGroupStateful group contains every component except master
ComponentGroupStateful ComponentGroup = "Stateful"
ComponentGroupStateless ComponentGroup = "Stateless"
ComponentGroupEverything ComponentGroup = "Everything"
ComponentGroupNothing ComponentGroup = "Nothing"
)
2 changes: 1 addition & 1 deletion test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func HaveClusterUpdatingComponents(components ...string) otypes.GomegaMatcher {
WithTransform(func(yts *ytv1.Ytsaurus) []string {
var result []string
for _, comp := range yts.Status.UpdateStatus.UpdatingComponents {
result = append(result, string(comp.Type))
result = append(result, comp.Name)
}
return result
}, Equal(components)),
Expand Down
50 changes: 42 additions & 8 deletions test/e2e/ytsaurus_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ import (
const (
pollInterval = time.Millisecond * 250
reactionTimeout = time.Second * 150
bootstrapTimeout = time.Minute * 10
upgradeTimeout = time.Minute * 10
bootstrapTimeout = time.Minute * 3
upgradeTimeout = time.Minute * 7
)

var getYtClient = getYtHTTPClient
Expand Down Expand Up @@ -316,7 +316,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func()
It("Should be updated according to UpdateSelector=Everything", func(ctx context.Context) {

By("Run cluster update with selector: nothing")
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupNothing}}
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupNothing}}
// We want change in all yson configs, new discovery instance will trigger that.
ytsaurus.Spec.Discovery.InstanceCount += 1
UpdateObject(ctx, ytsaurus)
Expand All @@ -330,7 +330,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func()
)

By("Update cluster update with strategy full")
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupEverything}}
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupEverything}}
ytsaurus.Spec.Discovery.InstanceCount += 1
UpdateObject(ctx, ytsaurus)

Expand Down Expand Up @@ -358,7 +358,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func()
It("Should be updated according to UpdateSelector=TabletNodesOnly,ExecNodesOnly", func(ctx context.Context) {

By("Run cluster update with selector:ExecNodesOnly")
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{ComponentType: consts.ExecNodeType}}
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{Type: consts.ExecNodeType}}
ytsaurus.Spec.Discovery.InstanceCount += 1
UpdateObject(ctx, ytsaurus)

Expand All @@ -376,7 +376,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func()
Expect(pods.Updated).To(ConsistOf("end-0"), "updated")

By("Run cluster update with selector:TabletNodesOnly")
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{ComponentType: consts.TabletNodeType}}
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{Type: consts.TabletNodeType}}
ytsaurus.Spec.Discovery.InstanceCount += 1
UpdateObject(ctx, ytsaurus)

Expand All @@ -397,7 +397,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func()
It("Should be updated according to UpdateSelector=MasterOnly,StatelessOnly", func(ctx context.Context) {

By("Run cluster update with selector:MasterOnly")
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{ComponentType: consts.MasterType}}
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{Type: consts.MasterType}}
ytsaurus.Spec.Discovery.InstanceCount += 1
UpdateObject(ctx, ytsaurus)

Expand All @@ -414,7 +414,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func()
Expect(pods.Updated).To(ConsistOf("ms-0"), "updated")

By("Run cluster update with selector:StatelessOnly")
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{ComponentGroup: consts.ComponentGroupStateless}}
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{Group: consts.ComponentGroupStateless}}
ytsaurus.Spec.Discovery.InstanceCount += 1
UpdateObject(ctx, ytsaurus)

Expand All @@ -438,6 +438,40 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func()
Expect(pods.Created).To(ConsistOf("ds-1", "ds-2"), "created")
})

It("Should update only specified data node group", func(ctx context.Context) {
By("Adding second data node group")
ytsaurus.Spec.DataNodes = append(ytsaurus.Spec.DataNodes, ytv1.DataNodesSpec{
InstanceSpec: testutil.CreateDataNodeInstanceSpec(1),
Name: "dn-2",
})
UpdateObject(ctx, ytsaurus)

EventuallyYtsaurus(ctx, ytsaurus, reactionTimeout).Should(HaveClusterState(ytv1.ClusterStateReconfiguration))
EventuallyYtsaurus(ctx, ytsaurus, upgradeTimeout).Should(HaveClusterStateRunning())
podsBeforeUpdate = getComponentPods(ctx, namespace)

By("Run cluster update with selector targeting only second data node group")
ytsaurus.Spec.UpdateSelectors = []ytv1.ComponentUpdateSelector{{
Name: "DataNode-dn-2",
}}
ytsaurus.Spec.Discovery.InstanceCount += 1
UpdateObject(ctx, ytsaurus)

EventuallyYtsaurus(ctx, ytsaurus, reactionTimeout).Should(HaveObservedGeneration())
Expect(ytsaurus).Should(HaveClusterUpdatingComponents("DataNode-dn-2"))

By("Wait cluster update with selector:DataNodesOnly complete")
EventuallyYtsaurus(ctx, ytsaurus, upgradeTimeout).Should(HaveClusterStateRunning())
checkClusterBaseViability(ytClient)

podsAfterUpdate := getComponentPods(ctx, namespace)
pods := getChangedPods(podsBeforeUpdate, podsAfterUpdate)
Expect(pods.Created).To(BeEmpty(), "created")
Expect(pods.Deleted).To(BeEmpty(), "deleted")
// Only the second data node group should be updated
Expect(pods.Updated).To(ConsistOf("dnd-dn-2-0"), "updated")
})

}) // update selector

Context("With config overrides", Label("overrides"), func() {
Expand Down
6 changes: 3 additions & 3 deletions ytop-chart/templates/crds/ytsaurus.cluster.ytsaurus.tech.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39588,11 +39588,11 @@ spec:
the update process.
items:
properties:
componentGroup:
group:
type: string
componentName:
name:
type: string
componentType:
type:
type: string
type: object
type: array
Expand Down

0 comments on commit 3fce632

Please sign in to comment.