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

Add FluxCD Application Management #743

Merged
merged 7 commits into from
Aug 25, 2022

Conversation

chengleqi
Copy link
Contributor

@chengleqi chengleqi commented Jul 18, 2022

What type of PR is this?

/kind feature
/kind design

What this PR does / why we need it:

  • Extend the gitops.kubesphere.io/v1alpha1/Application CRD to Support FluxApp.
  • Add fluxcd/application-controller to maintain the fluxcd Kustomization and HelmRelease.
  • Update the config/rbac/role.yaml
  • Add sample files in config/samples/gitops directory.

Which issue(s) this PR fixes:

Fixes #717 , #718

Special notes for reviewers:

Please check the following list before waiting reviewers:

  • Already committed the CRD files to the Helm Chart if you created some new CRDs
  • Already added the permission for the new API
  • Already added the RBAC markers for the new controllers

Does this PR introduce a user-facing change??

None

@ks-ci-bot ks-ci-bot requested a review from a team July 18, 2022 05:15
@ks-ci-bot ks-ci-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. kind/design Categorizes issue or PR as related to design. do-not-merge/release-note-label-needed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 18, 2022
@codecov
Copy link

codecov bot commented Jul 18, 2022

Codecov Report

Merging #743 (49dcc3f) into master (9367e7a) will increase coverage by 2.55%.
The diff coverage is 84.31%.

@@            Coverage Diff             @@
##           master     #743      +/-   ##
==========================================
+ Coverage   51.09%   53.65%   +2.55%     
==========================================
  Files         171      181      +10     
  Lines       10141    10668     +527     
==========================================
+ Hits         5182     5724     +542     
+ Misses       4666     4627      -39     
- Partials      293      317      +24     
Flag Coverage Δ
unittests 53.65% <84.31%> (+2.55%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/api/gitops/v1alpha1/application.go 100.00% <ø> (ø)
controllers/fluxcd/application-controller.go 84.10% <84.10%> (ø)
pkg/apis/apis.go 100.00% <100.00%> (ø)
pkg/client/devops/jenkins/credential.go 0.00% <0.00%> (-30.47%) ⬇️
pkg/kapis/devops/v1alpha2/register.go 95.29% <0.00%> (-0.16%) ⬇️
pkg/models/devops/common.go 100.00% <0.00%> (ø)
pkg/client/devops/jenkins/job.go 0.00% <0.00%> (ø)
pkg/client/devops/jenkins/build.go 0.00% <0.00%> (ø)
pkg/client/devops/jenkins/pipeline.go 5.52% <0.00%> (ø)
.../client/devops/jenkins/pipeline_model_converter.go 0.00% <0.00%> (ø)
... and 12 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@chengleqi
Copy link
Contributor Author

I encountered a strange problem when I wrote unit test due to the version of controller-runtime.

I use code like this r.Client.List(..., &unstructured.UnstructuredList{}, ...), It run correctly when the Client is RestClient, but It'll run into error when the client is fake client in the unit test scenario.

I found the root cause is this issue, but the PR which fix this issue was merged only in the 0.9.x version of controller-runtime, I tried to update the controller-runtime v0.6.3 => v0.9.7 but It caused too many changes.

So I Added code manually like this in the unit test:

schema.AddKnownTypeWithName(apischema.GroupVersionKind{
        Group:   "helm.toolkit.fluxcd.io",
        Version: "v2beta1",
        Kind:    "HelmReleaseList",
}, &unstructured.UnstructuredList{})

And the fluxcd project actually provide the module which include the HelmRelease type for convenience. But It also need higher version of controller-runtime.

Is it possible to update the controller-runtime version when it arrive version 1.0 or LTS ?

@chengleqi chengleqi marked this pull request as ready for review July 25, 2022 08:00
@ks-ci-bot ks-ci-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 25, 2022
@chengleqi
Copy link
Contributor Author

When I delete the gitops.kubesphere.io/Application I want to delete all HelmReleases belong to it. I can implement it just set the all HelmReleases' OwnerReferences to the Application. And I also can set the Finalizer on Application to deal with it.

Is there any different between the OwnerReferences solution and the Finalizer solution in this situation?

@LinuxSuRen
Copy link
Member

Is there any different between the OwnerReferences solution and the Finalizer solution in this situation?

I'm not sure if I understand it correctly. But it might be helpful for you.

IMO, the OwnerReferences is a built-in controller for resource collection. It could help you to delete Kubernetes CR (custom resource) instead of others (Jenkins jobs .e.g.). And for this case, the child resource does not have its own life cycle.

The Finalizer could let you delete any resources that you want.

See also https://kubernetes.io/blog/2021/05/14/using-finalizers-to-control-deletion/

@chengleqi
Copy link
Contributor Author

Is there any different between the OwnerReferences solution and the Finalizer solution in this situation?

I'm not sure if I understand it correctly. But it might be helpful for you.

IMO, the OwnerReferences is a built-in controller for resource collection. It could help you to delete Kubernetes CR (custom resource) instead of others (Jenkins jobs .e.g.). And for this case, the child resource does not have its own life cycle.

The Finalizer could let you delete any resources that you want.

See also https://kubernetes.io/blog/2021/05/14/using-finalizers-to-control-deletion/

Thanks a lot, this is very helpful.

controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
controllers/fluxcd/application-controller.go Show resolved Hide resolved
controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
pkg/api/gitops/v1alpha1/application.go Show resolved Hide resolved
@chengleqi
Copy link
Contributor Author

/test ?

@ks-ci-bot
Copy link
Collaborator

@chengleqi: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test ?

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@lxm
Copy link
Member

lxm commented Aug 16, 2022

@chengleqi: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

@kubesphere/sig-devops @LinuxSuRen

@ks-ci-bot
Copy link
Collaborator

@lxm: changing LGTM is restricted to collaborators

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@lxm
Copy link
Member

lxm commented Aug 17, 2022

@kubesphere/sig-devops

@LinuxSuRen
Copy link
Member

/test ?

You can retrigger the actions once you close and reopen this PR.

@lxm
Copy link
Member

lxm commented Aug 20, 2022

while controller-runtime version has been updated to v0.12.3 with #788.
some previously change requests in the PR can be performed, such as data struct import method

chengleqi and others added 4 commits August 23, 2022 18:11
Signed-off-by: chengleqi <leqicheng@stu.xidian.edu.cn>
Change Named design

Signed-off-by: chengleqi <leqicheng@stu.xidian.edu.cn>
Signed-off-by: chengleqi <leqicheng@stu.xidian.edu.cn>
@chengleqi chengleqi force-pushed the add-app-ctrl branch 2 times, most recently from 10ae430 to 24226d2 Compare August 23, 2022 14:25
@chengleqi chengleqi closed this Aug 23, 2022
@chengleqi chengleqi reopened this Aug 23, 2022
@chengleqi chengleqi closed this Aug 24, 2022
@chengleqi chengleqi reopened this Aug 24, 2022
Signed-off-by: chengleqi <leqicheng@stu.xidian.edu.cn>
Makefile Outdated Show resolved Hide resolved
controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
pkg/api/gitops/v1alpha1/application.go Outdated Show resolved Hide resolved
pkg/api/gitops/v1alpha1/application.go Outdated Show resolved Hide resolved
pkg/api/gitops/v1alpha1/constants.go Outdated Show resolved Hide resolved
@LinuxSuRen
Copy link
Member

Please try not to use force action. I need to review all files one by one if you push the code with the force option.

Signed-off-by: chengleqi <leqicheng@stu.xidian.edu.cn>
Copy link
Member

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

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

/lgtm

@ks-ci-bot ks-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 24, 2022
controllers/fluxcd/application-controller.go Outdated Show resolved Hide resolved
@ks-ci-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from linuxsuren after the PR has been reviewed.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Signed-off-by: chengleqi <leqicheng@stu.xidian.edu.cn>
@ks-ci-bot ks-ci-bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 25, 2022
@lxm
Copy link
Member

lxm commented Aug 25, 2022

lgtm @kubesphere/sig-devops @LinuxSuRen

Copy link
Member

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

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

/lgtm

@ks-ci-bot ks-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 25, 2022
@LinuxSuRen LinuxSuRen merged commit 5a189fa into kubesphere:master Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/design Categorizes issue or PR as related to design. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note-none size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FluxCD Integration] Update the gitops.kubesphere.io/v1alpha1 CRD to Support FluxCD Application
4 participants