-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(k8s): add wait and status color to k8s node
Signed-off-by: Patrik Cyvoct <pcyvoct@scaleway.com>
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package k8s | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/fatih/color" | ||
"github.com/scaleway/scaleway-cli/internal/core" | ||
"github.com/scaleway/scaleway-cli/internal/human" | ||
k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1beta4" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
const ( | ||
nodeActionTimeout = 10 * time.Minute | ||
) | ||
|
||
// | ||
// Marshalers | ||
// | ||
|
||
// nodeStatusMarshalerFunc marshals a k8s.ClusterStatus. | ||
var ( | ||
nodeStatusAttributes = human.Attributes{ | ||
k8s.NodeStatusCreating: color.FgBlue, | ||
k8s.NodeStatusRebooting: color.FgBlue, | ||
k8s.NodeStatusReady: color.FgGreen, | ||
k8s.NodeStatusNotready: color.FgYellow, | ||
k8s.NodeStatusCreationError: color.FgRed, | ||
k8s.NodeStatusLocked: color.FgRed, | ||
k8s.NodeStatusWarning: color.FgHiYellow, | ||
} | ||
) | ||
|
||
const ( | ||
nodeActionReboot = iota | ||
) | ||
|
||
func nodeRebootBuilder(c *core.Command) *core.Command { | ||
c.WaitFunc = waitForNodeFunc(nodeActionReboot) | ||
return c | ||
} | ||
|
||
func waitForNodeFunc(action int) core.WaitFunc { | ||
return func(ctx context.Context, _, respI interface{}) (interface{}, error) { | ||
node, err := k8s.NewAPI(core.ExtractClient(ctx)).WaitForNode(&k8s.WaitForNodeRequest{ | ||
Region: respI.(*k8s.Node).Region, | ||
NodeID: respI.(*k8s.Node).ID, | ||
Timeout: scw.DurationPtr(nodeActionTimeout), | ||
}) | ||
switch action { | ||
case nodeActionReboot: | ||
return node, err | ||
} | ||
return nil, err | ||
} | ||
} |