-
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.
feat: add support for embedded cluster updates
TBD
- Loading branch information
1 parent
d505141
commit aaa2496
Showing
9 changed files
with
255 additions
and
5 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 |
---|---|---|
|
@@ -71,3 +71,5 @@ spec: | |
type: text | ||
- name: branding_archive | ||
type: text | ||
- name: embeddedcluster_config | ||
type: text |
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,118 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
"github.com/replicatedhq/kots/pkg/embeddedcluster" | ||
"github.com/replicatedhq/kots/pkg/k8sutil" | ||
"github.com/replicatedhq/kots/pkg/logger" | ||
"github.com/replicatedhq/kots/pkg/store" | ||
) | ||
|
||
// EmbeddedClusterUpdateCheckResponse is the response of the cluster update check. Contains the app | ||
// slug the the verison to upgrade to. | ||
type EmbeddedClusterUpdateCheckResponse struct { | ||
Slug string `json:"app"` | ||
Version string `json:"version"` | ||
} | ||
|
||
// EmbeddedClusterUpdateCheck is a handler func that checks if an update is available for the embedded | ||
// cluster and returns the version to upgrade to if so. | ||
func (h *Handler) EmbeddedClusterUpdateCheck(w http.ResponseWriter, r *http.Request) { | ||
errout := func(err error) { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} | ||
ctx := r.Context() | ||
appSlug := mux.Vars(r)["appSlug"] | ||
client, err := k8sutil.GetClientset() | ||
if err != nil { | ||
errout(err) | ||
return | ||
} | ||
if isEmbeddedCluster, err := embeddedcluster.IsEmbeddedCluster(client); err != nil { | ||
errout(err) | ||
return | ||
} else if !isEmbeddedCluster { | ||
w.WriteHeader(http.StatusNoContent) | ||
return | ||
} | ||
app, err := store.GetStore().GetAppFromSlug(appSlug) | ||
if err != nil { | ||
errout(err) | ||
return | ||
} | ||
version, err := store.GetStore().GetAppVersion(app.ID, app.CurrentSequence) | ||
if err != nil { | ||
errout(err) | ||
return | ||
} | ||
if version.KOTSKinds == nil || version.KOTSKinds.EmbeddedClusterConfig == nil { | ||
w.WriteHeader(http.StatusNoContent) | ||
return | ||
} | ||
upgrade, err := embeddedcluster.RequiresUpgrade(ctx, version.KOTSKinds.EmbeddedClusterConfig.Spec) | ||
if err != nil { | ||
errout(err) | ||
return | ||
} | ||
if !upgrade { | ||
w.WriteHeader(http.StatusNoContent) | ||
return | ||
} | ||
JSON(w, http.StatusOK, EmbeddedClusterUpdateCheckResponse{ | ||
Slug: app.Slug, | ||
Version: version.KOTSKinds.EmbeddedClusterConfig.Spec.Version, | ||
}) | ||
} | ||
|
||
func (h *Handler) StartClusterUpdate(w http.ResponseWriter, r *http.Request) { | ||
errout := func(err error) { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} | ||
ctx := r.Context() | ||
appSlug := mux.Vars(r)["appSlug"] | ||
client, err := k8sutil.GetClientset() | ||
if err != nil { | ||
errout(err) | ||
return | ||
} | ||
if isEmbeddedCluster, err := embeddedcluster.IsEmbeddedCluster(client); err != nil { | ||
errout(err) | ||
return | ||
} else if !isEmbeddedCluster { | ||
w.WriteHeader(http.StatusNoContent) | ||
return | ||
} | ||
app, err := store.GetStore().GetAppFromSlug(appSlug) | ||
if err != nil { | ||
errout(err) | ||
return | ||
} | ||
version, err := store.GetStore().GetAppVersion(app.ID, app.CurrentSequence) | ||
if err != nil { | ||
errout(err) | ||
return | ||
} | ||
if version.KOTSKinds == nil || version.KOTSKinds.EmbeddedClusterConfig == nil { | ||
w.WriteHeader(http.StatusNoContent) | ||
return | ||
} | ||
upgrade, err := embeddedcluster.RequiresUpgrade(ctx, version.KOTSKinds.EmbeddedClusterConfig.Spec) | ||
if err != nil { | ||
errout(err) | ||
return | ||
} | ||
if !upgrade { | ||
w.WriteHeader(http.StatusNoContent) | ||
return | ||
} | ||
if err := embeddedcluster.StartClusterUpdate(ctx, version.KOTSKinds.EmbeddedClusterConfig.Spec); err != nil { | ||
errout(err) | ||
return | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
} |
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
Oops, something went wrong.