2022-08-08 09:50:37 -04:00
|
|
|
//go:build integration
|
2022-06-27 04:58:09 -04:00
|
|
|
|
2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-06-27 04:58:09 -04:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2022-06-29 08:47:03 -04:00
|
|
|
"context"
|
2022-06-27 04:58:09 -04:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2022-06-30 07:12:05 -04:00
|
|
|
"time"
|
2022-06-27 04:58:09 -04:00
|
|
|
|
2022-06-29 08:47:03 -04:00
|
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
|
|
|
2022-07-01 10:42:08 -04:00
|
|
|
nodemaintenancev1beta1 "github.com/medik8s/node-maintenance-operator/api/v1beta1"
|
2022-06-27 04:58:09 -04:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
|
|
"k8s.io/client-go/rest"
|
2022-06-30 07:12:05 -04:00
|
|
|
testclock "k8s.io/utils/clock/testing"
|
2022-06-27 04:58:09 -04:00
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
|
|
|
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
|
|
|
|
2022-09-21 07:47:57 -04:00
|
|
|
updatev1alpha1 "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/api/v1alpha1"
|
2022-06-27 04:58:09 -04:00
|
|
|
//+kubebuilder:scaffold:imports
|
|
|
|
)
|
|
|
|
|
|
|
|
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
|
|
|
|
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
|
|
|
|
2022-06-27 06:05:42 -04:00
|
|
|
var (
|
|
|
|
cfg *rest.Config
|
|
|
|
k8sClient client.Client
|
|
|
|
testEnv *envtest.Environment
|
2022-06-29 08:47:03 -04:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
2022-06-29 10:47:13 -04:00
|
|
|
fakes = newFakes()
|
2022-06-27 06:05:42 -04:00
|
|
|
)
|
2022-06-27 04:58:09 -04:00
|
|
|
|
|
|
|
func TestAPIs(t *testing.T) {
|
|
|
|
RegisterFailHandler(Fail)
|
|
|
|
|
|
|
|
RunSpecsWithDefaultAndCustomReporters(t,
|
|
|
|
"Controller Suite",
|
|
|
|
[]Reporter{printer.NewlineReporter{}})
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ = BeforeSuite(func() {
|
|
|
|
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
|
2022-06-29 08:47:03 -04:00
|
|
|
ctx, cancel = context.WithCancel(context.Background())
|
2022-06-27 04:58:09 -04:00
|
|
|
|
|
|
|
By("bootstrapping test environment")
|
|
|
|
testEnv = &envtest.Environment{
|
2022-07-01 10:42:08 -04:00
|
|
|
CRDDirectoryPaths: []string{
|
|
|
|
filepath.Join("..", "config", "crd", "bases"),
|
|
|
|
filepath.Join("..", "external", "github.com", "medik8s", "node-maintenance-operator", "config", "crd", "bases"),
|
|
|
|
},
|
2022-06-27 04:58:09 -04:00
|
|
|
ErrorIfCRDPathMissing: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
// cfg is defined in this file globally.
|
|
|
|
cfg, err = testEnv.Start()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(cfg).NotTo(BeNil())
|
|
|
|
|
|
|
|
err = updatev1alpha1.AddToScheme(scheme.Scheme)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2022-07-01 10:42:08 -04:00
|
|
|
err = nodemaintenancev1beta1.AddToScheme(scheme.Scheme)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2022-06-27 04:58:09 -04:00
|
|
|
|
|
|
|
//+kubebuilder:scaffold:scheme
|
|
|
|
|
|
|
|
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(k8sClient).NotTo(BeNil())
|
2022-06-29 08:47:03 -04:00
|
|
|
|
|
|
|
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
|
|
|
|
Scheme: scheme.Scheme,
|
|
|
|
})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2022-06-29 08:47:34 -04:00
|
|
|
err = (&AutoscalingStrategyReconciler{
|
|
|
|
Client: k8sManager.GetClient(),
|
|
|
|
Scheme: k8sManager.GetScheme(),
|
|
|
|
}).SetupWithManager(k8sManager)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2022-06-29 10:47:13 -04:00
|
|
|
err = (&ScalingGroupReconciler{
|
|
|
|
scalingGroupUpdater: fakes.scalingGroupUpdater,
|
|
|
|
Client: k8sManager.GetClient(),
|
|
|
|
Scheme: k8sManager.GetScheme(),
|
|
|
|
}).SetupWithManager(k8sManager)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2022-06-30 07:12:05 -04:00
|
|
|
err = (&PendingNodeReconciler{
|
|
|
|
nodeStateGetter: fakes.nodeStateGetter,
|
|
|
|
Client: k8sManager.GetClient(),
|
|
|
|
Scheme: k8sManager.GetScheme(),
|
|
|
|
Clock: fakes.clock,
|
|
|
|
}).SetupWithManager(k8sManager)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2022-07-01 10:44:38 -04:00
|
|
|
err = (&NodeImageReconciler{
|
|
|
|
nodeReplacer: fakes.nodeReplacer,
|
|
|
|
Client: k8sManager.GetClient(),
|
|
|
|
Scheme: k8sManager.GetScheme(),
|
|
|
|
}).SetupWithManager(k8sManager)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2022-06-29 08:47:03 -04:00
|
|
|
go func() {
|
|
|
|
defer GinkgoRecover()
|
|
|
|
err = k8sManager.Start(ctx)
|
|
|
|
Expect(err).ToNot(HaveOccurred(), "failed to run manager")
|
|
|
|
}()
|
2022-06-27 04:58:09 -04:00
|
|
|
}, 60)
|
|
|
|
|
|
|
|
var _ = AfterSuite(func() {
|
2022-06-29 08:47:03 -04:00
|
|
|
cancel()
|
2022-06-27 04:58:09 -04:00
|
|
|
By("tearing down the test environment")
|
|
|
|
err := testEnv.Stop()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|
2022-06-29 10:47:13 -04:00
|
|
|
|
|
|
|
type fakeCollection struct {
|
|
|
|
scalingGroupUpdater *fakeScalingGroupUpdater
|
2022-06-30 07:12:05 -04:00
|
|
|
nodeStateGetter *stubNodeStateGetter
|
2022-07-01 10:44:38 -04:00
|
|
|
nodeReplacer *stubNodeReplacer
|
2022-06-30 07:12:05 -04:00
|
|
|
clock *testclock.FakeClock
|
2022-06-29 10:47:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func newFakes() fakeCollection {
|
|
|
|
return fakeCollection{
|
|
|
|
scalingGroupUpdater: newFakeScalingGroupUpdater(),
|
2022-06-30 07:12:05 -04:00
|
|
|
nodeStateGetter: &stubNodeStateGetter{},
|
2022-07-01 10:44:38 -04:00
|
|
|
nodeReplacer: &stubNodeReplacer{},
|
2022-06-30 07:12:05 -04:00
|
|
|
clock: testclock.NewFakeClock(time.Now()),
|
2022-06-29 10:47:13 -04:00
|
|
|
}
|
|
|
|
}
|