Skip to content

Commit

Permalink
Fix queue agent init script usage for 24.* (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
l0kix2 authored Oct 11, 2024
1 parent c439d7c commit 805bba2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
30 changes: 28 additions & 2 deletions pkg/components/queue_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,37 @@ func (qa *QueueAgent) init(ctx context.Context, ytClient yt.Client) (err error)

func (qa *QueueAgent) prepareInitQueueAgentState() {
path := "/usr/bin/init_queue_agent_state"
proxy := qa.cfgen.GetHTTPProxiesServiceAddress(consts.DefaultHTTPProxyRole)

// Somewhere in 24.1 this script has changed signature and since it is not tied to some version we can check
// we will try to call it new way and fallback to old way on error.
// COMPAT(l0kix2): Remove after 23.1 not supported in the yt operator.
oldVersionInvokation := fmt.Sprintf("%s --create-registration-table --create-replicated-table-mapping-table --recursive --ignore-existing --proxy %s",
path,
proxy,
)
newVersionInvokation := fmt.Sprintf("%s --latest --proxy %s",
path,
proxy,
)

script := []string{
initJobWithNativeDriverPrologue(),
fmt.Sprintf("if [[ -f \"%s\" ]]; then %s --create-registration-table --create-replicated-table-mapping-table --recursive --ignore-existing --proxy %s; fi",
path, path, qa.cfgen.GetHTTPProxiesServiceAddress(consts.DefaultHTTPProxyRole)),
fmt.Sprintf(`if [ ! -f %s ]; then`, path),
fmt.Sprintf(`echo "%s doesn't exist, nothing to do"`, path),
`exit 0`,
`fi`,
// Temporary turning off exiting on non-zero status, since we expect this command may fail on
// unexpected arguments in the older server versions.
// In case arguments are valid and other error occurs it is not a problem, since new binary will fail with
// the old arguments later anyway.
`set +e`,
newVersionInvokation,
`if [ $? -ne 0 ]; then`,
`set -e`,
`echo "Binary execution failed. Running with an old set of arguments"`,
oldVersionInvokation,
`fi`,
}

qa.initQAState.SetInitScript(strings.Join(script, "\n"))
Expand Down
11 changes: 11 additions & 0 deletions pkg/testutil/spec_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ func WithQueryTracker(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus {
return ytsaurus
}

func WithQueueAgent(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus {
ytsaurus.Spec.QueueAgents = &ytv1.QueueAgentSpec{
InstanceSpec: ytv1.InstanceSpec{
InstanceCount: 1,
// Older version doesn't have /usr/bin/ytserver-queue-agent
Image: ptr.To(CoreImageNextVer),
},
}
return ytsaurus
}

func WithRPCProxies(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus {
ytsaurus.Spec.RPCProxies = []ytv1.RPCProxiesSpec{
createRPCProxiesSpec(),
Expand Down
1 change: 1 addition & 0 deletions test/e2e/ytsaurus_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {

ytsaurus := testutil.CreateBaseYtsaurusResource(namespace)
ytsaurus = testutil.WithQueryTracker(ytsaurus)
ytsaurus = testutil.WithQueueAgent(ytsaurus)

g := ytconfig.NewGenerator(ytsaurus, "local")

Expand Down

0 comments on commit 805bba2

Please sign in to comment.