Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow to pass optional flags to resource template #1779

Merged
merged 5 commits into from
Apr 15, 2020

Conversation

CermakM
Copy link
Contributor

@CermakM CermakM commented Nov 19, 2019

In some cases, it might be useful to have the option to pass optional flags to a resource template.

For example, to turn off kubectl default validation when submitting a resource manifest. OpenShift has some strict requirements (and in case of OpenShift 3.11 even discrepancies) in the oapi spec, which prevents resources from being submitted via kubectl

This patch introduces the Template.Spec.Resource.Flags parameter which allows to pass optional flags to a resource template.

Example:

resource:
  action: create
  flags: [
    "--validate=false"  # validation will be turned off
  ]
  manifest: |
    apiVersion: route.openshift.io/v1
    kind: Route
    metadata:
      name: host-route
    spec:
      to:
        kind: Service
        name: service-name

@CermakM CermakM changed the title Resource validation Allow to disable kubectl resource validation Nov 19, 2019
Copy link
Member

@sarabala1979 sarabala1979 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add examples

@CermakM
Copy link
Contributor Author

CermakM commented Nov 20, 2019

The example references openshift/origin#24060

@CermakM
Copy link
Contributor Author

CermakM commented Nov 21, 2019

Could I ask for help with the CI check? I am kinda struggling to understand the reason it failed.

@simster7
Copy link
Member

Looks like a network issue when running dep ensure. Doesn't seem like you changed any dependencies, so don't worry about it. @sarabala1979 will re-run the CI when he reviews your PR.

@sarabala1979 sarabala1979 changed the title Allow to disable kubectl resource validation feat: Allow to disable kubectl resource validation Dec 16, 2019
@simster7
Copy link
Member

I think that this PR could become more generalized by allowing the user to pass arbitrary arguments to kubectl. If we merge this, other users could request a similar implementation for other flags, which could cause it to get cluttered.

Something like:

  - name: create-route-without-validation
    resource:
      action: create
      flags: ["--validate=false"]  # validation will be turned off

could work.

Will open this as a new issue. @CermakM do you want to own this?

(P.S. Not that this is slightly different from the open #1834 as that requires executor changes, so it still requires its own PR)

@CermakM
Copy link
Contributor Author

CermakM commented Dec 17, 2019

@simster7 This looks reasonable to me and I'll be happy to extend the implementation :) I suppose we therefore want to have just flags, instead of both flags and validate, correct?

EDIT: Commented on the issue as well.

@CermakM CermakM force-pushed the resource-validation branch 2 times, most recently from 020c8a9 to 03c3f4d Compare January 2, 2020 12:03
@CermakM CermakM changed the title feat: Allow to disable kubectl resource validation feat: Allow to pass optional flags to resource template Jan 2, 2020
@CermakM
Copy link
Contributor Author

CermakM commented Jan 2, 2020

Fixes: #1857

@codecov
Copy link

codecov bot commented Jan 2, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@f3df966). Click here to learn what that means.
The diff coverage is 13.15%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1779   +/-   ##
=========================================
  Coverage          ?   11.39%           
=========================================
  Files             ?       74           
  Lines             ?    31163           
  Branches          ?        0           
=========================================
  Hits              ?     3550           
  Misses            ?    27134           
  Partials          ?      479
Impacted Files Coverage Δ
pkg/apis/workflow/v1alpha1/workflow_types.go 11.54% <ø> (ø)
...kg/apis/workflow/v1alpha1/zz_generated.deepcopy.go 0% <0%> (ø)
pkg/apis/workflow/v1alpha1/generated.pb.go 0.45% <0%> (ø)
workflow/executor/resource.go 6.46% <28.57%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3df966...c182b3b. Read the comment docs.

CermakM pushed a commit to CermakM/amun-api that referenced this pull request Jan 2, 2020
See argoproj/argo-workflows#1779

Signed-off-by: Marek Cermak <macermak@redhat.com>

modified:   workflows/templates/inspection-build-template.yaml
modified:   workflows/templates/inspection-build-with-cpu-template.yaml
@simster7 simster7 self-assigned this Jan 7, 2020
Copy link
Member

@simster7 simster7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM! Could you add some tests please?

@CermakM
Copy link
Contributor Author

CermakM commented Jan 8, 2020

Uh, well, I hoped you wouldn't say that :D I'll see what I can do.

CermakM pushed a commit to CermakM/amun-api that referenced this pull request Jan 16, 2020
See argoproj/argo-workflows#1779

Signed-off-by: Marek Cermak <macermak@redhat.com>

modified:   workflows/templates/inspection-build-template.yaml
modified:   workflows/templates/inspection-build-with-cpu-template.yaml
@maximmold
Copy link

Does this implementation require a manifest? I want to delete given a particular label in an argo work flow and I seem to only be able to do it with a specific manifest that requires a metadata.name

@CermakM CermakM force-pushed the resource-validation branch from 03c3f4d to 7b64016 Compare January 26, 2020 18:32
@CermakM
Copy link
Contributor Author

CermakM commented Jan 26, 2020

@maximmold I am sorry, struggling to understand your use case a little bit. Could you please elaborate or provide an example of how would you imagine that being used other than in the ResourceTemplate?

@CermakM CermakM force-pushed the resource-validation branch from 7b64016 to 2062de8 Compare January 26, 2020 19:14
@CermakM CermakM requested a review from simster7 January 26, 2020 20:36
CermakM pushed a commit to CermakM/amun-api that referenced this pull request Jan 27, 2020
See argoproj/argo-workflows#1779

Signed-off-by: Marek Cermak <macermak@redhat.com>

modified:   workflows/templates/inspection-build-template.yaml
modified:   workflows/templates/inspection-build-with-cpu-template.yaml
@maximmold
Copy link

I simply want to be able to do a delete of resources given a particular label selector.

- name: delete-resources-without-validation
    resource:
      action: delete
      flags: ["seldondeployment -l github-branch={{workflow.parameters.github-branch}}"]

Providing a manifest requires you know the same of the resource.

@CermakM
Copy link
Contributor Author

CermakM commented Jan 27, 2020

Ah, gotcha. Let me take a look at it. I think it shouldn't require many changes.

@simster7
Copy link
Member

Will try to get some internal comments w.r.t this PR today

CermakM pushed a commit to CermakM/amun-api that referenced this pull request Jan 30, 2020
See argoproj/argo-workflows#1779

Signed-off-by: Marek Cermak <macermak@redhat.com>

modified:   workflows/templates/inspection-build-template.yaml
modified:   workflows/templates/inspection-build-with-cpu-template.yaml
CermakM pushed a commit to CermakM/amun-api that referenced this pull request Feb 19, 2020
See argoproj/argo-workflows#1779

Signed-off-by: Marek Cermak <macermak@redhat.com>

modified:   workflows/templates/inspection-build-template.yaml
modified:   workflows/templates/inspection-build-with-cpu-template.yaml
@alexec
Copy link
Contributor

alexec commented Mar 18, 2020

@CermakM is this still wanted please?

@CermakM
Copy link
Contributor Author

CermakM commented Mar 19, 2020

@alexec Yes it is. I guess I have quite a lot of rebasing to do. :/

@CermakM CermakM force-pushed the resource-validation branch from 9b8d5a5 to cc94c54 Compare March 19, 2020 08:24
@alexec
Copy link
Contributor

alexec commented Mar 19, 2020

@simster7 do you want to continue as reviewer?

@CermakM
Copy link
Contributor Author

CermakM commented Mar 20, 2020

Is the failure of Golang CI setup on my side? 🤔

@CermakM CermakM force-pushed the resource-validation branch from cc94c54 to fb6522a Compare March 20, 2020 11:25
@simster7
Copy link
Member

@simster7 do you want to continue as reviewer?

Yes, sorry this got out of my radar. I'll give another review today

Copy link
Member

@simster7 simster7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor changes, otherwise LGTM.

I have reservations about security. With this PR we effectively give the workflow submitter full access to kubectl. I'm going to bring this up with @jessesuen, but feel free to chime in with your opinions.

workflow/executor/resource.go Outdated Show resolved Hide resolved
workflow/executor/resource.go Outdated Show resolved Hide resolved
@CermakM
Copy link
Contributor Author

CermakM commented Mar 23, 2020

@simster7 you're right, but IMHO it is not Argo who should impose security restrictions, it is the cluster/namespace admin, I.e. if users have the rights to execute a certain command via kubectl, they should be able to do that in Argo as well, shouldn't they?

@CermakM CermakM force-pushed the resource-validation branch from b2c42d1 to 4ed2795 Compare March 23, 2020 09:20
@simster7
Copy link
Member

@simster7 you're right, but IMHO it is not Argo who should impose security restrictions, it is the cluster/namespace admin, I.e. if users have the rights to execute a certain command via kubectl, they should be able to do that in Argo as well, shouldn't they?

You're right, except that Argo its own ServiceAccount with kubectl – not the user's – so with this PR we give free reign to the submitter to use Argo's ServiceAccount. However, @jessesuen brought up a good point by saying that we effectively already do this since users can submit arbitrary containers... so it looks like we're going to go ahead with this.

- added an example for resource flags
- added a test for resource flags
- allow to use resource flags without manifest

Signed-off-by: Marek Cermak <macermak@redhat.com>

modified:   cmd/argoexec/commands/resource.go
modified:   pkg/apis/workflow/v1alpha1/workflow_types.go
modified:   workflow/executor/resource.go

new file:   examples/resource-delete-with-flags.yaml
new file:   examples/resource-flags.yaml
new file:   workflow/executor/resource_test.go
@CermakM CermakM force-pushed the resource-validation branch from c182b3b to 8f772da Compare April 14, 2020 11:40
@CermakM
Copy link
Contributor Author

CermakM commented Apr 14, 2020

@simster7 I rebased it once again and pushed it without updated codegen, which causes the conflicts (which, in turn, I assume, have been blocking the merging the whole time). Please, if / when you decide to merge this, generate the codegen as well.

Cheers,
M

@sonarcloud
Copy link

sonarcloud bot commented Apr 15, 2020

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

51.4% 51.4% Coverage
0.0% 0.0% Duplication

@simster7 simster7 merged commit 2737c0a into argoproj:master Apr 15, 2020
@simster7
Copy link
Member

Thanks for your work @CermakM! Glad we finally got this merged

@CermakM
Copy link
Contributor Author

CermakM commented Apr 20, 2020

Thanks @simster7 !

@m-yosefpor
Copy link

I'm new to Argo. Will this solve the issue with Openshift resources when used with ArgoCD as well? or will it only affect argo workflows?

@m-yosefpor
Copy link

m-yosefpor commented Nov 3, 2020

I found this option in Application object:

syncPolicy:
  syncOptions:
    - Validate=false

However is it possible to disable it per resource (instead of the whole app)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants