feat: support targetPort option in goctl kube (#2378)

This commit is contained in:
Kevin Wan
2022-09-12 20:42:41 +08:00
committed by GitHub
parent 66c2a28e66
commit 3e96994b7b
4 changed files with 122 additions and 5 deletions

View File

@@ -16,6 +16,7 @@ var (
varIntRevisions int
varIntPort int
varIntNodePort int
varIntTargetPort int
varIntMinReplicas int
varIntMaxReplicas int
varStringHome string
@@ -51,6 +52,7 @@ func init() {
deployCmd.Flags().IntVar(&varIntRevisions, "revisions", 5, "The number of revision history to limit")
deployCmd.Flags().IntVar(&varIntPort, "port", 0, "The port of the deployment to listen on pod (required)")
deployCmd.Flags().IntVar(&varIntNodePort, "nodePort", 0, "The nodePort of the deployment to expose")
deployCmd.Flags().IntVar(&varIntTargetPort, "targetPort", 0, "The targetPort of the deployment, default to port")
deployCmd.Flags().IntVar(&varIntMinReplicas, "minReplicas", 3, "The min replicas to deploy")
deployCmd.Flags().IntVar(&varIntMaxReplicas, "maxReplicas", 10, "The max replicas to deploy")
deployCmd.Flags().StringVar(&varStringImagePullPolicy, "imagePullPolicy", "", "Image pull policy. One of Always, Never, IfNotPresent")

View File

@@ -59,11 +59,12 @@ metadata:
namespace: {{.Namespace}}
spec:
ports:
{{if .UseNodePort}}- nodePort: {{.NodePort}}
port: {{.Port}}
protocol: TCP
targetPort: {{.Port}}
type: NodePort{{else}}- port: {{.Port}}{{end}}
{{if .UseNodePort}}- nodePort: {{.NodePort}}
port: {{.Port}}
protocol: TCP
targetPort: {{.TargetPort}}
type: NodePort{{else}}- port: {{.Port}}
targetPort: {{.TargetPort}}{{end}}
selector:
app: {{.Name}}

View File

@@ -36,6 +36,7 @@ type Deployment struct {
Replicas int
Revisions int
Port int
TargetPort int
NodePort int
UseNodePort bool
RequestCpu int
@@ -81,6 +82,10 @@ func deploymentCommand(_ *cobra.Command, _ []string) error {
}
defer out.Close()
if varIntTargetPort == 0 {
varIntTargetPort = varIntPort
}
t := template.Must(template.New("deploymentTemplate").Parse(text))
err = t.Execute(out, Deployment{
Name: varStringName,
@@ -90,6 +95,7 @@ func deploymentCommand(_ *cobra.Command, _ []string) error {
Replicas: varIntReplicas,
Revisions: varIntRevisions,
Port: varIntPort,
TargetPort: varIntTargetPort,
NodePort: nodePort,
UseNodePort: nodePort > 0,
RequestCpu: varIntRequestCpu,