From dbff027ff02b696d0293c74e26308e51172611d7 Mon Sep 17 00:00:00 2001 From: shuangkun tian <72060326+shuangkun@users.noreply.github.com> Date: Sat, 23 Mar 2024 01:00:36 +0800 Subject: [PATCH] fix: pass dnsconfig to agent pod. Fixes: #12824 (#12825) Signed-off-by: shuangkun --- api/jsonschema/schema.json | 2 +- api/openapi-spec/swagger.json | 2 +- docs/fields.md | 2 +- pkg/apis/workflow/v1alpha1/generated.proto | 2 +- .../workflow/v1alpha1/openapi_generated.go | 2 +- pkg/apis/workflow/v1alpha1/workflow_types.go | 2 +- .../IoArgoprojWorkflowV1alpha1WorkflowSpec.md | 2 +- ...rgoproj_workflow_v1alpha1_workflow_spec.py | 4 ++-- .../IoArgoprojWorkflowV1alpha1WorkflowSpec.md | 2 +- workflow/controller/agent.go | 1 + workflow/controller/workflowpod.go | 19 ++++++++++++------- 11 files changed, 23 insertions(+), 17 deletions(-) diff --git a/api/jsonschema/schema.json b/api/jsonschema/schema.json index 982416175d60..50034e0bb349 100644 --- a/api/jsonschema/schema.json +++ b/api/jsonschema/schema.json @@ -7389,7 +7389,7 @@ "description": "PodDNSConfig defines the DNS parameters of a pod in addition to those generated from DNSPolicy." }, "dnsPolicy": { - "description": "Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.", + "description": "Set DNS policy for workflow pods. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.", "type": "string" }, "entrypoint": { diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 46f6d2d730b1..9cfbc9a78399 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -11312,7 +11312,7 @@ "$ref": "#/definitions/io.k8s.api.core.v1.PodDNSConfig" }, "dnsPolicy": { - "description": "Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.", + "description": "Set DNS policy for workflow pods. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.", "type": "string" }, "entrypoint": { diff --git a/docs/fields.md b/docs/fields.md index 604d0b5de42c..54b6db15bbbc 100644 --- a/docs/fields.md +++ b/docs/fields.md @@ -801,7 +801,7 @@ WorkflowSpec is the specification of a Workflow. |`artifactRepositoryRef`|[`ArtifactRepositoryRef`](#artifactrepositoryref)|ArtifactRepositoryRef specifies the configMap name and key containing the artifact repository config.| |`automountServiceAccountToken`|`boolean`|AutomountServiceAccountToken indicates whether a service account token should be automatically mounted in pods. ServiceAccountName of ExecutorConfig must be specified if this value is false.| |`dnsConfig`|[`PodDNSConfig`](#poddnsconfig)|PodDNSConfig defines the DNS parameters of a pod in addition to those generated from DNSPolicy.| -|`dnsPolicy`|`string`|Set DNS policy for the pod. Defaults to "ClusterFirst". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.| +|`dnsPolicy`|`string`|Set DNS policy for workflow pods. Defaults to "ClusterFirst". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.| |`entrypoint`|`string`|Entrypoint is a template reference to the starting point of the io.argoproj.workflow.v1alpha1.| |`executor`|[`ExecutorConfig`](#executorconfig)|Executor holds configurations of executor containers of the io.argoproj.workflow.v1alpha1.| |`hooks`|[`LifecycleHook`](#lifecyclehook)|Hooks holds the lifecycle hook which is invoked at lifecycle of step, irrespective of the success, failure, or error status of the primary step| diff --git a/pkg/apis/workflow/v1alpha1/generated.proto b/pkg/apis/workflow/v1alpha1/generated.proto index c06d42d0e9c2..221f9f64d9c9 100644 --- a/pkg/apis/workflow/v1alpha1/generated.proto +++ b/pkg/apis/workflow/v1alpha1/generated.proto @@ -1975,7 +1975,7 @@ message WorkflowSpec { // Host networking requested for this workflow pod. Default to false. optional bool hostNetwork = 14; - // Set DNS policy for the pod. + // Set DNS policy for workflow pods. // Defaults to "ClusterFirst". // Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. // DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. diff --git a/pkg/apis/workflow/v1alpha1/openapi_generated.go b/pkg/apis/workflow/v1alpha1/openapi_generated.go index 10aaa7b910e8..07e6b6c6c466 100644 --- a/pkg/apis/workflow/v1alpha1/openapi_generated.go +++ b/pkg/apis/workflow/v1alpha1/openapi_generated.go @@ -7547,7 +7547,7 @@ func schema_pkg_apis_workflow_v1alpha1_WorkflowSpec(ref common.ReferenceCallback }, "dnsPolicy": { SchemaProps: spec.SchemaProps{ - Description: "Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.", + Description: "Set DNS policy for workflow pods. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.", Type: []string{"string"}, Format: "", }, diff --git a/pkg/apis/workflow/v1alpha1/workflow_types.go b/pkg/apis/workflow/v1alpha1/workflow_types.go index 7ef912919d00..b883eb4552cd 100644 --- a/pkg/apis/workflow/v1alpha1/workflow_types.go +++ b/pkg/apis/workflow/v1alpha1/workflow_types.go @@ -326,7 +326,7 @@ type WorkflowSpec struct { // Host networking requested for this workflow pod. Default to false. HostNetwork *bool `json:"hostNetwork,omitempty" protobuf:"bytes,14,opt,name=hostNetwork"` - // Set DNS policy for the pod. + // Set DNS policy for workflow pods. // Defaults to "ClusterFirst". // Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. // DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. diff --git a/sdks/java/client/docs/IoArgoprojWorkflowV1alpha1WorkflowSpec.md b/sdks/java/client/docs/IoArgoprojWorkflowV1alpha1WorkflowSpec.md index 24e847068076..e889ac8f8756 100644 --- a/sdks/java/client/docs/IoArgoprojWorkflowV1alpha1WorkflowSpec.md +++ b/sdks/java/client/docs/IoArgoprojWorkflowV1alpha1WorkflowSpec.md @@ -16,7 +16,7 @@ Name | Type | Description | Notes **artifactRepositoryRef** | [**IoArgoprojWorkflowV1alpha1ArtifactRepositoryRef**](IoArgoprojWorkflowV1alpha1ArtifactRepositoryRef.md) | | [optional] **automountServiceAccountToken** | **Boolean** | AutomountServiceAccountToken indicates whether a service account token should be automatically mounted in pods. ServiceAccountName of ExecutorConfig must be specified if this value is false. | [optional] **dnsConfig** | [**io.kubernetes.client.openapi.models.V1PodDNSConfig**](io.kubernetes.client.openapi.models.V1PodDNSConfig.md) | | [optional] -**dnsPolicy** | **String** | Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'. | [optional] +**dnsPolicy** | **String** | Set DNS policy for workflow pods. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'. | [optional] **entrypoint** | **String** | Entrypoint is a template reference to the starting point of the io.argoproj.workflow.v1alpha1. | [optional] **executor** | [**IoArgoprojWorkflowV1alpha1ExecutorConfig**](IoArgoprojWorkflowV1alpha1ExecutorConfig.md) | | [optional] **hooks** | [**Map<String, IoArgoprojWorkflowV1alpha1LifecycleHook>**](IoArgoprojWorkflowV1alpha1LifecycleHook.md) | Hooks holds the lifecycle hook which is invoked at lifecycle of step, irrespective of the success, failure, or error status of the primary step | [optional] diff --git a/sdks/python/client/argo_workflows/model/io_argoproj_workflow_v1alpha1_workflow_spec.py b/sdks/python/client/argo_workflows/model/io_argoproj_workflow_v1alpha1_workflow_spec.py index d56f6e163032..3a5e330beda5 100644 --- a/sdks/python/client/argo_workflows/model/io_argoproj_workflow_v1alpha1_workflow_spec.py +++ b/sdks/python/client/argo_workflows/model/io_argoproj_workflow_v1alpha1_workflow_spec.py @@ -276,7 +276,7 @@ def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 artifact_repository_ref (IoArgoprojWorkflowV1alpha1ArtifactRepositoryRef): [optional] # noqa: E501 automount_service_account_token (bool): AutomountServiceAccountToken indicates whether a service account token should be automatically mounted in pods. ServiceAccountName of ExecutorConfig must be specified if this value is false.. [optional] # noqa: E501 dns_config (PodDNSConfig): [optional] # noqa: E501 - dns_policy (str): Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.. [optional] # noqa: E501 + dns_policy (str): Set DNS policy for workflow pods. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.. [optional] # noqa: E501 entrypoint (str): Entrypoint is a template reference to the starting point of the io.argoproj.workflow.v1alpha1.. [optional] # noqa: E501 executor (IoArgoprojWorkflowV1alpha1ExecutorConfig): [optional] # noqa: E501 hooks ({str: (IoArgoprojWorkflowV1alpha1LifecycleHook,)}): Hooks holds the lifecycle hook which is invoked at lifecycle of step, irrespective of the success, failure, or error status of the primary step. [optional] # noqa: E501 @@ -399,7 +399,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 artifact_repository_ref (IoArgoprojWorkflowV1alpha1ArtifactRepositoryRef): [optional] # noqa: E501 automount_service_account_token (bool): AutomountServiceAccountToken indicates whether a service account token should be automatically mounted in pods. ServiceAccountName of ExecutorConfig must be specified if this value is false.. [optional] # noqa: E501 dns_config (PodDNSConfig): [optional] # noqa: E501 - dns_policy (str): Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.. [optional] # noqa: E501 + dns_policy (str): Set DNS policy for workflow pods. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'.. [optional] # noqa: E501 entrypoint (str): Entrypoint is a template reference to the starting point of the io.argoproj.workflow.v1alpha1.. [optional] # noqa: E501 executor (IoArgoprojWorkflowV1alpha1ExecutorConfig): [optional] # noqa: E501 hooks ({str: (IoArgoprojWorkflowV1alpha1LifecycleHook,)}): Hooks holds the lifecycle hook which is invoked at lifecycle of step, irrespective of the success, failure, or error status of the primary step. [optional] # noqa: E501 diff --git a/sdks/python/client/docs/IoArgoprojWorkflowV1alpha1WorkflowSpec.md b/sdks/python/client/docs/IoArgoprojWorkflowV1alpha1WorkflowSpec.md index d0ac0b10fbb6..3f9ded2612a9 100644 --- a/sdks/python/client/docs/IoArgoprojWorkflowV1alpha1WorkflowSpec.md +++ b/sdks/python/client/docs/IoArgoprojWorkflowV1alpha1WorkflowSpec.md @@ -13,7 +13,7 @@ Name | Type | Description | Notes **artifact_repository_ref** | [**IoArgoprojWorkflowV1alpha1ArtifactRepositoryRef**](IoArgoprojWorkflowV1alpha1ArtifactRepositoryRef.md) | | [optional] **automount_service_account_token** | **bool** | AutomountServiceAccountToken indicates whether a service account token should be automatically mounted in pods. ServiceAccountName of ExecutorConfig must be specified if this value is false. | [optional] **dns_config** | [**PodDNSConfig**](PodDNSConfig.md) | | [optional] -**dns_policy** | **str** | Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'. | [optional] +**dns_policy** | **str** | Set DNS policy for workflow pods. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy. To have DNS options set along with hostNetwork, you have to specify DNS policy explicitly to 'ClusterFirstWithHostNet'. | [optional] **entrypoint** | **str** | Entrypoint is a template reference to the starting point of the io.argoproj.workflow.v1alpha1. | [optional] **executor** | [**IoArgoprojWorkflowV1alpha1ExecutorConfig**](IoArgoprojWorkflowV1alpha1ExecutorConfig.md) | | [optional] **hooks** | [**{str: (IoArgoprojWorkflowV1alpha1LifecycleHook,)}**](IoArgoprojWorkflowV1alpha1LifecycleHook.md) | Hooks holds the lifecycle hook which is invoked at lifecycle of step, irrespective of the success, failure, or error status of the primary step | [optional] diff --git a/workflow/controller/agent.go b/workflow/controller/agent.go index e728ad799d3d..efb4fa502060 100644 --- a/workflow/controller/agent.go +++ b/workflow/controller/agent.go @@ -243,6 +243,7 @@ func (woc *wfOperationCtx) createAgentPod(ctx context.Context) (*apiv1.Pod, erro tmpl := &wfv1.Template{} woc.addSchedulingConstraints(pod, woc.execWf.Spec.DeepCopy(), tmpl, "") woc.addMetadata(pod, tmpl) + woc.addDNSConfig(pod) if woc.execWf.Spec.HasPodSpecPatch() { patchedPodSpec, err := util.ApplyPodSpecPatch(pod.Spec, woc.execWf.Spec.PodSpecPatch) diff --git a/workflow/controller/workflowpod.go b/workflow/controller/workflowpod.go index b4114e386c32..b31bd71dd070 100644 --- a/workflow/controller/workflowpod.go +++ b/workflow/controller/workflowpod.go @@ -200,13 +200,7 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin pod.Spec.HostNetwork = *woc.execWf.Spec.HostNetwork } - if woc.execWf.Spec.DNSPolicy != nil { - pod.Spec.DNSPolicy = *woc.execWf.Spec.DNSPolicy - } - - if woc.execWf.Spec.DNSConfig != nil { - pod.Spec.DNSConfig = woc.execWf.Spec.DNSConfig - } + woc.addDNSConfig(pod) if woc.controller.Config.InstanceID != "" { pod.ObjectMeta.Labels[common.LabelKeyControllerInstanceID] = woc.controller.Config.InstanceID @@ -756,6 +750,17 @@ func (woc *wfOperationCtx) addMetadata(pod *apiv1.Pod, tmpl *wfv1.Template) { } } +// addDNSConfig applies DNSConfig to the pod +func (woc *wfOperationCtx) addDNSConfig(pod *apiv1.Pod) { + if woc.execWf.Spec.DNSPolicy != nil { + pod.Spec.DNSPolicy = *woc.execWf.Spec.DNSPolicy + } + + if woc.execWf.Spec.DNSConfig != nil { + pod.Spec.DNSConfig = woc.execWf.Spec.DNSConfig + } +} + // addSchedulingConstraints applies any node selectors or affinity rules to the pod, either set in the workflow or the template func (woc *wfOperationCtx) addSchedulingConstraints(pod *apiv1.Pod, wfSpec *wfv1.WorkflowSpec, tmpl *wfv1.Template, nodeName string) { // Get boundaryNode Template (if specified)