generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2aebadc
Add Flux support to install resources from git source:
matrus2 31ed661
Restructure flux integration
matrus2 07c8302
Add permissions to flux install
matrus2 9ec6366
Fix typo in install flux script
matrus2 60ea14d
Make installation to work
matrus2 88a9d1c
Add documentation
matrus2 607e2ea
Update reference to e2e-framework
matrus2 2ddff14
Fix lint errors
matrus2 efd73eb
Remove obsolete comment from flux example
matrus2 aab80f0
Add possibility to specify flux path
matrus2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Flux Integration | ||
|
||
This section of the document gives you an example of how to integrate the flux workflow | ||
into the `e2e-framework` while writing your tests. | ||
|
||
## Pre-Requisites | ||
|
||
1. `Flux` Installed on your system where the tests are being run for details visit flux official [website](https://fluxcd.io/). | ||
|
||
## Flux supported commands | ||
|
||
For the time being the framework supports following functionality: | ||
- Flux installation and uninstallation. | ||
- Handling [Kustomization](https://fluxcd.io/flux/components/kustomize/kustomization/) objects. | ||
- Handling [GitRepository](https://fluxcd.io/flux/components/source/gitrepositories/) objects. | ||
|
||
## How does the example work? | ||
|
||
1. It creates a kind cluster with `flux` prefix. | ||
2. Creates a namespace with `flux` prefix. | ||
3. Installs all flux resources. | ||
4. Creates a reference to the git repository, where a simple hello world application deployment is specified. You can find it [here](https://github.com/matrus2/go-hello-world). | ||
5. Starts reconciliation by a flux kustomization manifest to path `template` of the git repository. | ||
6. Assesses if the deployment of simple hello world app is up and running. | ||
7. After the test passes it removes all resources. | ||
|
||
## How to run tests | ||
|
||
```shell | ||
go test -c -o flux.test . && ./flux.test --v 4 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package flux | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/e2e-framework/klient/wait" | ||
"sigs.k8s.io/e2e-framework/klient/wait/conditions" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
"sigs.k8s.io/e2e-framework/pkg/features" | ||
) | ||
|
||
func TestFluxRepoWorkflow(t *testing.T) { | ||
feature := features.New("Install resources by flux"). | ||
Assess("check if deployment was successful", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { | ||
deployment := &appsv1.Deployment{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "hello-app", | ||
Namespace: c.Namespace(), | ||
}, | ||
Spec: appsv1.DeploymentSpec{}, | ||
} | ||
|
||
err := wait.For(conditions.New(c.Client().Resources()).DeploymentConditionMatch(deployment, appsv1.DeploymentAvailable, corev1.ConditionStatus(v1.ConditionTrue)), wait.WithTimeout(time.Minute*5)) | ||
if err != nil { | ||
t.Fatal("Error deployment not found", err) | ||
} | ||
|
||
return ctx | ||
}).Feature() | ||
|
||
testEnv.Test(t, feature) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package flux | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"sigs.k8s.io/e2e-framework/pkg/env" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
"sigs.k8s.io/e2e-framework/pkg/envfuncs" | ||
"sigs.k8s.io/e2e-framework/third_party/flux" | ||
) | ||
|
||
var ( | ||
testEnv env.Environment | ||
namespace string | ||
kindClusterName string | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
cfg, _ := envconf.NewFromFlags() | ||
testEnv = env.NewWithConfig(cfg) | ||
kindClusterName = envconf.RandomName("flux", 10) | ||
namespace = envconf.RandomName("flux", 10) | ||
gitRepoName := "e2e-framework" | ||
ksName := "hello-world" | ||
testEnv.Setup( | ||
envfuncs.CreateKindCluster(kindClusterName), | ||
envfuncs.CreateNamespace(namespace), | ||
flux.InstallFlux(), | ||
flux.CreateGitRepo(gitRepoName, "https://github.com/kubernetes-sigs/e2e-framework", flux.WithBranch("main")), | ||
flux.CreateKustomization(ksName, "GitRepository/"+gitRepoName+".flux-system", flux.WithPath("examples/third_party_integration/flux/template"), flux.WithArgs("--target-namespace", namespace, "--prune")), | ||
) | ||
|
||
testEnv.Finish( | ||
flux.DeleteKustomization(ksName), | ||
flux.DeleteGitRepo(gitRepoName), | ||
flux.UninstallFlux(), | ||
envfuncs.DeleteNamespace(namespace), | ||
envfuncs.DestroyKindCluster(kindClusterName), | ||
) | ||
os.Exit(testEnv.Run(m)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2023 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -e | ||
|
||
FLUX_URL=https://fluxcd.io/install.sh | ||
|
||
if ! command -v flux; then | ||
# Running the piped command with sudo disabled to avoid any security concerns that might arise | ||
curl -s $FLUX_URL | USE_SUDO=false bash | ||
fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.