Skip to content

Commit

Permalink
Adjustments to support WSL environements (rumstead#21)
Browse files Browse the repository at this point in the history
feat: added the ability to toggle port forwarding and support for WSL to bind on all interfaces
  • Loading branch information
eramella authored Nov 29, 2023
1 parent 7dcb64b commit 01d2593
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 34 deletions.
14 changes: 10 additions & 4 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# FAQ/Troubleshooting

## I want to pass in different K3s/K3d args
You can pass in any `k3s` argument or any `k3d` argument via the `additionalArgs` array.
You can pass in any `k3s` argument or any `k3d` argument via the `additionalArgs` array.

It is a great way to pass in a different k8s version.
It is a great way to pass in a different k8s version.

## level=fatal msg="dial tcp: lookup host.docker.internal..."
You can control the container gateway via the `CRI_GATEWAY` environment variable.
Ie, for podman `CRI_GATEWAY=containers`
You can control the container gateway hostname via the `CRI_GATEWAY` environment variable. By default the container gateway hostname is `host.docker.internal`. Ie:
- for podman `CRI_GATEWAY=host.containers.internal`
- other hosts `CRI_GATEWAY=my-gateway`
- or ip `CRI_GATEWAY=172.18.0.1`

## Argo is behind a reverse proxy (ingress like treafik)
You can add required flags, such as `--grpc-web`, to the argocd commands by adding `ARGOFLAGS` an an environment variable.
Ie, `ARGOFLAGS=--grpc-web`
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.5.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0
google.golang.org/protobuf v1.28.1
google.golang.org/protobuf v1.31.0
)

require (
Expand Down Expand Up @@ -39,7 +39,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/goodhosts/hostsfile v0.1.1 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/goodhosts/hostsfile v0.1.1 h1:SqRUTFOshOCon0ZSXDrW1bkKZvs4+5pRgYFWySdaLno=
github.com/goodhosts/hostsfile v0.1.1/go.mod h1:lXcUP8xO4WR5vvuQ3F/N0bMQoclOtYKEEUnyY2jTusY=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
Expand Down Expand Up @@ -1290,8 +1290,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/cenkalti/backoff.v2 v2.2.1 h1:eJ9UAg01/HIHG987TwxvnzK2MgxXq97YY6rYDpY9aII=
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/proto/cluster-config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ message GitOps {
string namespace = 1;
string port = 2;
string manifestPath = 3;
Credentials credentials = 4;
bool noPortForward = 4;
Credentials credentials = 5;
}

message Credentials {
Expand Down
48 changes: 29 additions & 19 deletions pkg/config/v1alpha1/cluster-config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/config/v1alpha1/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"manifestPath": {
"type": "string"
},
"noPortForward": {
"type": "boolean"
},
"credentials": {
"$ref": "#/$defs/Credentials"
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/gitops/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ func (a *Agent) deployArgoCD(_ context.Context, ops *kubernetes.Cluster) error {

logging.Log().Debugf("port forwarding on %s\n", ops.GetGitOps().GetPort())
// 4. port forward
// if port forward is not required return nil now
if ops.GetGitOps().GetNoPortForward() {
logging.Log().Infoln("Port forward is not required")
return nil
}
// use start because we do not want to wait
port := fmt.Sprintf("%s:8080", ops.GetGitOps().GetPort())
cmd = exec.Command(a.cmd.Kubectl, "port-forward", "-n", ops.GetGitOps().GetNamespace(), "deploy/argocd-server", port)
cmd = exec.Command(a.cmd.Kubectl, "port-forward", "-n", ops.GetGitOps().GetNamespace(), "deploy/argocd-server", port, "--address", "0.0.0.0")
pid, err := tkexec.StartCommand(cmd)
if err != nil {
return fmt.Errorf("could not port foward argo server: %v", err)
Expand Down Expand Up @@ -178,17 +183,20 @@ func (a *Agent) AddCluster(_ context.Context, ops, workload *kubernetes.Cluster)
}
argoUser := fmt.Sprintf("ARGOUSER=%s", ops.GetGitOps().GetCredentials().GetUsername())
argoPasswd := fmt.Sprintf("ARGOPASSWD=%s", ops.GetGitOps().GetCredentials().GetPassword())
argoPort := fmt.Sprintf("ARGOPORT=%s", ops.GetGitOps().GetPort())
contextName := fmt.Sprintf("CONTEXT=%s", workload.Name)
clusterName := fmt.Sprintf("CLUSTER=%s", workload.RequestCluster.GetName())
labels := generateArgs(clusterArgLabels, workload.GetLabels())
annotations := generateArgs(clusterArgAnnotations, workload.GetAnnotations())
cmd := exec.Command(a.cmd.CR, "run", "--network", ops.GetNetwork(), "--rm",
"-e", argoUser,
"-e", argoPasswd,
"-e", argoPort,
"-e", kubeConfig,
"-e", contextName,
"-e", clusterName,
"-e", "CRI_GATEWAY",
"-e", "ARGOFLAGS",
"-v", workDirVolume,
"quay.io/argoproj/argocd:latest", "/hack/addCluster.sh", labels+annotations)
logging.Log().Debugf("%s\n", cmd.String())
Expand Down
8 changes: 5 additions & 3 deletions pkg/gitops/argocd/embed/addClusters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
set -e
set -o pipefail

ARGO_PORT="${ARGOPORT:-"8080"}"
# support podman or any other non-docker gateway
CRI_GATEWAY="${CRI_GATEWAY:-"docker"}"
CRI_GATEWAY="${CRI_GATEWAY:-"host.docker.internal"}"

# login
# https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
argocd login "host.$CRI_GATEWAY.internal:8080" --insecure --username "$ARGOUSER" --password "$ARGOPASSWD"
argocd login "$CRI_GATEWAY:$ARGO_PORT" --insecure $ARGOFLAGS --username "$ARGOUSER" --password "$ARGOPASSWD"

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

0 comments on commit 01d2593

Please sign in to comment.