diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index ea9792f..c241bb5 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -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` \ No newline at end of file diff --git a/go.mod b/go.mod index 1b278fc..b2b2ac0 100644 --- a/go.mod +++ b/go.mod @@ -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 ( @@ -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 diff --git a/go.sum b/go.sum index c638890..116f3b9 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/pkg/config/proto/cluster-config.proto b/pkg/config/proto/cluster-config.proto index 75425d7..c829d9b 100644 --- a/pkg/config/proto/cluster-config.proto +++ b/pkg/config/proto/cluster-config.proto @@ -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 { diff --git a/pkg/config/v1alpha1/cluster-config.pb.go b/pkg/config/v1alpha1/cluster-config.pb.go index 638e417..cf20cde 100644 --- a/pkg/config/v1alpha1/cluster-config.pb.go +++ b/pkg/config/v1alpha1/cluster-config.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.0 -// protoc v3.21.12 +// protoc-gen-go v1.31.0 +// protoc v4.25.0 // source: cluster-config.proto package v1alpha1 @@ -175,10 +175,11 @@ type GitOps struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` - Port string `protobuf:"bytes,2,opt,name=port,proto3" json:"port,omitempty"` - ManifestPath string `protobuf:"bytes,3,opt,name=manifestPath,proto3" json:"manifestPath,omitempty"` - Credentials *Credentials `protobuf:"bytes,4,opt,name=credentials,proto3" json:"credentials,omitempty"` + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` + Port string `protobuf:"bytes,2,opt,name=port,proto3" json:"port,omitempty"` + ManifestPath string `protobuf:"bytes,3,opt,name=manifestPath,proto3" json:"manifestPath,omitempty"` + NoPortForward bool `protobuf:"varint,4,opt,name=noPortForward,proto3" json:"noPortForward,omitempty"` + Credentials *Credentials `protobuf:"bytes,5,opt,name=credentials,proto3" json:"credentials,omitempty"` } func (x *GitOps) Reset() { @@ -234,6 +235,13 @@ func (x *GitOps) GetManifestPath() string { return "" } +func (x *GitOps) GetNoPortForward() bool { + if x != nil { + return x.NoPortForward + } + return false +} + func (x *GitOps) GetCredentials() *Credentials { if x != nil { return x.Credentials @@ -393,24 +401,26 @@ var file_cluster_config_proto_rawDesc = []byte{ 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x22, 0x97, 0x01, 0x0a, 0x06, 0x47, 0x69, 0x74, 0x4f, 0x70, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x6e, + 0x22, 0xbd, 0x01, 0x0a, 0x06, 0x47, 0x69, 0x74, 0x4f, 0x70, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x6d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x50, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6d, 0x61, 0x6e, 0x69, 0x66, 0x65, 0x73, 0x74, 0x50, 0x61, 0x74, - 0x68, 0x12, 0x37, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, - 0x31, 0x2e, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73, 0x52, 0x0b, 0x63, - 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73, 0x22, 0x45, 0x0a, 0x0b, 0x43, 0x72, - 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, - 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, - 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, - 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, - 0x64, 0x22, 0x21, 0x0a, 0x0b, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x41, 0x72, 0x67, 0x73, - 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, - 0x61, 0x72, 0x67, 0x73, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x3b, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, - 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x68, 0x12, 0x24, 0x0a, 0x0d, 0x6e, 0x6f, 0x50, 0x6f, 0x72, 0x74, 0x46, 0x6f, 0x72, 0x77, 0x61, + 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x6e, 0x6f, 0x50, 0x6f, 0x72, 0x74, + 0x46, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x12, 0x37, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x64, 0x65, + 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x76, + 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, + 0x61, 0x6c, 0x73, 0x52, 0x0b, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73, + 0x22, 0x45, 0x0a, 0x0b, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73, 0x12, + 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, + 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, + 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x21, 0x0a, 0x0b, 0x43, 0x6c, 0x75, 0x73, 0x74, + 0x65, 0x72, 0x41, 0x72, 0x67, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x3b, + 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pkg/config/v1alpha1/schema.json b/pkg/config/v1alpha1/schema.json index 1dc56f8..8be8f0e 100644 --- a/pkg/config/v1alpha1/schema.json +++ b/pkg/config/v1alpha1/schema.json @@ -25,6 +25,9 @@ "manifestPath": { "type": "string" }, + "noPortForward": { + "type": "boolean" + }, "credentials": { "$ref": "#/$defs/Credentials" } diff --git a/pkg/gitops/argocd/argocd.go b/pkg/gitops/argocd/argocd.go index 7504d37..dc911aa 100644 --- a/pkg/gitops/argocd/argocd.go +++ b/pkg/gitops/argocd/argocd.go @@ -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) @@ -178,6 +183,7 @@ 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()) @@ -185,10 +191,12 @@ func (a *Agent) AddCluster(_ context.Context, ops, workload *kubernetes.Cluster) 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()) diff --git a/pkg/gitops/argocd/embed/addClusters.sh b/pkg/gitops/argocd/embed/addClusters.sh index bee1892..7b22bbb 100755 --- a/pkg/gitops/argocd/embed/addClusters.sh +++ b/pkg/gitops/argocd/embed/addClusters.sh @@ -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 \ No newline at end of file +argocd cluster add -y --upsert "$CONTEXT" --insecure $ARGOFLAGS --name "$CLUSTER" --kubeconfig "$KUBECONFIG" $1 \ No newline at end of file