Skip to content

Commit

Permalink
Paramaterize kubectl port-forward bind address (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfordwagner authored Feb 22, 2024
1 parent a34e40f commit b019ea2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pkg/config/proto/cluster-config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ message GitOps {
string manifestPath = 3;
bool noPortForward = 4;
Credentials credentials = 5;
string bindAddress = 6;
}

message Credentials {
Expand All @@ -32,4 +33,4 @@ message Credentials {

message ClusterArgs {
repeated string args = 2;
}
}
1 change: 1 addition & 0 deletions pkg/config/testdata/clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ clusters:
namespace: argocd
port: '8080'
manifestPath: "./manifests/argo-cd/"
bindAddress: localhost
credentials:
username: admin
password: admin1234
Expand Down
33 changes: 22 additions & 11 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 @@ -30,6 +30,9 @@
},
"credentials": {
"$ref": "#/$defs/Credentials"
},
"bindAddress": {
"type": "string"
}
},
"additionalProperties": false,
Expand Down
9 changes: 7 additions & 2 deletions pkg/gitops/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b019ea2

Please sign in to comment.