mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Allow no ports when exposing headless service
This commit is contained in:
@@ -186,6 +186,8 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
|
||||
params["selector"] = s
|
||||
}
|
||||
|
||||
isHeadlessService := params["cluster-ip"] == "None"
|
||||
|
||||
// For objects that need a port, derive it from the exposed object in case a user
|
||||
// didn't explicitly specify one via --port
|
||||
if port, found := params["port"]; found && kubectl.IsZero(port) {
|
||||
@@ -195,7 +197,9 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
|
||||
}
|
||||
switch len(ports) {
|
||||
case 0:
|
||||
return cmdutil.UsageError(cmd, "couldn't find port via --port flag or introspection")
|
||||
if !isHeadlessService {
|
||||
return cmdutil.UsageError(cmd, "couldn't find port via --port flag or introspection")
|
||||
}
|
||||
case 1:
|
||||
params["port"] = ports[0]
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user