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

Adjustments to support WSL environements #21

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
14 changes: 11 additions & 3 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# 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.
You can control the container gateway via the `CRI_GATEWAY` environment variable.
Ie, for podman `CRI_GATEWAY=containers`

## 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`

## Are you using wsl and host.docker.internal does not work?
You can pass a host name or IP address via the `DOCKERGATEWAY` environment variable.
Ie, `DOCKERGATEWAY=my-gateway` or `DOCKERGATEWAY=172.18.0.1`
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
12 changes: 11 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,18 +183,23 @@ 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",
"-e", "DOCKERGATEWAY",
"-v", workDirVolume,
"-h", "0.0.0.0",
"quay.io/argoproj/argocd:latest", "/hack/addCluster.sh", labels+annotations)
logging.Log().Debugf("%s\n", cmd.String())
if output, err := tkexec.RunCommand(cmd); err != nil {
Expand Down
12 changes: 10 additions & 2 deletions pkg/gitops/argocd/embed/addClusters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
set -e
set -o pipefail

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

if [ -z "$DOCKERGATEWAY" ]
then
DOCKER_GATEWAY="host.$CRI_GATEWAY.internal"
else
DOCKER_GATEWAY="$DOCKERGATEWAY"
fi
# 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 "$DOCKER_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