Skip to content

Commit

Permalink
Fixes for findings while testing the upgrade path from v0.26.0 => v1.…
Browse files Browse the repository at this point in the history
…0.0 (#870)
  • Loading branch information
laszlocph authored Sep 13, 2024
1 parent a17abaa commit dd0e2e0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pkg/dashboard/server/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func MustUser() func(next http.Handler) http.Handler {
ctx := r.Context()
_, userSet := ctx.Value("user").(*model.User)
if !userSet {
if r.URL.Path == "/settings/installed" {
if r.URL.Path == "/installed" {
http.Redirect(w, r, "/auth?"+r.URL.RawQuery, http.StatusSeeOther)
}
http.Error(w, http.StatusText(401), 401)
Expand Down
39 changes: 27 additions & 12 deletions web/src/views/deployWizzard/deployWizzard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export function DeployWizzard(props) {

const deployHandler = new DeployHandler(owner, repo, gimletClient, store)

const [registries, setRegistries] = useState()
const [preferredDomain, setPreferredDomain] = useState()
const [ingressAnnotations, setIngressAnnotations] = useState()
const [stackConfigDerivedValues, setStackConfigDerivedValues] = useState()

store.subscribe(() => {
setEnvs(reduxState.envs)
Expand Down Expand Up @@ -87,9 +85,12 @@ export function DeployWizzard(props) {
useEffect(() => {
gimletClient.getStackConfig(env)
.then(data => {
setRegistries(configuredRegistries(data.stackConfig, data.stackDefinition))
setPreferredDomain(extractPreferredDomain(data.stackConfig, data.stackDefinition))
setIngressAnnotations(extractIngressAnnotations(data.stackConfig, data.stackDefinition))
setStackConfigDerivedValues({
"registries": configuredRegistries(data.stackConfig, data.stackDefinition),
"preferredDomain": extractPreferredDomain(data.stackConfig, data.stackDefinition),
"ingressAnnotations": extractIngressAnnotations(data.stackConfig, data.stackDefinition),
}
)
}, () => {/* Generic error handler deals with it */ });

gimletClient.getDefaultDeploymentTemplates()
Expand Down Expand Up @@ -205,22 +206,36 @@ export function DeployWizzard(props) {
}

useEffect(() => {
if(!selectedTemplate || !registries) {
if(!selectedTemplate || !stackConfigDerivedValues) {
return
}

setPatchedTemplate(patchUIWidgets(selectedTemplate, registries, preferredDomain))
}, [selectedTemplate, registries, preferredDomain]);
setPatchedTemplate(
patchUIWidgets(selectedTemplate, stackConfigDerivedValues.registries, stackConfigDerivedValues.preferredDomain)
)
}, [selectedTemplate, stackConfigDerivedValues]);

useEffect(() => {
if(!selectedTemplate || !preferredDomain || !ingressAnnotations) {
if(!selectedTemplate || !stackConfigDerivedValues) {
return
}

setConfigFile(newConfig(configFile ? configFile.app : repo, configFile ? configFile.namespace : "default", env, selectedTemplate.reference.chart, repoName, preferredDomain, settings.scmUrl, ingressAnnotations, false))
setConfigFile(
newConfig(
configFile ? configFile.app : repo,
configFile ? configFile.namespace : "default",
env,
selectedTemplate.reference.chart,
repoName,
stackConfigDerivedValues.preferredDomain,
settings.scmUrl,
stackConfigDerivedValues.ingressAnnotations,
false
)
)
setDefaultConfigFile({})
setRenderId(uuidv4())
}, [selectedTemplate, preferredDomain, ingressAnnotations]);
}, [selectedTemplate, stackConfigDerivedValues]);

// useEffect(() => {
// console.log(configFile)
Expand Down
76 changes: 46 additions & 30 deletions web/src/views/envConfig/envConfig.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export function EnvConfig(props) {
const [navigation, setNavigation] = useState([])
const [showModal, setShowModal] = useState(false)

const [registries, setRegistries] = useState()
const [preferredDomain, setPreferredDomain] = useState()
const [ingressAnnotations, setIngressAnnotations] = useState()
const [stackConfigDerivedValues, setStackConfigDerivedValues] = useState()
const [templateLoadError, setTemplateLoadError] = useState(false)

store.subscribe(() => {
Expand All @@ -52,9 +50,12 @@ export function EnvConfig(props) {
useEffect(() => {
gimletClient.getStackConfig(env)
.then(data => {
setRegistries(configuredRegistries(data.stackConfig, data.stackDefinition))
setPreferredDomain(extractPreferredDomain(data.stackConfig, data.stackDefinition))
setIngressAnnotations(extractIngressAnnotations(data.stackConfig, data.stackDefinition))
setStackConfigDerivedValues({
"registries": configuredRegistries(data.stackConfig, data.stackDefinition),
"preferredDomain": extractPreferredDomain(data.stackConfig, data.stackDefinition),
"ingressAnnotations": extractIngressAnnotations(data.stackConfig, data.stackDefinition),
}
)
}, () => {/* Generic error handler deals with it */ });

gimletClient.getRepoMetas(owner, repo)
Expand Down Expand Up @@ -99,12 +100,12 @@ export function EnvConfig(props) {
}, []);

useEffect(() => {
if(!selectedTemplate || !registries) {
if(!selectedTemplate || !stackConfigDerivedValues) {
return
}

setPatchedTemplate(patchUIWidgets(selectedTemplate, registries, preferredDomain))
}, [selectedTemplate, registries, preferredDomain]);
setPatchedTemplate(patchUIWidgets(selectedTemplate, stackConfigDerivedValues.registries, stackConfigDerivedValues.preferredDomain))
}, [selectedTemplate, stackConfigDerivedValues]);

useEffect(() => {
if (configFile && configFile.values.ingress) {
Expand All @@ -117,8 +118,8 @@ export function EnvConfig(props) {
...prevState.values.ingress,
annotations: {
...prevState.values.ingress.annotations,
"nginx.ingress.kubernetes.io/auth-url": "https://auth"+preferredDomain+"/oauth2/auth",
"nginx.ingress.kubernetes.io/auth-signin": "https://auth"+preferredDomain+"/oauth2/start?rd=/redirect/$http_host$escaped_request_uri",
"nginx.ingress.kubernetes.io/auth-url": "https://auth"+stackConfigDerivedValues.preferredDomain+"/oauth2/auth",
"nginx.ingress.kubernetes.io/auth-signin": "https://auth"+stackConfigDerivedValues.preferredDomain+"/oauth2/start?rd=/redirect/$http_host$escaped_request_uri",
}
}
},
Expand All @@ -133,7 +134,7 @@ export function EnvConfig(props) {
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [configFile && configFile.values.ingress && configFile.values.ingress.protectWithOauthProxy, preferredDomain])
}, [configFile && configFile.values.ingress && configFile.values.ingress.protectWithOauthProxy, stackConfigDerivedValues])

const setAppName = (appName) => {
setConfigFile(prevState => ({
Expand Down Expand Up @@ -326,17 +327,29 @@ export function EnvConfig(props) {
}

useEffect(() => {
if(!selectedTemplate || !preferredDomain || !ingressAnnotations) {
if(!selectedTemplate || !stackConfigDerivedValues) {
return
}

if (action === "new-preview") {
setConfigFile(newConfig(configFile ? configFile.app : config, configFile ? configFile.namespace : "default", env, selectedTemplate.reference.chart, repoName, preferredDomain, scmUrl, ingressAnnotations, true))
setConfigFile(
newConfig(
configFile ? configFile.app : config,
configFile ? configFile.namespace : "default",
env,
selectedTemplate.reference.chart,
repoName,
stackConfigDerivedValues.preferredDomain,
scmUrl,
stackConfigDerivedValues.ingressAnnotations,
true
)
)
setSavedConfigFile({})
}

setNavigation(translateToNavigation(selectedTemplate))
}, [selectedTemplate, preferredDomain, ingressAnnotations]);
}, [selectedTemplate, stackConfigDerivedValues]);


const setDeploymentTemplate = (template) => {
Expand Down Expand Up @@ -678,24 +691,14 @@ export function robustName(str) {
}

export function newConfig(configName, namespace, env, chartRef, repoName, preferredDomain, scmUrl, ingressAnnotations, preview) {
let sanitizedRepoName = robustName(repoName)
sanitizedRepoName = sanitizedRepoName.length > 55 ? sanitizedRepoName.slice(0, 55) : sanitizedRepoName

const config = {
app: configName,
namespace: namespace,
env: env,
chart: chartRef,
values: {
gitRepository: repoName,
gitSha: "{{ .SHA }}",
ingress: {
host: `${sanitizedRepoName}${preferredDomain}`,
tlsEnabled: true,
annotations: {
...ingressAnnotations
}
}
gitSha: "{{ .SHA }}"
},
}

Expand All @@ -704,10 +707,10 @@ export function newConfig(configName, namespace, env, chartRef, repoName, prefer

if (oneChart && !staticSite) {
config.values.image = {
repository: "127.0.0.1:32447/{{ .APP }}",
tag: "{{ .SHA }}",
strategy: "buildpacks",
registry: "dockerRegistry",
repository: "nginx",
tag: "1.27",
strategy: "static",
registry: "public",
}
config.values.resources = {
ignoreLimits: true,
Expand All @@ -722,6 +725,19 @@ export function newConfig(configName, namespace, env, chartRef, repoName, prefer
config.preview = true
}

if (preferredDomain) {
let sanitizedRepoName = robustName(repoName)
sanitizedRepoName = sanitizedRepoName.length > 55 ? sanitizedRepoName.slice(0, 55) : sanitizedRepoName

config.values.ingress = {
host: `${sanitizedRepoName}${preferredDomain}`,
tlsEnabled: true,
annotations: {
...ingressAnnotations
}
}
}

return config
}

Expand Down
6 changes: 3 additions & 3 deletions web/src/views/envConfig/imageWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function ImageWidget(props) {
setImage({
...image,
"strategy": strategy,
"registry": "dockerRegistry",
"registry": "containerizedRegistry",
"repository": "127.0.0.1:32447/{{ .APP }}",
"tag": "{{ .SHA }}",
"dockerfile": "Dockerfile"
Expand All @@ -51,7 +51,7 @@ export default function ImageWidget(props) {
setImage({
...image,
"strategy": strategy,
"registry": "dockerRegistry",
"registry": "containerizedRegistry",
"repository": "127.0.0.1:32447/{{ .APP }}",
"tag": "{{ .SHA }}",
"dockerfile": ""
Expand All @@ -63,7 +63,7 @@ export default function ImageWidget(props) {
"strategy": strategy,
"registry": "public",
"repository": "nginx",
"tag": "1.25",
"tag": "1.27",
"dockerfile": ""
})
}
Expand Down

0 comments on commit dd0e2e0

Please sign in to comment.