Skip to content

Commit

Permalink
⚡ add support for argocd insecure flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zcubbs committed Jan 15, 2024
1 parent 601c649 commit 5ee6640
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 12 deletions.
4 changes: 0 additions & 4 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ env:
GOOS: "{{OS}}"

tasks:
build:
desc: Build Go Binaries
cmds:
- go build -v ./...

test:
desc: Run tests
Expand Down
40 changes: 35 additions & 5 deletions argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ func Install(values Values, kubeconfig string, debug bool) error {
return err
}

vals := map[string]string{
"configs.params.server\\.insecure": fmt.Sprintf("%t", values.Insecure),
}

// install argocd
helmClient := helm.NewClient()
helmClient.Settings.KubeConfig = kubeconfig
Expand All @@ -54,7 +50,7 @@ func Install(values Values, kubeconfig string, debug bool) error {
ChartName: argocdChartName,
ReleaseName: argocdChartName,
RepoName: argocdHelmRepoName,
Values: vals,
Values: nil,
ValuesFiles: nil,
Debug: debug,
CreateNamespace: true,
Expand Down Expand Up @@ -85,6 +81,22 @@ func Install(values Values, kubeconfig string, debug bool) error {
return fmt.Errorf("failed to wait for argocd server to be ready \n %w", err)
}

// patch argocd-cmd-params-cm configmap to set insecure flag
err = patchConfigMap(kubeconfig, argocdNamespace, "argocd-cmd-params-cm", map[string]string{
"server.insecure": fmt.Sprintf("%t", values.Insecure),
}, debug)
if err != nil {
return fmt.Errorf("failed to patch argocd-cmd-params-cm: %w", err)
}

// restart argocd server pod
err = kubernetes.RestartPods(kubeconfig, argocdNamespace, []string{
argocdServerDeploymentName,
}, debug)
if err != nil {
return fmt.Errorf("failed to restart argocd server pod: %w", err)
}

return nil
}

Expand Down Expand Up @@ -192,3 +204,21 @@ func validateValues(values Values) error {
}
return nil
}

func patchConfigMap(kubeconfig string, namespace string, name string, patch map[string]string, debug bool) error {
cm, err := kubernetes.GetConfigMap(kubeconfig, namespace, name)
if err != nil {
return fmt.Errorf("failed to get configmap %s: %w", name, err)
}

for k, v := range patch {
cm.Data[k] = v
}

err = kubernetes.UpdateConfigMap(kubeconfig, cm, namespace)
if err != nil {
return fmt.Errorf("failed to update configmap %s: %w", name, err)
}

return nil
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/zcubbs/secret v0.1.1
github.com/zcubbs/x v0.1.16
golang.org/x/crypto v0.17.0
golang.org/x/crypto v0.18.0
golang.org/x/text v0.14.0
gopkg.in/yaml.v2 v2.4.0
helm.sh/helm/v3 v3.13.3
Expand Down Expand Up @@ -131,8 +131,8 @@ require (
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand Down Expand Up @@ -499,12 +501,16 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
43 changes: 43 additions & 0 deletions kubernetes/cm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package kubernetes

import (
"context"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func GetConfigMap(kubeconfig, namespace, name string) (*v1.ConfigMap, error) {
cs, err := GetClientSet(kubeconfig)
if err != nil {
return nil, err
}
cm, err := cs.CoreV1().ConfigMaps(namespace).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return cm, nil
}

func CreateConfigMap(kubeconfig string, cm *v1.ConfigMap, namespace string) error {
cs, err := GetClientSet(kubeconfig)
if err != nil {
return err
}
_, err = cs.CoreV1().ConfigMaps(namespace).Create(context.Background(), cm, metav1.CreateOptions{})
if err != nil {
return err
}
return nil
}

func UpdateConfigMap(kubeconfig string, cm *v1.ConfigMap, namespace string) error {
cs, err := GetClientSet(kubeconfig)
if err != nil {
return err
}
_, err = cs.CoreV1().ConfigMaps(namespace).Update(context.Background(), cm, metav1.UpdateOptions{})
if err != nil {
return err
}
return nil
}

0 comments on commit 5ee6640

Please sign in to comment.