Skip to content

Commit

Permalink
Rename devMode, dev-mode to staticPasswords and static-passwords. Fix…
Browse files Browse the repository at this point in the history
… issues with log format of the messages

Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Dec 11, 2024
1 parent 86b26a2 commit 35fc902
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
14 changes: 7 additions & 7 deletions api/v1alpha1/localbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ type PackageConfigsSpec struct {

// BuildCustomizationSpec fields cannot change once a cluster is created
type BuildCustomizationSpec struct {
Protocol string `json:"protocol,omitempty"`
Host string `json:"host,omitempty"`
IngressHost string `json:"ingressHost,omitempty"`
Port string `json:"port,omitempty"`
UsePathRouting bool `json:"usePathRouting,omitempty"`
SelfSignedCert string `json:"selfSignedCert,omitempty"`
DevMode bool `json:"devMode,omitempty"`
Protocol string `json:"protocol,omitempty"`
Host string `json:"host,omitempty"`
IngressHost string `json:"ingressHost,omitempty"`
Port string `json:"port,omitempty"`
UsePathRouting bool `json:"usePathRouting,omitempty"`
SelfSignedCert string `json:"selfSignedCert,omitempty"`
StaticPasswords bool `json:"staticPasswords,omitempty"`
}

type LocalbuildSpec struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,5 @@ func isBuildCustomizationSpecEqual(s1, s2 v1alpha1.BuildCustomizationSpec) bool
s1.Port == s2.Port &&
s1.UsePathRouting == s2.UsePathRouting &&
s1.SelfSignedCert == s2.SelfSignedCert &&
s1.DevMode == s2.DevMode
s1.StaticPasswords == s2.StaticPasswords
}
18 changes: 9 additions & 9 deletions pkg/cmd/create/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
const (
recreateClusterUsage = "Delete cluster first if it already exists."
buildNameUsage = "Name for build (Prefix for kind cluster name, pod names, etc)."
devModeUsage = "When enabled, the platform will run the core packages with developer password."
staticPasswordsUsage = "Set a static password: developer to the applications: argocd and gitea."
kubeVersionUsage = "Version of the kind kubernetes cluster to create."
extraPortsMappingUsage = "List of extra ports to expose on the docker container and kubernetes cluster as nodePort " +
"(e.g. \"22:32222,9090:39090,etc\")."
Expand All @@ -41,7 +41,7 @@ var (
// Flags
recreateCluster bool
buildName string
devMode bool
staticPasswords bool
kubeVersion string
extraPortsMapping string
kindConfigPath string
Expand Down Expand Up @@ -69,7 +69,7 @@ func init() {
CreateCmd.PersistentFlags().StringVar(&buildName, "build-name", "localdev", buildNameUsage)
CreateCmd.PersistentFlags().MarkDeprecated("build-name", "use --name instead.")
CreateCmd.PersistentFlags().StringVar(&buildName, "name", "localdev", buildNameUsage)
CreateCmd.PersistentFlags().BoolVar(&devMode, "dev-mode", false, devModeUsage)
CreateCmd.PersistentFlags().BoolVar(&staticPasswords, "static-passwords", false, staticPasswordsUsage)
CreateCmd.PersistentFlags().StringVar(&kubeVersion, "kube-version", "v1.30.3", kubeVersionUsage)
CreateCmd.PersistentFlags().StringVar(&extraPortsMapping, "extra-ports", "", extraPortsMappingUsage)
CreateCmd.PersistentFlags().StringVar(&kindConfigPath, "kind-config", "", kindConfigPathUsage)
Expand Down Expand Up @@ -141,12 +141,12 @@ func create(cmd *cobra.Command, args []string) error {
ExtraPortsMapping: extraPortsMapping,

TemplateData: v1alpha1.BuildCustomizationSpec{
Protocol: protocol,
Host: host,
IngressHost: ingressHost,
Port: port,
UsePathRouting: pathRouting,
DevMode: devMode,
Protocol: protocol,
Host: host,
IngressHost: ingressHost,
Port: port,
UsePathRouting: pathRouting,
StaticPasswords: staticPasswords,
},

CustomPackageDirs: absDirPaths,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/get/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ func secretToTemplateData(s v1.Secret) TemplateData {

// TODO: The following code should be reviewed and improved as the secret containing the developer username/password is argocd-secret
// where the password has been bcrypted and by consequence we cannot get and decode it from the secret
// This is why we are going to add it here BUT it will be displayed every time no matter if --dev-mode has been used or not
// This is why we are going to add it here BUT it will be displayed every time no matter if --static-passwords has been used or not
if strings.Contains(s.Name, "gitea") {
data.Data["username-developer"] = "giteAdmin"
data.Data["password-developer"] = "developer"
} else if strings.Contains(s.Name, "argocd") {
data.Data["username-developer"] = "developer"
data.Data["username-developer"] = "admin"
data.Data["password-developer"] = "developer"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/gitrepository/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (r *RepositoryReconciler) reconcileGitRepo(ctx context.Context, repo *v1alp
return ctrl.Result{}, fmt.Errorf("getting git provider credentials: %w", err)
}

if r.Config.DevMode {
if r.Config.StaticPasswords {
creds.password = "developer"
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/controllers/localbuild/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func (r *LocalbuildReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
}

if r.Config.DevMode {
logger.V(1).Info("DevMode is enabled")
if r.Config.StaticPasswords {
logger.V(1).Info("StaticPasswords is enabled")

// Check if the Argocd Initial admin secret exists
argocdInitialAdminPassword, err := r.extractArgocdInitialAdminSecret(ctx)
Expand Down Expand Up @@ -683,7 +683,7 @@ func (r *LocalbuildReconciler) updateGiteaDevPassword(ctx context.Context, admin

resp, err := client.AdminEditUser("giteaAdmin", opts)
if err != nil {
return fmt.Errorf("cannot update gitea admin user: %w", resp.StatusCode, err), "failed"
return fmt.Errorf("cannot update gitea admin user. status: %d error : %w", resp.StatusCode, err), "failed"
}
return nil, "succeeded"
}
Expand Down Expand Up @@ -731,7 +731,7 @@ func (r *LocalbuildReconciler) updateArgocdDevPassword(ctx context.Context, admi

err := json.Unmarshal([]byte(body), &argocdSession)
if err != nil {
fmt.Errorf("Error unmarshalling JSON: %v", err)
return fmt.Errorf("Error unmarshalling JSON: %v", err), "failed"
}

payload := map[string]string{
Expand Down Expand Up @@ -794,7 +794,6 @@ func (r *LocalbuildReconciler) updateArgocdDevPassword(ctx context.Context, admi
} else {
return fmt.Errorf("HTTP Error: %d", resp.StatusCode), "failed"
}
return nil, "failed"
}

func (r *LocalbuildReconciler) applyArgoCDAnnotation(ctx context.Context, obj client.Object, argoCDType, annotationKey, annotationValue string) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ spec:
description: BuildCustomizationSpec fields cannot change once a cluster
is created
properties:
devMode:
type: boolean
host:
type: string
ingressHost:
Expand All @@ -53,6 +51,8 @@ spec:
type: string
selfSignedCert:
type: string
staticPasswords:
type: boolean
usePathRouting:
type: boolean
type: object
Expand Down

0 comments on commit 35fc902

Please sign in to comment.