-
Notifications
You must be signed in to change notification settings - Fork 101
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 Flux support to install resources from git source: #255
Conversation
Hi @matrus2. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matrus2 Thanks for this great contribution.
@@ -0,0 +1,86 @@ | |||
/* | |||
Copyright 2021 The Kubernetes Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see Copyrights added in the new files are for 2021 and 2022. Kindly update it with the latest Copyright (Copyright 2023 The Kubernetes Authors.)
pkg/envfuncs/third_party_funcs.go
Outdated
@@ -0,0 +1,40 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file can be moved under third-party/flux to maintain the structuring we followed for the other third-party support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second that. Putting flux references in pkg would make it a required dependency when pulling the project, whether you want it or not.
/ok-to-test |
/cc @vladimirvivien |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great contribution. And it is a great start.
Let's continue the review process to get it where it needs to land.
kustomizationName := "hello-world" | ||
|
||
feature := features.New("Install resources by flux"). | ||
Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: this setup/teardown probably belongs in a test environment setup/finish block in TestMain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a great point, agree. It should go to setup block.
pkg/envfuncs/third_party_funcs.go
Outdated
@@ -0,0 +1,40 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second that. Putting flux references in pkg would make it a required dependency when pulling the project, whether you want it or not.
t.Fatal("failed to create git repository", err) | ||
} | ||
// Set --prune so that once deleteKustomization will be called all corresponding resources will be removed | ||
err = manager.CreateKustomization(kustomizationName, "GitRepository/hello-world.flux-system", flux.WithPath("template"), flux.WithArgs("--target-namespace", c.Namespace(), "--prune")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: where is the kustomization file GitRepository/hello-world.flux-system
coming from ? Is it pulled from the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitRepository/hello-world.flux-system is a reference to GitRepository object in the flux-system namespace created in previous step. Basically, GitRepository is the declaration of a git repository and reference to the source of manifest files:
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: hello-world
namespace: flux-system
spec:
interval: 10m
ref:
branch: main
url: ssh://git@github.com/matrus2/go-hello-world
The Kustomization is a specification, which files form Git Repository and how they should be deployed. In this example we deploy files from path template
within 1 minute interval to target namespace default. See below the example:
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: hello-world
namespace: flux-system
spec:
interval: 1m
targetNamespace: default
path: template
prune: true
sourceRef:
kind: GitRepository
name: hello-world
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome @matrus2 .
I would suggest to add documentation comments for the functions in package third_party/flux
envfuncs.CreateKindCluster(kindClusterName), | ||
envfuncs.CreateNamespace(namespace), | ||
flux.InstallFlux(), | ||
flux.CreateGitRepo(gitRepoName, "https://github.com/matrus2/go-hello-world", flux.WithBranch("main")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to find a better way to manage this repository may be. I would rather have this repo co-located with some kubernetes-sigs
org than have it in a personal repo and then use it here. cc @vladimirvivien
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative, We could actually have a self-referencing repo and point the test to use e2e-framework
repo itself. We can create the sample customization template and other bits and use that from here directly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in fact this was the plan to move it here to e2e-framework
repo after merge of this PR. I see two possible scenarios:
- Merge this PR and later move the manifests to
e2e-framework
and at the same time harden the security and reference not a branch, but a commit SHA, so that we ensure no new unexpected changes will land to external repo. - Split this PR and first move manifests from external repo to
e2e-framework
, and in the next PR reference it via Flux.
Please advice which one you prefer.
third_party/flux/flux_setup.go
Outdated
|
||
const NoFluxInstallationFoundMsg = "flux needs to be installed within a cluster first" | ||
|
||
func InstallFlux() env.Func { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be a good idea to take the namespace as an optional argument here so that one can easily install this on a non standard flux-system
namespace ?
third_party/flux/cmd_manager.go
Outdated
const ( | ||
Git Source = iota | ||
Bucket | ||
Helm | ||
Oci | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be easier to define a custom type for Source
as string and define these as string values directly instead of using .String()
function ?
third_party/flux/flux_setup.go
Outdated
} | ||
} | ||
|
||
func UninstallFlux() env.Func { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some documentation for these helper functions.
flux.InstallFlux(), | ||
flux.CreateGitRepo(gitRepoName, "https://github.com/matrus2/go-hello-world", flux.WithBranch("main")), | ||
flux.CreateKustomization(ksName, "GitRepository/"+gitRepoName+".flux-system", flux.WithPath("template"), flux.WithArgs("--target-namespace", namespace, "--prune")), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also noticed that the repo https://github.com/matrus2/go-hello-world/blob/main/template/deployment.yaml#L18 hardcodes the image reference. Don't we need to create a ImageUpdateAutomation
for it to really do the right thing ? Also I am not sure if we have any precedence for this where the image from a personal dockerhub repo is included into the rest util. May be we should move all of these repo and images to a common location and manage them like we do for rest of the test images and others in k8s ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the purpose of this test the image reference is hardcoded and this is one of the use case. For example you may have some prerequisite components to install inside the cluster like CNI, before deploy your staff. The example here is the simplest possible.
For moving the manifests see my answer above, for image reference not sure if you have any kuberentes-sigs registry.
/retest |
@vladimirvivien @harshanarayana Please take a look in spare time. I think I answered to all your comments. I would like to continue with Flux and add Helm support, which gives a lot of more flexibility and add possibility to write more complex use cases as examples. |
@matrus2 Sorry, this one totally went missing from my radar. Thanks for taking care of this and working towards adding this awesome feature into the framework. With regards to the sample app part of the questions, I think we might be able to do it in two phases like you were suggesting above.
This way, we can keep all the test data co-located and can easily make changes to new things. I wish there was a way to setup flux to use a local file system path as a repo instead of an actual URL. That would have simplified a whole lot of this work! I would prefer to hear from @vladimirvivien @cpanato @ShwethaKumbla on what their view on this is before we can make any further decision. I will go over the rest of the changes and if I find something needing a change, I will leave a comment. Give me until Weekend to sort a few things out. |
@harshanarayana Thanks for taking time and review this one. Template migrated in #283, reference updated. |
@matrus2 This will be great. Always a good thing when this framework can be integrated with other projects. @harshanarayana thanks for looking at this so thoroughly🎉 |
/retest |
@vladimirvivien Thanks for taking a look at this. The test won't pass untill #283 is merged as files reference template directory. |
/retest |
* Include create and delete GitRepository * Include create and delete Kustmozation * Provide basic example
third_party/flux/cmd_manager.go
Outdated
} | ||
|
||
func (m *Manager) run(opts *Opts) (err error) { | ||
if m.e.Prog().Avail("flux") == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @matrus2 Now that we have the template merged, this is more or less ready to be merged as well.
Recently we enabled a way to use a custom path for these binaries that we use in the framework. i.e You can specify a path outside of the $PATH
that you have your binaries in. Can we have a mechanism similar to that here? We have the same behavior on kind/and helm already. A way to customize teh path using WithPath
kind of helper would be great to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now fixed.
@vladimirvivien Would you mind taking a look at this and see if you have any more pending request that needs to be addressed on this ? |
Hi @vladimirvivien, any chance to wrap this up? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @matrus2, apologies for the delay, I was on vacation.
Thanks for hanging in there and doing this valuable contribution.
Thanks @harshanarayana for the thorough reviews!!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: matrus2, vladimirvivien The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hello,
This a proposal and MVP for integration e2e framework with Flux. This one include:
Please comment & review. Once first part is done we can focus to provide all other functionalities from Flux e.g. Helm repository reconciliation support.