-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: API Start and Stop mechanism for RpaasInstance. (#150)
* Start and stop routes and client command * Update copyright date * Adding missing implementations * Fix linter * Shutdown flag showing in the cli info cmd * Bug fixes and creating innitial testing * Fetching reference after patch * Completed test suite * Showing Shutdown when using kubectl get rpaasinstance * Remove content type * Remove content-type assertions
- Loading branch information
Showing
23 changed files
with
505 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 tsuru authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func NewCmdStart() *cli.Command { | ||
return &cli.Command{ | ||
Name: "start", | ||
Usage: "Starts instance if the current state is shutdown", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "service", | ||
Aliases: []string{"tsuru-service", "s"}, | ||
Usage: "the Tsuru service name", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "instance", | ||
Aliases: []string{"tsuru-service-instance", "i"}, | ||
Usage: "the reverse proxy instance name", | ||
Required: true, | ||
}, | ||
}, | ||
Before: setupClient, | ||
Action: runStart, | ||
} | ||
} | ||
|
||
func runStart(c *cli.Context) error { | ||
client, err := getClient(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = client.Start(c.Context, c.String("instance")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(c.App.Writer, "Started instance %s\n", formatInstanceName(c)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2024 tsuru authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/tsuru/rpaas-operator/pkg/rpaas/client/fake" | ||
) | ||
|
||
func TestStart(t *testing.T) { | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
|
||
args := []string{"./rpaasv2", "start", "-s", "some-service", "-i", "my-instance"} | ||
|
||
client := &fake.FakeClient{ | ||
FakeStart: func(instance string) error { | ||
require.Equal(t, instance, "my-instance") | ||
return nil | ||
}, | ||
} | ||
|
||
app := NewApp(stdout, stderr, client) | ||
err := app.Run(args) | ||
require.NoError(t, err) | ||
assert.Equal(t, stdout.String(), "Started instance some-service/my-instance\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 tsuru authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func NewCmdStop() *cli.Command { | ||
return &cli.Command{ | ||
Name: "stop", | ||
Usage: "Shutdown instance (halt autoscale and scale in all replicas)", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "service", | ||
Aliases: []string{"tsuru-service", "s"}, | ||
Usage: "the Tsuru service name", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "instance", | ||
Aliases: []string{"tsuru-service-instance", "i"}, | ||
Usage: "the reverse proxy instance name", | ||
Required: true, | ||
}, | ||
}, | ||
Before: setupClient, | ||
Action: runStop, | ||
} | ||
} | ||
|
||
func runStop(c *cli.Context) error { | ||
client, err := getClient(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = client.Stop(c.Context, c.String("instance")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(c.App.Writer, "Shutting down instance %s\n", formatInstanceName(c)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2024 tsuru authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/tsuru/rpaas-operator/pkg/rpaas/client/fake" | ||
) | ||
|
||
func TestStop(t *testing.T) { | ||
stdout := &bytes.Buffer{} | ||
stderr := &bytes.Buffer{} | ||
|
||
args := []string{"./rpaasv2", "stop", "-s", "some-service", "-i", "my-instance"} | ||
|
||
client := &fake.FakeClient{ | ||
FakeStop: func(instance string) error { | ||
require.Equal(t, instance, "my-instance") | ||
return nil | ||
}, | ||
} | ||
|
||
app := NewApp(stdout, stderr, client) | ||
err := app.Run(args) | ||
require.NoError(t, err) | ||
assert.Equal(t, stdout.String(), "Shutting down instance some-service/my-instance\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.