Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade service preflights api #4693

Merged
merged 34 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
db807eb
KOTS upgrader
sgalsaleh May 20, 2024
d2614a6
updates
sgalsaleh May 21, 2024
60f11fd
save
sgalsaleh May 21, 2024
1130b39
save
sgalsaleh May 21, 2024
a72536a
save
sgalsaleh May 21, 2024
4b8490a
save
sgalsaleh May 22, 2024
d51befd
save
sgalsaleh May 22, 2024
295e881
save
sgalsaleh May 22, 2024
11d93ff
save
sgalsaleh May 23, 2024
9089dbe
save
sgalsaleh May 23, 2024
0b96bf6
save
sgalsaleh May 23, 2024
7edd3d8
save
sgalsaleh May 23, 2024
7b77629
rename to upgrade service
sgalsaleh Jun 11, 2024
15ef89d
update pkg name
sgalsaleh Jun 11, 2024
df99ab4
add available updates api endpoint (#4677)
Jun 11, 2024
be60914
move tasks outside the store
sgalsaleh Jun 11, 2024
b38a8f1
Use params file
sgalsaleh Jun 12, 2024
91e6a9c
Embedded Cluster: Show available updates in the UI (#4680)
miaawong Jun 13, 2024
bb1c47c
allow same origin iframing in kurl proxy (#4682)
Jun 13, 2024
7c017bc
upgrade service lifecycle
sgalsaleh Jun 13, 2024
5b96922
required releases
sgalsaleh Jun 14, 2024
a42e73a
remove comment
sgalsaleh Jun 14, 2024
b3a8bac
make it more readable
sgalsaleh Jun 14, 2024
811cef9
remove comment
sgalsaleh Jun 14, 2024
604ccc3
remove comments
sgalsaleh Jun 14, 2024
28b553e
enforce required releases in api
sgalsaleh Jun 14, 2024
b4deb57
save config api for upgrade service (#4681)
Jun 14, 2024
120426c
check if license id changed
sgalsaleh Jun 15, 2024
289b309
download config file (#4691)
Jun 17, 2024
ae26b69
get preflight result endpoint
Jun 17, 2024
6b419b9
start preflights endpoint
Jun 17, 2024
dbd8cd0
use os.RemoveAll
Jun 17, 2024
7a4d7bb
address PR feedback
Jun 17, 2024
3310322
Merge branch 'kots-upgrader' into cbo/sc-105495/upgrade-service-prefl…
Jun 18, 2024
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
2 changes: 1 addition & 1 deletion .github/actions/copy-assets/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 as builder
FROM golang:1.22 as builder
WORKDIR /action
COPY . /action

Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ kots: capture-start-time kots-real report-metric

.PHONY: kots-real
kots-real:
mkdir -p web/dist
touch web/dist/README.md
go build ${LDFLAGS} -o bin/kots $(BUILDFLAGS) github.com/replicatedhq/kots/cmd/kots

.PHONY: fmt
Expand Down Expand Up @@ -80,7 +82,7 @@ build: capture-start-time build-real report-metric
.PHONY: build-real
build-real:
mkdir -p web/dist
touch web/dist/THIS_IS_OKTETO # we need this for go:embed, but it's not actually used in dev
touch web/dist/README.md
go build ${LDFLAGS} ${GCFLAGS} -v -o bin/kotsadm $(BUILDFLAGS) ./cmd/kotsadm

.PHONY: tidy
Expand Down Expand Up @@ -112,9 +114,12 @@ debug-build:
debug: debug-build
LOG_LEVEL=$(LOG_LEVEL) dlv --listen=:2345 --headless=true --api-version=2 exec ./bin/kotsadm-debug api

.PHONY: build-ttl.sh
build-ttl.sh: kots build
.PHONY: web
web:
source .image.env && ${MAKE} -C web build-kotsadm

.PHONY: build-ttl.sh
build-ttl.sh: web kots build
docker build -f deploy/Dockerfile -t ttl.sh/${CURRENT_USER}/kotsadm:24h .
docker push ttl.sh/${CURRENT_USER}/kotsadm:24h

Expand Down
6 changes: 3 additions & 3 deletions cmd/kots/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
"github.com/replicatedhq/kots/pkg/print"
"github.com/replicatedhq/kots/pkg/pull"
"github.com/replicatedhq/kots/pkg/replicatedapp"
"github.com/replicatedhq/kots/pkg/store/kotsstore"
storetypes "github.com/replicatedhq/kots/pkg/store/types"
"github.com/replicatedhq/kots/pkg/tasks"
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
"github.com/replicatedhq/troubleshoot/pkg/preflight"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -887,7 +887,7 @@ func ValidateAutomatedInstall(deployOptions kotsadmtypes.DeployOptions, authSlug
return "", errors.New("timeout waiting for automated install. Use the --wait-duration flag to increase timeout.")
}

func getAutomatedInstallStatus(url string, authSlug string) (*kotsstore.TaskStatus, error) {
func getAutomatedInstallStatus(url string, authSlug string) (*tasks.TaskStatus, error) {
newReq, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, errors.Wrap(err, "failed to create request")
Expand All @@ -910,7 +910,7 @@ func getAutomatedInstallStatus(url string, authSlug string) (*kotsstore.TaskStat
return nil, errors.Wrap(err, "failed to read response body")
}

taskStatus := kotsstore.TaskStatus{}
taskStatus := tasks.TaskStatus{}
if err := json.Unmarshal(b, &taskStatus); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal task status")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/kots/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func RootCmd() *cobra.Command {
cmd.AddCommand(CompletionCmd())
cmd.AddCommand(DockerRegistryCmd())
cmd.AddCommand(EnableHACmd())
cmd.AddCommand(UpgradeServiceCmd())

viper.BindPFlags(cmd.Flags())

Expand Down
78 changes: 78 additions & 0 deletions cmd/kots/cli/upgrade-service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cli

import (
"fmt"
"io"
"os"

"github.com/replicatedhq/kots/pkg/upgradeservice"
"github.com/replicatedhq/kots/pkg/upgradeservice/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v3"
)

func UpgradeServiceCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "upgrade-service",
Short: "KOTS Upgrade Service",
Hidden: true,
}

cmd.AddCommand(UpgradeServiceStartCmd())

return cmd
}

func UpgradeServiceStartCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "start [params-file]",
Short: "Starts a KOTS upgrade service using the provided params file",
Long: ``,
SilenceUsage: true,
SilenceErrors: false,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
os.Setenv("IS_UPGRADE_SERVICE", "true")
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
cmd.Help()
os.Exit(1)
}

paramsYAML, err := readUpgradeServiceParams(args[0])
if err != nil {
return fmt.Errorf("failed to read config file: %v", err)
}

var params types.UpgradeServiceParams
if err := yaml.Unmarshal(paramsYAML, &params); err != nil {
return fmt.Errorf("failed to unmarshal config file: %v", err)
}

if err := upgradeservice.Serve(params); err != nil {
return err
}

return nil
},
}

return cmd
}

func readUpgradeServiceParams(path string) ([]byte, error) {
if path == "-" {
b, err := io.ReadAll(os.Stdin)
if err != nil {
return nil, fmt.Errorf("read stdin: %w", err)
}
return b, nil
}
b, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("read file: %w", err)
}
return b, nil
}
41 changes: 12 additions & 29 deletions cmd/kots/cli/version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cli

import (
"encoding/json"
"fmt"
"log"
"net/http"

"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/buildversion"
"github.com/gorilla/mux"
"github.com/replicatedhq/kots/pkg/handlers"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -25,37 +26,19 @@ func VersionCmd() *cobra.Command {
viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
r := mux.NewRouter()

output := v.GetString("output")
spa := handlers.SPAHandler{}
r.PathPrefix("/").Handler(spa)

isLatest, latestVer, err := buildversion.IsLatestRelease()
versionOutput := VersionOutput{
Version: buildversion.Version(),
}
if err == nil && !isLatest {
versionOutput.LatestVersion = latestVer
versionOutput.InstallLatest = "curl https://kots.io/install | bash"
srv := &http.Server{
Handler: r,
Addr: ":30888",
}

if output != "json" && output != "" {
return errors.Errorf("output format %s not supported (allowed formats are: json)", output)
} else if output == "json" {
// marshal JSON
outputJSON, err := json.Marshal(versionOutput)
if err != nil {
return errors.Wrap(err, "error marshaling JSON")
}
fmt.Println(string(outputJSON))
} else {
// print basic version info
fmt.Printf("Replicated KOTS %s\n", buildversion.Version())
fmt.Printf("Starting KOTS SPA handler on port %d...\n", 30888)

// check if this is the latest release, and display possible upgrade instructions
if versionOutput.LatestVersion != "" {
fmt.Printf("\nVersion %s is available for kots. To install updates, run\n $ %s\n", versionOutput.LatestVersion, versionOutput.InstallLatest)
}
}
log.Fatal(srv.ListenAndServe())

return nil
},
Expand Down
1 change: 0 additions & 1 deletion hack/dev/skaffold.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM kotsadm:cache AS builder

ENV PROJECTPATH=/go/src/github.com/replicatedhq/kots
WORKDIR $PROJECTPATH
RUN mkdir -p web/dist && touch web/dist/README.md
COPY Makefile ./
COPY Makefile.build.mk ./
COPY go.mod go.sum ./
Expand Down
1 change: 0 additions & 1 deletion hack/dev/skaffoldcache.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ RUN go install github.com/go-delve/delve/cmd/[email protected]

ENV PROJECTPATH=/go/src/github.com/replicatedhq/kots
WORKDIR $PROJECTPATH
RUN mkdir -p web/dist && touch web/dist/README.md
COPY Makefile ./
COPY Makefile.build.mk ./
COPY go.mod go.sum ./
Expand Down
4 changes: 2 additions & 2 deletions kurl_proxy/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ func getHttpsServer(upstream, dexUpstream *url.URL, tlsSecretName string, secret

// CSPMiddleware adds Content-Security-Policy and X-Frame-Options headers to the response.
func CSPMiddleware(c *gin.Context) {
c.Writer.Header().Set("Content-Security-Policy", "frame-ancestors 'none';")
c.Writer.Header().Set("X-Frame-Options", "DENY")
c.Writer.Header().Set("Content-Security-Policy", "frame-ancestors 'self';")
c.Writer.Header().Set("X-Frame-Options", "SAMEORIGIN")
c.Next()
}

Expand Down
22 changes: 11 additions & 11 deletions kurl_proxy/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func Test_httpServerCSPHeaders(t *testing.T) {
httpServer: getHttpServer("some-fingerprint", true, tmpDir),
path: "/assets/index.html",
wantHeaders: map[string]string{
"Content-Security-Policy": "frame-ancestors 'none';",
"X-Frame-Options": "DENY",
"Content-Security-Policy": "frame-ancestors 'self';",
"X-Frame-Options": "SAMEORIGIN",
},
},
{
Expand All @@ -191,8 +191,8 @@ func Test_httpServerCSPHeaders(t *testing.T) {
isHttps: true,
path: "/tls/assets/index.html",
wantHeaders: map[string]string{
"Content-Security-Policy": "frame-ancestors 'none';",
"X-Frame-Options": "DENY",
"Content-Security-Policy": "frame-ancestors 'self';",
"X-Frame-Options": "SAMEORIGIN",
},
},
}
Expand Down Expand Up @@ -275,15 +275,15 @@ func Test_generateDefaultCertSecret(t *testing.T) {

func Test_generateCertHostnames(t *testing.T) {
tests := []struct {
name string
name string
namespace string
hostname string
altNames []string
altNames []string
}{
{
name: "with no namespace",
hostname: "kotsadm.default.svc.cluster.local",
altNames : []string{
name: "with no namespace",
hostname: "kotsadm.default.svc.cluster.local",
altNames: []string{
"kotsadm",
"kotsadm.default",
"kotsadm.default.svc",
Expand All @@ -292,10 +292,10 @@ func Test_generateCertHostnames(t *testing.T) {
},
},
{
name: "with some other namespace",
name: "with some other namespace",
namespace: "somecluster",
hostname: "kotsadm.default.svc.cluster.local",
altNames : []string{
altNames: []string{
"kotsadm",
"kotsadm.default",
"kotsadm.default.svc",
Expand Down
2 changes: 1 addition & 1 deletion kurl_proxy/skaffold.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-bookworm
FROM golang:1.22-bookworm

ENV PROJECTPATH=/go/src/github.com/replicatedhq/kots/kurl_proxy
WORKDIR $PROJECTPATH
Expand Down
66 changes: 0 additions & 66 deletions migrations/tables/instance-report.yaml

This file was deleted.

Loading
Loading