Skip to content
Open
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
44 changes: 2 additions & 42 deletions provider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fpoc

import (
"bytes"
"context"
"errors"
"fmt"
Expand All @@ -19,7 +18,6 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/jinzhu/copier"

"gitlab.com/gitlab-org/fleeting/fleeting/connector"
"gitlab.com/gitlab-org/fleeting/fleeting/provider"
)

Expand Down Expand Up @@ -140,25 +138,7 @@ func (g *InstanceGroup) Update(ctx context.Context, update func(instance string,
}

case "ACTIVE":
if srv.Created.Add(g.BootTime).Before(time.Now()) {
// treat all nodes running long enough as Running
state = provider.StateRunning
} else {
log, err := servers.ShowConsoleOutput(ctx, g.computeClient, srv.ID, servers.ShowConsoleOutputOpts{
Length: 100,
}).Extract()
if err != nil {
reterr = errors.Join(reterr, err)
continue
}

if IsCloudInitFinished(log) {
g.log.Debug("Instance cloud-init finished", "server_id", srv.ID, "created", srv.Created)
state = provider.StateRunning
} else {
g.log.Debug("Instance boot time not passed and cloud-init not finished", "server_id", srv.ID, "created", srv.Created, "boot_time", g.BootTime)
}
}
state = provider.StateRunning
}

update(srv.ID, state)
Expand Down Expand Up @@ -232,7 +212,7 @@ func (g *InstanceGroup) getInstances(ctx context.Context, initial bool) ([]serve
size := len(filteredServers)

if !initial && size != g.size {
g.log.Error("out-of-sync capacity", "expected", g.size, "actual", size)
g.log.Info("out-of-sync capacity", "expected", g.size, "actual", size)
}
g.size = size

Expand Down Expand Up @@ -318,26 +298,6 @@ func (g *InstanceGroup) ConnectInfo(ctx context.Context, instanceID string) (pro
return info, nil
}

inp := bytes.NewBuffer(nil)
combinedOut := bytes.NewBuffer(nil)

ropts := connector.ConnectorOptions{
DialOptions: connector.DialOptions{
// UseExternalAddr: true,
},
RunOptions: connector.RunOptions{
Command: `echo "ok"`,
Stdin: inp,
Stdout: combinedOut,
Stderr: combinedOut,
},
}
err = connector.Run(ctx, info, ropts)
if err != nil {
return provider.ConnectInfo{}, fmt.Errorf("Failed to test ssh: %w", err)
}
g.log.Debug("SSH test result", "out", combinedOut.String())

return info, nil
}

Expand Down
12 changes: 4 additions & 8 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fpoc
import (
"maps"
"regexp"
"slices"
"strings"

"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
Expand All @@ -25,7 +26,7 @@ type ExtCreateOpts struct {
}

// ToServerCreateMap for extended opts
func (opts ExtCreateOpts) ToServerCreateMap() (map[string]interface{}, error) {
func (opts ExtCreateOpts) ToServerCreateMap() (map[string]any, error) {
if opts.Networks != nil {
opts.CreateOpts.Networks = opts.Networks
}
Expand Down Expand Up @@ -79,7 +80,7 @@ func extractAddresses(srv *servers.Server) (map[string][]Address, error) {
ret := make(map[string][]Address, len(srv.Addresses))

for net, isv := range srv.Addresses {
ism := isv.([]interface{})
ism := isv.([]any)
items := make([]Address, 0, len(ism))

for _, iv := range ism {
Expand Down Expand Up @@ -110,10 +111,5 @@ var initFinishedRe = regexp.MustCompile(`^.*Cloud-init\ v\.\ \d+\.\d+\.\d+\ fini
func IsCloudInitFinished(log string) bool {
lines := strings.Split(log, "\n")

for _, line := range lines {
if initFinishedRe.MatchString(line) {
return true
}
}
return false
return slices.ContainsFunc(lines, initFinishedRe.MatchString)
}
2 changes: 1 addition & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestExtCreateOpts(t *testing.T) {
}
`

expected := `{"os:scheduler_hints":{"group":"a5b557be-b7f0-4cb3-8f7c-6b5092f29c2c"},"server":{"description":"podman instance","flavorRef":"5","imageRef":"f2403879-6fbe-49a0-b71f-54b70039f32a","key_name":"gitlab-autoscaler","metadata":{"foo":"bar"},"name":"gitlab-runner-%d","networks":[{"uuid":"c487d046-80ad-4da0-8b98-4a48ad3c257a"}],"security_groups":[{"name":"allow_gitlab_runner"}],"tags":["podman","CI"],"user_data":"IyFjbG91ZC1jb25maWcKcGFja2FnZV91cGRhdGU6IHRydWUKcGFja2FnZV91cGdyYWRlOiB0cnVlCg=="}}`
expected := `{"server":{"description":"podman instance","flavorRef":"5","imageRef":"f2403879-6fbe-49a0-b71f-54b70039f32a","key_name":"gitlab-autoscaler","metadata":{"foo":"bar"},"name":"gitlab-runner-%d","networks":[{"uuid":"c487d046-80ad-4da0-8b98-4a48ad3c257a"}],"security_groups":[{"name":"allow_gitlab_runner"}],"tags":["podman","CI"],"user_data":"IyFjbG91ZC1jb25maWcKcGFja2FnZV91cGRhdGU6IHRydWUKcGFja2FnZV91cGdyYWRlOiB0cnVlCg=="}}`

cfg := new(ExtCreateOpts)
err := json.Unmarshal([]byte(cfgJSON), cfg)
Expand Down
Loading