-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pending_cluster_management status for embedded clusters
- Loading branch information
Craig O'Donnell
committed
Feb 21, 2024
1 parent
0a7a43a
commit d5b5a96
Showing
10 changed files
with
188 additions
and
21 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
pkg/handlers/embedded_cluster_confirm_cluster_management.go
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,95 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/replicatedhq/kots/pkg/kotsutil" | ||
"github.com/replicatedhq/kots/pkg/logger" | ||
"github.com/replicatedhq/kots/pkg/preflight" | ||
"github.com/replicatedhq/kots/pkg/store" | ||
storetypes "github.com/replicatedhq/kots/pkg/store/types" | ||
) | ||
|
||
type ConfirmEmbeddedClusterManagementResponse struct { | ||
VersionStatus string `json:"versionStatus"` | ||
} | ||
|
||
func (h *Handler) ConfirmEmbeddedClusterManagement(w http.ResponseWriter, r *http.Request) { | ||
apps, err := store.GetStore().ListInstalledApps() | ||
if err != nil { | ||
logger.Error(fmt.Errorf("failed to list installed apps: %w", err)) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
if len(apps) == 0 { | ||
logger.Error(fmt.Errorf("no installed apps found")) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
app := apps[0] | ||
|
||
downstreamVersions, err := store.GetStore().FindDownstreamVersions(app.ID, true) | ||
if err != nil { | ||
logger.Error(fmt.Errorf("failed to find downstream versions: %w", err)) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
if len(downstreamVersions.PendingVersions) == 0 { | ||
logger.Error(fmt.Errorf("no pending versions found")) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
pendingVersion := downstreamVersions.PendingVersions[0] | ||
|
||
if pendingVersion.Status == storetypes.VersionPendingClusterManagement { | ||
archiveDir, err := os.MkdirTemp("", "kotsadm") | ||
if err != nil { | ||
logger.Error(fmt.Errorf("failed to create temp dir: %w", err)) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
defer os.RemoveAll(archiveDir) | ||
|
||
err = store.GetStore().GetAppVersionArchive(app.ID, pendingVersion.Sequence, archiveDir) | ||
if err != nil { | ||
logger.Error(fmt.Errorf("failed to get app version archive: %w", err)) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
kotsKinds, err := kotsutil.LoadKotsKinds(archiveDir) | ||
if err != nil { | ||
logger.Error(fmt.Errorf("failed to load kots kinds: %w", err)) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
downstreamVersionStatus := storetypes.VersionPending | ||
if kotsKinds.IsConfigurable() { | ||
downstreamVersionStatus = storetypes.VersionPendingConfig | ||
} else if kotsKinds.HasPreflights() { | ||
downstreamVersionStatus = storetypes.VersionPendingPreflight | ||
if err := preflight.Run(app.ID, app.Slug, pendingVersion.Sequence, false, archiveDir); err != nil { | ||
logger.Error(errors.Wrap(err, "failed to start preflights")) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
} | ||
pendingVersion.Status = downstreamVersionStatus | ||
|
||
if err := store.GetStore().SetDownstreamVersionStatus(app.ID, pendingVersion.Sequence, pendingVersion.Status, ""); err != nil { | ||
logger.Error(fmt.Errorf("failed to set downstream version status: %w", err)) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
} | ||
|
||
JSON(w, http.StatusOK, ConfirmEmbeddedClusterManagementResponse{ | ||
VersionStatus: string(pendingVersion.Status), | ||
}) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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