-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
276 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package argocd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/zcubbs/x/helm" | ||
"github.com/zcubbs/x/kubernetes" | ||
"time" | ||
) | ||
|
||
const ( | ||
argocdChartName = "argocd" | ||
argocdHelmRepoName = "argocd" | ||
argocdHelmRepoURL = "https://argoproj.github.io/argo-helm" | ||
argocdChartVersion = "latest" | ||
argocdNamespace = "argocd" | ||
) | ||
|
||
const ( | ||
argocdServerDeploymentName = "argo-cd-argocd-server" | ||
argocdRepoServerDeploymentName = "argo-cd-argocd-repo-server" | ||
argocdRedisDeploymentName = "argo-cd-argocd-redis" | ||
argocdDexServerDeploymentName = "argo-cd-argocd-dex-server" | ||
argocdApplicationsetControllerDeploymentName = "argo-cd-argocd-applicationset-controller" | ||
argocdNotificationsControllerDeploymentName = "argo-cd-argocd-notifications-controller" | ||
) | ||
|
||
func Install(values Values, kubeconfig string, debug bool) error { | ||
if err := validateValues(values); err != nil { | ||
return err | ||
} | ||
|
||
vals := map[string]interface{}{ | ||
"configs.params.server\\.insecure": values.Insecure, | ||
} | ||
|
||
err := helm.Install(helm.Chart{ | ||
Name: argocdChartName, | ||
Repo: argocdHelmRepoName, | ||
URL: argocdHelmRepoURL, | ||
Version: values.ChartVersion, | ||
Values: vals, | ||
ValuesFiles: nil, | ||
Namespace: argocdNamespace, | ||
}, kubeconfig, debug) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// wait for argocd server to be ready | ||
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | ||
defer cancel() | ||
err = kubernetes.IsDeploymentReady( | ||
ctxWithTimeout, | ||
kubeconfig, | ||
argocdNamespace, | ||
[]string{ | ||
argocdServerDeploymentName, | ||
argocdRepoServerDeploymentName, | ||
argocdRedisDeploymentName, | ||
argocdDexServerDeploymentName, | ||
argocdApplicationsetControllerDeploymentName, | ||
argocdNotificationsControllerDeploymentName, | ||
}, | ||
debug, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("failed to wait for argocd server to be ready \n %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Uninstall(kubeconfig string, debug bool) error { | ||
return helm.Uninstall(helm.Chart{ | ||
Name: argocdChartName, | ||
Namespace: argocdNamespace, | ||
}, kubeconfig, debug) | ||
} | ||
|
||
type Values struct { | ||
Insecure bool | ||
ChartVersion string | ||
} | ||
|
||
func validateValues(values Values) error { | ||
if values.ChartVersion == "" { | ||
values.ChartVersion = argocdChartVersion | ||
} | ||
return nil | ||
} |
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 |
---|---|---|
@@ -1,163 +1,72 @@ | ||
package recipe | ||
|
||
import ( | ||
"github.com/zcubbs/hotpot/pkg/traefik" | ||
"github.com/zcubbs/x/helm" | ||
"github.com/zcubbs/x/k3s" | ||
) | ||
|
||
const ( | ||
// CertResolver is the name of the cert-manager resolver | ||
CertResolver = "certResolver" | ||
) | ||
|
||
type Hooks struct { | ||
Pre PreHook | ||
Post PostHook | ||
} | ||
type PreHook func() error | ||
type PostHook func() error | ||
|
||
// Cook runs recipe | ||
func Cook(cfgPath string, hooks ...PreHook) error { | ||
func Cook(recipePath string, hooks ...Hooks) error { | ||
// load config | ||
cfg, err := Load(cfgPath) | ||
recipe, err := Load(recipePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// validate config | ||
if err := validate(cfg); err != nil { | ||
if err := validate(recipe); err != nil { | ||
return err | ||
} | ||
|
||
// preheat hooks | ||
for _, hook := range hooks { | ||
if err := hook(); err != nil { | ||
if err := hook.Pre(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if err := checkPrerequisites(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := installK3s(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := installHelm(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := installCertManager(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := installTraefik(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := installArgocd(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := configureArgocdRepos(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := configureArgocdProjects(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := configureArgocdApps(cfg); err != nil { | ||
return err | ||
} | ||
|
||
if err := printKubeconfig(cfg); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func checkPrerequisites(_ *Recipe) error { | ||
return nil | ||
} | ||
|
||
func installK3s(cfg *Recipe) error { | ||
k3sCfg := cfg.Ingredients.K3s | ||
return k3s.Install(k3s.Config{ | ||
Disable: k3sCfg.Disable, | ||
TlsSan: k3sCfg.TlsSan, | ||
DataDir: k3sCfg.DataDir, | ||
DefaultLocalStoragePath: k3sCfg.DefaultLocalStoragePath, | ||
WriteKubeconfigMode: k3sCfg.WriteKubeconfigMode, | ||
}, cfg.Debug) | ||
} | ||
|
||
func installHelm(cfg *Recipe) error { | ||
ok, err := helm.IsHelmInstalled() | ||
if err != nil { | ||
// add steps | ||
if err := add(recipe, | ||
step{f: checkPrerequisites, c: true}, | ||
step{f: installK3s, c: recipe.Ingredients.K3s.Enabled}, | ||
step{f: installHelm, c: true}, | ||
step{f: installCertManager, c: recipe.Ingredients.CertManager.Enabled}, | ||
step{f: installTraefik, c: recipe.Ingredients.Traefik.Enabled}, | ||
step{f: installArgocd, c: recipe.Ingredients.ArgoCD.Enabled}, | ||
step{f: configureArgocdRepos, c: recipe.Ingredients.ArgoCD.Enabled}, | ||
step{f: configureArgocdProjects, c: recipe.Ingredients.ArgoCD.Enabled}, | ||
step{f: configureArgocdApps, c: recipe.Ingredients.ArgoCD.Enabled}, | ||
step{f: printKubeconfig, c: recipe.Debug}, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
if !ok { | ||
err = helm.InstallCli(cfg.Debug) | ||
if err != nil { | ||
// post cook hooks | ||
for _, hook := range hooks { | ||
if err := hook.Post(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func installCertManager(_ *Recipe) error { | ||
return nil | ||
} | ||
|
||
func installTraefik(cfg *Recipe) error { | ||
var ingressProvider string | ||
if cfg.Ingredients.CertManager.Enabled { | ||
ingressProvider = CertResolver | ||
func add(r *Recipe, steps ...step) error { | ||
for _, step := range steps { | ||
if !step.c { | ||
continue | ||
} | ||
if err := step.f(r); err != nil { | ||
return err | ||
} | ||
} | ||
traefikCfg := cfg.Ingredients.Traefik | ||
return traefik.Install( | ||
traefik.Values{ | ||
AdditionalArguments: nil, | ||
IngressProvider: ingressProvider, | ||
DnsProvider: traefikCfg.DnsChallengeProvider, | ||
DnsResolverEmail: traefikCfg.DnsChallengeResolverEmail, | ||
EnableDashboard: traefikCfg.EnableDashboard, | ||
EnableAccessLog: traefikCfg.EnableAccessLog, | ||
DebugLog: traefikCfg.Debug, | ||
EndpointsWeb: traefikCfg.EndpointsWeb, | ||
EndpointsWebsecure: traefikCfg.EndpointsWebsecure, | ||
ServersTransportInsecureSkipVerify: traefikCfg.TransportInsecure, | ||
ForwardedHeaders: traefikCfg.ForwardHeaders, | ||
ForwardedHeadersInsecure: traefikCfg.ForwardHeadersInsecure, | ||
ForwardedHeadersTrustedIPs: traefikCfg.ForwardHeadersTrustedIPs, | ||
ProxyProtocol: traefikCfg.ProxyProtocol, | ||
ProxyProtocolInsecure: traefikCfg.ProxyProtocolInsecure, | ||
ProxyProtocolTrustedIPs: traefikCfg.ProxyProtocolTrustedIPs, | ||
DnsTZ: traefikCfg.DnsChallengeTZ, | ||
}, | ||
cfg.Kubeconfig, | ||
cfg.Debug, | ||
) | ||
} | ||
|
||
func installArgocd(cfg *Recipe) error { | ||
return nil | ||
} | ||
|
||
func configureArgocdRepos(cfg *Recipe) error { | ||
return nil | ||
} | ||
|
||
func configureArgocdProjects(cfg *Recipe) error { | ||
return nil | ||
} | ||
|
||
func configureArgocdApps(cfg *Recipe) error { | ||
return nil | ||
} | ||
|
||
func printKubeconfig(cfg *Recipe) error { | ||
return nil | ||
} |
Oops, something went wrong.