generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from matrus2/flux
Add Flux support to install resources from git source:
- Loading branch information
Showing
8 changed files
with
505 additions
and
1 deletion.
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.