Skip to content

Commit e3750e5

Browse files
authored
Fix/support podman (#18)
* fix: support podman Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com>
1 parent 9f8926a commit e3750e5

6 files changed

Lines changed: 40 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# gitops-toolkit
22
Helpful manifests, scripts, and tools for gitops. Currently, the go binary supports creating N of clusters and allowing a GitOps engine to manage them.
3-
The first use case was to setup an environment to test [Argo CD Application Sets](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/#introduction-to-applicationset-controller),
3+
The first use case was to set up an environment to test [Argo CD Application Sets](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/#introduction-to-applicationset-controller),
44
specifically with [cluster generators](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Cluster/).
55

6+
## Troubleshooting
7+
See the [troubleshooting guide](TROUBLESHOOTING.md).
8+
69
## Shell Script
710
The first version of the toolkit was done via [shell scripts](hack/multiple-clusters/README.md).
811

@@ -16,10 +19,10 @@ make build
1619
go install github.com/rumstead/gitops-toolkit
1720
```
1821
### Configuring
19-
The script reads a json configuration file to create clusters. Order of the clusters matters because of how K3d updates DNS. The bottom most cluster can
22+
The script reads a json/yaml configuration file to create clusters. Order of the clusters matters because of how K3d updates DNS. The bottom cluster can
2023
address all cluster above it.
2124
#### Schema
22-
A json schema file can be found [here](pkg/config/v1alpha1/schema.json) with a [sample](pkg/config/testdata/clusters.json).
25+
A json schema file can be found [here](pkg/config/v1alpha1/schema.json) with a [sample](pkg/config/testdata/clusters.json). Similarly, a yaml example file is [here](pkg/config/testdata/clusters.yaml).
2326
#### Generating a configuration file
2427
You can use the [proto structs](pkg/config/v1alpha1/cluster-config.pb.go) to write your configuration in code and dump them out as json.
2528
## What is happening under the covers?

TROUBLESHOOTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# FAQ/Troubleshooting
2+
3+
## I want to pass in different K3s/K3d args
4+
You can pass in any `k3s` argument or any `k3d` argument via the `additionalArgs` array.
5+
6+
It is a great way to pass in a different k8s version.
7+
8+
## level=fatal msg="dial tcp: lookup host.docker.internal..."
9+
You can control the container gateway via the `CRI_GATEWAY` environment variable.
10+
Ie, for podman `CRI_GATEWAY=containers`

pkg/gitops/argocd/argocd.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func NewGitOpsEngine(binaries map[string]string) gitops.Engine {
3333
}
3434

3535
func (a *Agent) Deploy(ctx context.Context, ops *kubernetes.Cluster) error {
36+
logging.Log().Infoln("Deploying Argo CD")
3637
if _, err := os.Stat(ops.KubeConfigPath); err != nil {
3738
return err
3839
}
@@ -181,8 +182,16 @@ func (a *Agent) AddCluster(_ context.Context, ops, workload *kubernetes.Cluster)
181182
clusterName := fmt.Sprintf("CLUSTER=%s", workload.RequestCluster.GetName())
182183
labels := generateArgs(clusterArgLabels, workload.GetLabels())
183184
annotations := generateArgs(clusterArgAnnotations, workload.GetAnnotations())
184-
cmd := exec.Command(a.cmd.CR, "run", "--network", ops.GetNetwork(), "--rm", "-e", argoUser, "-e", argoPasswd, "-e", kubeConfig, "-e", contextName,
185-
"-e", clusterName, "-v", workDirVolume, "quay.io/argoproj/argocd:latest", "/hack/addCluster.sh", labels+annotations)
185+
cmd := exec.Command(a.cmd.CR, "run", "--network", ops.GetNetwork(), "--rm",
186+
"-e", argoUser,
187+
"-e", argoPasswd,
188+
"-e", kubeConfig,
189+
"-e", contextName,
190+
"-e", clusterName,
191+
"-e", "CRI_GATEWAY",
192+
"-v", workDirVolume,
193+
"quay.io/argoproj/argocd:latest", "/hack/addCluster.sh", labels+annotations)
194+
logging.Log().Debugf("%s\n", cmd.String())
186195
if output, err := tkexec.RunCommand(cmd); err != nil {
187196
return fmt.Errorf("error adding cluster to gitops agent: %s: %v", string(output), err)
188197
}

pkg/gitops/argocd/embed/addClusters.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
set -e
33
set -o pipefail
44

5+
# support podman or any other non-docker gateway
6+
CRI_GATEWAY="${CRI_GATEWAY:-"docker"}"
57
# login
68
# https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
7-
argocd login host.docker.internal:8080 --insecure --username "$ARGOUSER" --password "$ARGOPASSWD"
9+
argocd login "host.$CRI_GATEWAY.internal:8080" --insecure --username "$ARGOUSER" --password "$ARGOPASSWD"
810

911
# don't quote $1 so it globs
1012
argocd cluster add -y --upsert "$CONTEXT" --insecure --name "$CLUSTER" --kubeconfig "$KUBECONFIG" $1

pkg/kubernetes/k3d/k3d.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
78

89
k3dcluster "github.com/k3d-io/k3d/v5/cmd/cluster"
910
k3dclient "github.com/k3d-io/k3d/v5/pkg/client"
@@ -36,6 +37,10 @@ func (k *K3d) getKubeConfig(ctx context.Context, cluster *v1alpha1.RequestCluste
3637
if err != nil {
3738
return "", err
3839
}
40+
// allow anyone to read the file since it will be consumed by the gitops agent later.
41+
if err = os.Chmod(output, 0755); err != nil {
42+
return "", err
43+
}
3944
return output, nil
4045
}
4146

pkg/logging/logging.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package logging
22

33
import (
4+
"os"
5+
46
"github.com/sirupsen/logrus"
57
)
68

79
var Logger *logrus.Logger
810

911
func init() {
1012
Logger = logrus.New()
11-
Logger.SetLevel(logrus.DebugLevel)
13+
if os.Getenv("DEBUG") != "" {
14+
Logger.SetLevel(logrus.DebugLevel)
15+
}
1216
}
1317

1418
func Log() *logrus.Logger {

0 commit comments

Comments
 (0)