Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RELEASE] 20230308 #3653

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cmd/convox/pkg
provider/aws/lambda/autoscale/handler
provider/aws/lambda/autoscale/lambda.zip
.vscode/
.DS_Store
74 changes: 74 additions & 0 deletions pkg/cli/rack.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func init() {
Validate: stdcli.Args(0),
})

register("rack runtimes", "list of attachable runtime integrations", RackRuntimes, stdcli.CommandOptions{
Flags: []stdcli.Flag{flagRack},
Validate: stdcli.Args(0),
})

register("rack runtime attach", "attach runtime integration", RackRuntimeAttach, stdcli.CommandOptions{
Flags: []stdcli.Flag{flagRack},
Validate: stdcli.Args(1),
})

register("rack scale", "scale the rack", RackScale, stdcli.CommandOptions{
Flags: []stdcli.Flag{
flagRack,
Expand Down Expand Up @@ -332,6 +342,70 @@ func RackReleases(rack sdk.Interface, c *stdcli.Context) error {
return t.Print()
}

func RackRuntimes(rack sdk.Interface, c *stdcli.Context) error {
host, err := currentHost(c)
if err != nil {
c.Fail(err)
}

rname := currentRack(c, host)

endpoint, err := currentEndpoint(c, "")
if err != nil {
return err
}

p, err := sdk.New(endpoint)
if err != nil {
return err
}

p.Authenticator = authenticator(c)
p.Session = currentSession(c)

rs, err := p.Runtimes(rname)
if err != nil {
return err
}

t := c.Table("ID", "TITLE")
for _, r := range rs {
t.AddRow(r.Id, r.Title)
}

return t.Print()
}

func RackRuntimeAttach(rack sdk.Interface, c *stdcli.Context) error {
host, err := currentHost(c)
if err != nil {
c.Fail(err)
}

rname := currentRack(c, host)

endpoint, err := currentEndpoint(c, "")
if err != nil {
return err
}

p, err := sdk.New(endpoint)
if err != nil {
return err
}

p.Authenticator = authenticator(c)
p.Session = currentSession(c)

if err := p.RuntimeAttach(rname, structs.RuntimeAttachOptions{
Runtime: &c.Args[0],
}); err != nil {
return err
}

return c.OK()
}

func RackScale(rack sdk.Interface, c *stdcli.Context) error {
s, err := rack.SystemGet()
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/structs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ type SystemUpdateOptions struct {
Type *string `param:"type"`
Version *string `param:"version"`
}

type Runtime struct {
Id string `json:"id"`
Title string `json:"title"`
}

type Runtimes []Runtime

type RuntimeAttachOptions struct {
Runtime *string `param:"runtime"`
}
4 changes: 4 additions & 0 deletions provider/aws/formation/rack.json
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,7 @@
] ] },
{ "Ref": "AWS::NoValue" }
] },
" - until yum install -y amazon-cloudwatch-agent; do echo \"Waiting for network\"; done;\n",
" - export http_proxy=", { "Ref": "HttpProxy" }, "\n",
" - echo http_proxy=", { "Ref": "HttpProxy" }, " >> /etc/environment\n",
" - export https_proxy=", { "Ref": "HttpProxy" }, "\n",
Expand Down Expand Up @@ -1796,6 +1797,7 @@
{ "Ref": "AWS::NoValue" }
] },
" - until yum install -y aws-cli nfs-utils; do echo \"Waiting for network\"; done;\n",
" - until yum install -y amazon-cloudwatch-agent; do echo \"Waiting for network\"; done;\n",
" - export IMDS_TOKEN=$(curl -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds:21600')\n",
" - mkdir /volumes\n",
{ "Fn::If": [ "RegionHasEFS",
Expand Down Expand Up @@ -1841,6 +1843,7 @@
" - ", { "Ref": "InstanceRunCommand" }, "\n"
] ] }
] },
" - sudo yum install -y amazon-cloudwatch-agent",
" - export IMDS_TOKEN=$(curl -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds:21600')\n",
" - export INSTANCE_ID=$(curl -s --noproxy 169.254.169.254 -H \"X-aws-ec2-metadata-token:$IMDS_TOKEN\" http://169.254.169.254/latest/meta-data/instance-id)\n",
" - export ASG_NAME=$(env $(cat /etc/environment) /usr/bin/aws autoscaling describe-auto-scaling-instances --instance-ids=$INSTANCE_ID --region ", {"Ref":"AWS::Region"}, " --output text --query 'AutoScalingInstances[0].AutoScalingGroupName')\n",
Expand Down Expand Up @@ -2288,6 +2291,7 @@
{ "Ref": "AWS::NoValue" }
] },
" - until yum install -y aws-cli nfs-utils; do echo \"Waiting for network\"; done;\n",
" - until yum install -y amazon-cloudwatch-agent; do echo \"Waiting for network\"; done;\n",
" - export IMDS_TOKEN=$(curl -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds:21600')\n",
" - mkdir /volumes\n",
{ "Fn::If": [ "RegionHasEFS",
Expand Down
25 changes: 25 additions & 0 deletions sdk/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,31 @@ func (c *Client) ResourceList(app string) (structs.Resources, error) {
return v, err
}

func (c *Client) Runtimes(rackOrgSlug string) (structs.Runtimes, error) {
var err error

ro := stdsdk.RequestOptions{Headers: stdsdk.Headers{}, Params: stdsdk.Params{}, Query: stdsdk.Query{}}

var v structs.Runtimes

err = c.Get(fmt.Sprintf("/racks/%s/runtimes", rackOrgSlug), ro, &v)

return v, err
}

func (c *Client) RuntimeAttach(rackOrgSlug string, opts structs.RuntimeAttachOptions) error {
var err error

ro, err := stdsdk.MarshalOptions(opts)
if err != nil {
return err
}

err = c.Put(fmt.Sprintf("/racks/%s/runtimes", rackOrgSlug), ro, nil)

return err
}

func (c *Client) ServiceList(app string) (structs.Services, error) {
var err error

Expand Down