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

feat: add redirect to https from ingress #825

Merged
merged 2 commits into from
Dec 6, 2022
Merged
Changes from 1 commit
Commits
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
21 changes: 19 additions & 2 deletions cmd/local/local.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,11 @@ package local

import (
"fmt"
"github.com/rs/zerolog/log"
"sync"
"time"

"github.com/rs/zerolog/log"

"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/wrappers"

@@ -62,7 +63,7 @@ func NewCommand() *cobra.Command {
// todo: UPDATE IT BEFORE MERGING
// todo: UPDATE IT BEFORE MERGING
// todo: UPDATE IT BEFORE MERGING
localCmd.Flags().StringVar(&gitOpsBranch, "gitops-branch", "fix_atlantis_tcp", "version/branch used on git clone")
localCmd.Flags().StringVar(&gitOpsBranch, "gitops-branch", "add-ingress-localhost", "version/branch used on git clone")
localCmd.Flags().StringVar(&gitOpsRepo, "gitops-repo", "gitops", "")
localCmd.Flags().StringVar(&templateTag, "template-tag", "",
"when running a built version, and ldflag is set for the Kubefirst version, it will use this tag value to clone the templates (gitops and metaphor's)",
@@ -191,6 +192,12 @@ func runLocal(cmd *cobra.Command, args []string) error {
log.Info().Msg("already added secrets to k3d cluster")
}

log.Info().Msg("storing certificates into application secrets namespace")
if err := k8s.CreateSecretsFromCertificatesForLocalWrapper(config); err != nil {
log.Error().Err(err).Msg("")
}
log.Info().Msg("storing certificates into application secrets namespace done")

// create argocd initial repository config
executionControl = viper.GetBool("argocd.initial-repository.created")
if !executionControl {
@@ -419,6 +426,16 @@ func runLocal(cmd *cobra.Command, args []string) error {
progressPrinter.IncrementTracker("step-telemetry", 1)
}

_, _, err = pkg.ExecShellReturnStrings(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "-n", "argocd", "apply", "-f", fmt.Sprintf("%s/gitops/ingressroute.yaml", config.K1FolderPath))

if err != nil {

log.Printf("failed to create ingress route to argocd: %s", err)
marinhojess marked this conversation as resolved.
Show resolved Hide resolved
marinhojess marked this conversation as resolved.
Show resolved Hide resolved

}

_, _, _ = pkg.ExecShellReturnStrings(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "-n", "argocd", "delete", "ingress", "argocd-server")
marinhojess marked this conversation as resolved.
Show resolved Hide resolved

log.Info().Msg("Kubefirst installation finished successfully")
pkg.InformUser("Kubefirst installation finished successfully", silentMode)

18 changes: 2 additions & 16 deletions cmd/local/postrun.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package local

import (
"fmt"
"github.com/rs/zerolog/log"
"os"
"os/signal"
"sync"
"syscall"

"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/k8s"
"github.com/rs/zerolog/log"

"github.com/kubefirst/kubefirst/internal/reports"
"github.com/kubefirst/kubefirst/pkg"
"github.com/spf13/cobra"
@@ -22,14 +20,6 @@ func runPostLocal(cmd *cobra.Command, args []string) error {
return nil
}

config := configs.ReadConfig()

log.Info().Msg("storing certificates into application secrets namespace")
if err := k8s.CreateSecretsFromCertificatesForLocalWrapper(config); err != nil {
log.Error().Err(err).Msg("")
}
log.Info().Msg("storing certificates into application secrets namespace done")

log.Info().Msg("Starting the presentation of console and api for the handoff screen")

err := pkg.IsConsoleUIAvailable(pkg.KubefirstConsoleLocalURL)
@@ -44,10 +34,6 @@ func runPostLocal(cmd *cobra.Command, args []string) error {
reports.LocalHandoffScreen(dryRun, silentMode)

log.Info().Msgf("Kubefirst Console available at: http://localhost:9094", silentMode)
_, _, err = pkg.ExecShellReturnStrings(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "-n", "argocd", "apply", "-f", fmt.Sprintf("%s/gitops/ingressroute.yaml", config.K1FolderPath))
if err != nil {
log.Printf("failed to create ingress route to argocd: %s", err)
}

log.Info().Msgf("Kubefirst Console available at: http://localhost:9094", silentMode)

7 changes: 4 additions & 3 deletions cmd/local/prerun.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,9 @@ package local
import (
"context"
"fmt"
"net/http"
"time"

"github.com/dustin/go-humanize"
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/addon"
@@ -18,8 +21,6 @@ import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"net/http"
"time"
)

func validateLocal(cmd *cobra.Command, args []string) error {
@@ -71,7 +72,7 @@ func validateLocal(cmd *cobra.Command, args []string) error {
viper.Set("adminemail", adminEmail)

viper.Set("argocd.local.service", pkg.ArgoCDLocalURL)
viper.Set("vault.local.service", pkg.VaultLocalURL)
viper.Set("vault.local.service", pkg.VaultLocalURLTLS)
go pkg.RunNgrok(context.TODO())

// addons
8 changes: 4 additions & 4 deletions configs/config.go
Original file line number Diff line number Diff line change
@@ -34,9 +34,9 @@ type Config struct {
KubectlClientPath string
KubeConfigPath string
KubeConfigFolder string
HelmClientPath string
GitOpsLocalRepoPath string
NgrokVersion string
HelmClientPath string
GitOpsLocalRepoPath string
NgrokVersion string
NgrokClientPath string
TerraformClientPath string
K3dPath string
@@ -136,7 +136,7 @@ func ReadConfig() *Config {
config.GitopsTemplateURL = "https://github.com/kubefirst/gitops-template-gh.git"
// Local Configs URL
config.LocalArgoWorkflowsURL = "http://argo.localdev.me"
config.LocalVaultURL = "http://vault.localdev.me"
config.LocalVaultURL = "https://vault.localdev.me"
marinhojess marked this conversation as resolved.
Show resolved Hide resolved
config.LocalArgoURL = "http://argocd.localdev.me"
config.LocalAtlantisURL = "http://atlantis.localdev.me"
config.LocalChartmuseumURL = "http://localhost:8181"
6 changes: 2 additions & 4 deletions internal/argocd/argocd.go
Original file line number Diff line number Diff line change
@@ -45,9 +45,8 @@ type Config struct {
Ingress struct {
Enabled string `yaml:"enabled"`
Annotations struct {
IngressKubernetesIoRewriteTarget string `yaml:"ingress.kubernetes.io/rewrite-target"`
IngressKubernetesIoBackendProtocol string `yaml:"ingress.kubernetes.io/backend-protocol"`
IngressKubernetesIoActionsSslRedirect string `yaml:"ingress.kubernetes.io/actions.ssl-redirect"`
IngressKubernetesIoRewriteTarget string `yaml:"ingress.kubernetes.io/rewrite-target"`
IngressKubernetesIoBackendProtocol string `yaml:"ingress.kubernetes.io/backend-protocol"`
} `yaml:"annotations"`
Hosts []string `yaml:"hosts"`
TLS []TLSConfig `yaml:"tls"`
@@ -467,7 +466,6 @@ func GetArgoCDInitialLocalConfig(gitOpsRepo string, botPrivateKey string) Config
argoCDConfig.Server.Ingress.Enabled = "true"
argoCDConfig.Server.Ingress.Annotations.IngressKubernetesIoRewriteTarget = "/"
argoCDConfig.Server.Ingress.Annotations.IngressKubernetesIoBackendProtocol = "HTTPS"
argoCDConfig.Server.Ingress.Annotations.IngressKubernetesIoActionsSslRedirect = `{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}`
argoCDConfig.Server.Ingress.Hosts = []string{"argocd.localdev.me"}

argoCDConfig.Server.Ingress.TLS = []TLSConfig{
5 changes: 3 additions & 2 deletions internal/k3d/secrets.go
Original file line number Diff line number Diff line change
@@ -5,9 +5,10 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/rs/zerolog/log"
"os"

"github.com/rs/zerolog/log"

"github.com/kubefirst/kubefirst/internal/k8s"
"github.com/spf13/viper"
v1 "k8s.io/api/core/v1"
@@ -17,7 +18,7 @@ import (
func AddK3DSecrets(dryrun bool) error {
clientset, err := k8s.GetClientSet(dryrun)

newNamespaces := []string{"argo", "argocd", "atlantis", "chartmuseum", "github-runner", "vault", "development", "staging", "production"}
newNamespaces := []string{"argo", "argocd", "atlantis", "chartmuseum", "github-runner", "vault", "development", "staging", "production", "kubefirst", "minio"}
for i, s := range newNamespaces {
namespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: s}}
_, err = clientset.CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{})
7 changes: 4 additions & 3 deletions internal/k8s/kubernetes.go
Original file line number Diff line number Diff line change
@@ -5,15 +5,16 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/rs/zerolog/log"
"io"
v1 "k8s.io/api/core/v1"
"net/http"
"os"
"os/exec"
"strings"
"time"

"github.com/rs/zerolog/log"
v1 "k8s.io/api/core/v1"

"github.com/itchyny/gojq"
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/argocd"
@@ -386,7 +387,7 @@ func LoopUntilPodIsReady(dryRun bool) {
if len(token) == 0 {

totalAttempts := 50
url := pkg.VaultLocalURL + "/v1/sys/health"
url := pkg.VaultLocalURLTLS + "/v1/sys/health"
for i := 0; i < totalAttempts; i++ {
log.Info().Msgf("vault is not ready yet, sleeping and checking again, attempt (%d/%d)", i+1, totalAttempts)
time.Sleep(10 * time.Second)