-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
949e6f2
commit cf5aab6
Showing
11 changed files
with
520 additions
and
112 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ cover.out | |
.vscode | ||
.idea | ||
.DS_Store | ||
e2e/logs |
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,27 @@ | ||
//go:build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/crossplane-contrib/xp-testing/pkg/resources" | ||
"sigs.k8s.io/e2e-framework/pkg/features" | ||
|
||
"github.com/swisscom/provider-cortex/apis/alerts/v1alpha1" | ||
) | ||
|
||
func Test_AlertManagerConfiguration_v1alpha1(t *testing.T) { | ||
|
||
resource := resources.NewResourceTestConfig(&v1alpha1.AlertManagerConfiguration{}, "AlertManagerConfiguration") | ||
|
||
fB := features.New(fmt.Sprintf("%v", resource.Kind)) | ||
fB.WithLabel("kind", resource.Kind) | ||
fB.Setup(resource.Setup) | ||
fB.Assess("create", resource.AssessCreate) | ||
fB.Assess("delete", resource.AssessDelete) | ||
|
||
testenv.Test(t, fB.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,24 @@ | ||
apiVersion: alerts.cortex.crossplane.io/v1alpha1 | ||
kind: AlertManagerConfiguration | ||
metadata: | ||
name: example-configuration | ||
spec: | ||
forProvider: | ||
template_files: | ||
default_template: | | ||
{{ define "__alertmanager" }}AlertManager{{ end }} | ||
{{ define "__alertmanagerURL" }}{{ .ExternalURL }}/#/alerts?receiver={{ .Receiver | urlquery }}{{ end }} | ||
alertmanager_config: | | ||
global: | ||
smtp_smarthost: 'localhost:25' | ||
smtp_from: 'youraddress@example.org' | ||
templates: | ||
- 'default_template' | ||
route: | ||
receiver: example-email | ||
receivers: | ||
- name: example-email | ||
email_configs: | ||
- to: 'youraddress@example.org' | ||
providerConfigRef: | ||
name: provider-cortex |
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,20 @@ | ||
apiVersion: rules.cortex.crossplane.io/v1alpha1 | ||
kind: RuleGroup | ||
metadata: | ||
name: example-rulegroup | ||
spec: | ||
forProvider: | ||
namespace: example-namespace | ||
interval: 10m | ||
rules: | ||
- record: instance_path:request_failures:rate5m | ||
expr: rate(request_failures_total{job="myjob"}[5m]) | ||
- alert: HighCPUUtilization | ||
expr: avg(node_cpu{mode="system"}) > 80 | ||
for: 5m | ||
annotations: | ||
annotation_name: test | ||
labels: | ||
label_name: test | ||
providerConfigRef: | ||
name: provider-cortex |
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,48 @@ | ||
//go:build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
runtime "k8s.io/apimachinery/pkg/runtime" | ||
|
||
xpv1alpha1 "github.com/crossplane/crossplane/apis/pkg/v1alpha1" | ||
"github.com/swisscom/provider-cortex/apis" | ||
"sigs.k8s.io/e2e-framework/pkg/env" | ||
|
||
"github.com/crossplane-contrib/xp-testing/pkg/images" | ||
"github.com/crossplane-contrib/xp-testing/pkg/logging" | ||
"github.com/crossplane-contrib/xp-testing/pkg/setup" | ||
) | ||
|
||
var testenv env.Environment | ||
|
||
func TestMain(m *testing.M) { | ||
var verbosity = 4 | ||
logging.EnableVerboseLogging(&verbosity) | ||
testenv = env.NewParallel() | ||
|
||
key := "crossplane/provider-cortex" | ||
imgs := images.GetImagesFromEnvironmentOrPanic(key, &key) | ||
clusterSetup := setup.ClusterSetup{ | ||
Name: "cortex", | ||
Images: imgs, | ||
ControllerConfig: &xpv1alpha1.ControllerConfig{ | ||
Spec: xpv1alpha1.ControllerConfigSpec{ | ||
Image: &imgs.Package, | ||
// Raise sync interval to speed up tests | ||
// add debug output, in case necessary for debugging in e.g. CI | ||
Args: []string{"--debug", "--sync=5s"}, | ||
}, | ||
}, | ||
SecretData: nil, | ||
AddToSchemaFuncs: []func(s *runtime.Scheme) error{apis.AddToScheme}, | ||
CrossplaneVersion: "1.13.2", | ||
} | ||
|
||
clusterSetup.Configure(testenv) | ||
testenv.Setup(installCortex("v1.15.2")) | ||
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,7 @@ | ||
apiVersion: cortex.crossplane.io/v1alpha1 | ||
kind: ProviderConfig | ||
metadata: | ||
name: provider-cortex | ||
spec: | ||
tenantId: example-tenant | ||
address: http://cortex.default.svc:9009 |
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,27 @@ | ||
//go:build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/crossplane-contrib/xp-testing/pkg/resources" | ||
"sigs.k8s.io/e2e-framework/pkg/features" | ||
|
||
"github.com/swisscom/provider-cortex/apis/rules/v1alpha1" | ||
) | ||
|
||
func Test_RuleGroup_v1alpha1(t *testing.T) { | ||
|
||
resource := resources.NewResourceTestConfig(&v1alpha1.RuleGroup{}, "RuleGroup") | ||
|
||
fB := features.New(fmt.Sprintf("%v", resource.Kind)) | ||
fB.WithLabel("kind", resource.Kind) | ||
fB.Setup(resource.Setup) | ||
fB.Assess("create", resource.AssessCreate) | ||
fB.Assess("delete", resource.AssessDelete) | ||
|
||
testenv.Test(t, fB.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,117 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"log" | ||
"net/http" | ||
"strings" | ||
"time" | ||
|
||
"github.com/crossplane-contrib/xp-testing/pkg/xpenvfuncs" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/klog/v2" | ||
"sigs.k8s.io/e2e-framework/klient/decoder" | ||
"sigs.k8s.io/e2e-framework/klient/k8s/resources" | ||
"sigs.k8s.io/e2e-framework/klient/wait" | ||
"sigs.k8s.io/e2e-framework/klient/wait/conditions" | ||
"sigs.k8s.io/e2e-framework/pkg/env" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
"sigs.k8s.io/e2e-framework/pkg/envfuncs" | ||
) | ||
|
||
const ( | ||
cortexNamespace = "default" | ||
bucketCreatorPodLabel = "app=minio-bucket-creator" | ||
) | ||
|
||
func installCortex(cortexVersion string) env.Func { | ||
return xpenvfuncs.Compose( | ||
xpenvfuncs.IgnoreMatchedErr(envfuncs.CreateNamespace(cortexNamespace), errors.IsAlreadyExists), | ||
installCortexManifests(cortexVersion), | ||
waitForCortexToBeAvailable(cortexNamespace, bucketCreatorPodLabel), | ||
) | ||
} | ||
|
||
func waitForCortexToBeAvailable(namespace, cortexPodLabel string) env.Func { | ||
return func(ctx context.Context, config *envconf.Config) (context.Context, error) { | ||
res := config.Client().Resources() | ||
res = res.WithNamespace(namespace) | ||
|
||
c := conditions.New(res) | ||
var pods v1.PodList | ||
|
||
err := res.List(ctx, &pods, resources.WithLabelSelector(bucketCreatorPodLabel)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
klog.V(4).Info("Waiting for Cortex to become available") | ||
for i := range pods.Items { | ||
err := wait.For( | ||
c.PodPhaseMatch(&pods.Items[i], v1.PodSucceeded), | ||
wait.WithTimeout(8*time.Minute), wait.WithImmediate()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
} | ||
klog.V(4).Info("Cortex has become available") | ||
return ctx, nil | ||
} | ||
} | ||
|
||
func installCortexManifests(cortexVersion string) env.Func { | ||
return func(ctx context.Context, config *envconf.Config) (context.Context, error) { | ||
manifest, err := downloadManifest() | ||
if err != nil { | ||
return ctx, err | ||
} | ||
r, err := resources.New(config.Client().RESTConfig()) | ||
if err != nil { | ||
return ctx, err | ||
} | ||
err = decoder.DecodeEach( | ||
ctx, | ||
strings.NewReader(manifest), | ||
decoder.IgnoreErrorHandler(decoder.CreateHandler(r), errors.IsAlreadyExists), | ||
decoder.MutateNamespace(cortexNamespace), | ||
) | ||
|
||
if err != nil { | ||
return ctx, err | ||
} | ||
return ctx, nil | ||
} | ||
} | ||
|
||
func downloadManifest() (string, error) { | ||
url := "https://raw.githubusercontent.com/janwillies/cortex-cue/main/generated.yaml" | ||
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, url, nil) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
client := http.DefaultClient | ||
res, err := client.Do(req) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
defer func() { | ||
err := res.Body.Close() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
d, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
if res.StatusCode != http.StatusOK { | ||
return "", err | ||
} | ||
manifests := string(d) | ||
return manifests, nil | ||
} |
Oops, something went wrong.