From b019ea260899c5629f5a1e17a6022df3f67088bf Mon Sep 17 00:00:00 2001 From: Bradford Wagner Date: Thu, 22 Feb 2024 10:16:03 -0500 Subject: [PATCH] Paramaterize kubectl port-forward bind address (#25) --- pkg/config/proto/cluster-config.proto | 3 ++- pkg/config/testdata/clusters.yaml | 1 + pkg/config/v1alpha1/cluster-config.pb.go | 33 ++++++++++++++++-------- pkg/config/v1alpha1/schema.json | 3 +++ pkg/gitops/argocd/argocd.go | 9 +++++-- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/pkg/config/proto/cluster-config.proto b/pkg/config/proto/cluster-config.proto index c829d9b..61edc02 100644 --- a/pkg/config/proto/cluster-config.proto +++ b/pkg/config/proto/cluster-config.proto @@ -23,6 +23,7 @@ message GitOps { string manifestPath = 3; bool noPortForward = 4; Credentials credentials = 5; + string bindAddress = 6; } message Credentials { @@ -32,4 +33,4 @@ message Credentials { message ClusterArgs { repeated string args = 2; -} \ No newline at end of file +} diff --git a/pkg/config/testdata/clusters.yaml b/pkg/config/testdata/clusters.yaml index 50823f5..183176e 100644 --- a/pkg/config/testdata/clusters.yaml +++ b/pkg/config/testdata/clusters.yaml @@ -66,6 +66,7 @@ clusters: namespace: argocd port: '8080' manifestPath: "./manifests/argo-cd/" + bindAddress: localhost credentials: username: admin password: admin1234 diff --git a/pkg/config/v1alpha1/cluster-config.pb.go b/pkg/config/v1alpha1/cluster-config.pb.go index cf20cde..6ea2d27 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.31.0 -// protoc v4.25.0 +// protoc-gen-go v1.32.0 +// protoc v4.25.3 // source: cluster-config.proto package v1alpha1 @@ -180,6 +180,7 @@ type GitOps struct { 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"` + BindAddress string `protobuf:"bytes,6,opt,name=bindAddress,proto3" json:"bindAddress,omitempty"` } func (x *GitOps) Reset() { @@ -249,6 +250,13 @@ func (x *GitOps) GetCredentials() *Credentials { return nil } +func (x *GitOps) GetBindAddress() string { + if x != nil { + return x.BindAddress + } + return "" +} + type Credentials struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -401,7 +409,7 @@ 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, 0xbd, 0x01, 0x0a, 0x06, 0x47, 0x69, 0x74, 0x4f, 0x70, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x6e, + 0x22, 0xdf, 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, @@ -413,14 +421,17 @@ var file_cluster_config_proto_rawDesc = []byte{ 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, + 0x12, 0x20, 0x0a, 0x0b, 0x62, 0x69, 0x6e, 0x64, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x62, 0x69, 0x6e, 0x64, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 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 8be8f0e..23ba9d9 100644 --- a/pkg/config/v1alpha1/schema.json +++ b/pkg/config/v1alpha1/schema.json @@ -30,6 +30,9 @@ }, "credentials": { "$ref": "#/$defs/Credentials" + }, + "bindAddress": { + "type": "string" } }, "additionalProperties": false, diff --git a/pkg/gitops/argocd/argocd.go b/pkg/gitops/argocd/argocd.go index 1056e2d..6ef0498 100644 --- a/pkg/gitops/argocd/argocd.go +++ b/pkg/gitops/argocd/argocd.go @@ -101,14 +101,19 @@ func (a *Agent) deployArgoCD(_ context.Context, ops *kubernetes.Cluster) error { logging.Log().Infoln("Port forward is not required") return nil } + // pull bind address from yaml config or default to 0.0.0.0 (maintaining backwards compatibility) + bindAddress := "0.0.0.0" + if ops.GetGitOps().GetBindAddress() != "" { + bindAddress = ops.GetGitOps().GetBindAddress() + } port := fmt.Sprintf("%s:8080", ops.GetGitOps().GetPort()) - cmd = exec.Command(a.cmd.Kubectl, "port-forward", "-n", ops.GetGitOps().GetNamespace(), "deploy/argocd-server", port, "--address", "0.0.0.0") + cmd = exec.Command(a.cmd.Kubectl, "port-forward", "-n", ops.GetGitOps().GetNamespace(), "deploy/argocd-server", port, "--address", bindAddress) // use start because we do not want to wait for the process to finish pid, err := tkexec.StartCommand(cmd) if err != nil { return fmt.Errorf("could not port foward argo server: %v", err) } - logging.Log().Infof("port forward pid: %d\n", pid) + logging.Log().Infof("port forward pid=%d,bind_addr=%s\n", pid, bindAddress) logging.Log().Infoln("argo cd deployed") return nil }