feat(edge): kubernetes WaitForStatus support (#85)

pull/12292/merge
LP B 2024-11-11 14:02:20 +01:00 committed by GitHub
parent fd2b00bf3b
commit 6bc52dd39c
6 changed files with 34 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package portainer
import ( import (
"context" "context"
"fmt"
"io" "io"
"time" "time"
@ -1722,6 +1723,30 @@ const (
EdgeStackStatusCompleted EdgeStackStatusCompleted
) )
var edgeStackStatusTypeStr = map[EdgeStackStatusType]string{
EdgeStackStatusPending: "Pending",
EdgeStackStatusDeploymentReceived: "DeploymentReceived",
EdgeStackStatusError: "Error",
EdgeStackStatusAcknowledged: "Acknowledged",
EdgeStackStatusRemoved: "Removed",
EdgeStackStatusRemoteUpdateSuccess: "RemoteUpdateSuccess",
EdgeStackStatusImagesPulled: "ImagesPulled",
EdgeStackStatusRunning: "Running",
EdgeStackStatusDeploying: "Deploying",
EdgeStackStatusRemoving: "Removing",
EdgeStackStatusPausedDeploying: "PausedDeploying",
EdgeStackStatusRollingBack: "RollingBack",
EdgeStackStatusRolledBack: "RolledBack",
EdgeStackStatusCompleted: "Completed",
}
func (s EdgeStackStatusType) String() string {
if str, ok := edgeStackStatusTypeStr[s]; ok {
return fmt.Sprintf("%d (%s)", s, str)
}
return fmt.Sprintf("%d (UNKNOWN)", s)
}
const ( const (
_ EndpointStatus = iota _ EndpointStatus = iota
// EndpointStatusUp is used to represent an available environment(endpoint) // EndpointStatusUp is used to represent an available environment(endpoint)

View File

@ -22,7 +22,7 @@ export function DeploymentCounterLink({
<Link <Link
className="hover:no-underline" className="hover:no-underline"
to="edge.stacks.edit" to="edge.stacks.edit"
params={{ stackId, tab: 1, status: type }} params={{ stackId, tab: 'environments', status: type }}
data-cy="deployment-counter-link" data-cy="deployment-counter-link"
> >
<DeploymentCounter count={count} type={type} total={total} /> <DeploymentCounter count={count} type={type} total={total} />

View File

@ -104,7 +104,7 @@ export const columns = _.compact([
to="edge.stacks.edit" to="edge.stacks.edit"
params={{ params={{
stackId: row.original.Id, stackId: row.original.Id,
tab: 1, tab: 'environments',
status: StatusType.Error, status: StatusType.Error,
}} }}
data-cy={`edge-stacks-error-${row.original.Id}`} data-cy={`edge-stacks-error-${row.original.Id}`}

View File

@ -113,7 +113,7 @@ func aggregateStatuses(services []service) (libstack.Status, string) {
} }
func (wrapper *PluginWrapper) WaitForStatus(ctx context.Context, name string, status libstack.Status) <-chan libstack.WaitResult { func (wrapper *PluginWrapper) WaitForStatus(ctx context.Context, name string, status libstack.Status, _ string) <-chan libstack.WaitResult {
waitResultCh := make(chan libstack.WaitResult) waitResultCh := make(chan libstack.WaitResult)
waitResult := libstack.WaitResult{ waitResult := libstack.WaitResult{
Status: status, Status: status,
@ -200,6 +200,7 @@ func (wrapper *PluginWrapper) WaitForStatus(ctx context.Context, name string, st
log.Debug(). log.Debug().
Str("project_name", name). Str("project_name", name).
Str("required_status", string(status)).
Str("status", string(aggregateStatus)). Str("status", string(aggregateStatus)).
Msg("waiting for status") Msg("waiting for status")

View File

@ -66,7 +66,7 @@ func TestComposeProjectStatus(t *testing.T) {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
status, statusMessage, err := waitForStatus(w, ctx, projectName, libstack.StatusRunning) status, statusMessage, err := waitForStatus(w, ctx, projectName, libstack.StatusRunning, "")
if err != nil { if err != nil {
t.Fatalf("[test: %s] Failed to get compose project status: %v", testCase.TestName, err) t.Fatalf("[test: %s] Failed to get compose project status: %v", testCase.TestName, err)
} }
@ -86,7 +86,7 @@ func TestComposeProjectStatus(t *testing.T) {
time.Sleep(20 * time.Second) time.Sleep(20 * time.Second)
status, statusMessage, err = waitForStatus(w, ctx, projectName, libstack.StatusRemoved) status, statusMessage, err = waitForStatus(w, ctx, projectName, libstack.StatusRemoved, "")
if err != nil { if err != nil {
t.Fatalf("[test: %s] Failed to get compose project status: %v", testCase.TestName, err) t.Fatalf("[test: %s] Failed to get compose project status: %v", testCase.TestName, err)
} }
@ -102,11 +102,11 @@ func TestComposeProjectStatus(t *testing.T) {
} }
} }
func waitForStatus(deployer libstack.Deployer, ctx context.Context, stackName string, requiredStatus libstack.Status) (libstack.Status, string, error) { func waitForStatus(deployer libstack.Deployer, ctx context.Context, stackName string, requiredStatus libstack.Status, stackFileLocation string) (libstack.Status, string, error) {
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute) ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel() defer cancel()
statusCh := deployer.WaitForStatus(ctx, stackName, requiredStatus) statusCh := deployer.WaitForStatus(ctx, stackName, requiredStatus, stackFileLocation)
result := <-statusCh result := <-statusCh
if result.ErrorMsg == "" { if result.ErrorMsg == "" {
return result.Status, "", nil return result.Status, "", nil

View File

@ -14,7 +14,7 @@ type Deployer interface {
Pull(ctx context.Context, filePaths []string, options Options) error Pull(ctx context.Context, filePaths []string, options Options) error
Run(ctx context.Context, filePaths []string, serviceName string, options RunOptions) error Run(ctx context.Context, filePaths []string, serviceName string, options RunOptions) error
Validate(ctx context.Context, filePaths []string, options Options) error Validate(ctx context.Context, filePaths []string, options Options) error
WaitForStatus(ctx context.Context, name string, status Status) <-chan WaitResult WaitForStatus(ctx context.Context, name string, status Status, stackFileLocation string) <-chan WaitResult
Config(ctx context.Context, filePaths []string, options Options) ([]byte, error) Config(ctx context.Context, filePaths []string, options Options) ([]byte, error)
} }