Skip to content

Commit a0ebc56

Browse files
committed
wip
1 parent 6452a14 commit a0ebc56

36 files changed

+4158
-234
lines changed

cmd/machine-api-migration/main.go

+22
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
configv1client "github.com/openshift/client-go/config/clientset/versioned"
2727
configinformers "github.com/openshift/client-go/config/informers/externalversions"
2828
"github.com/openshift/cluster-capi-operator/pkg/controllers"
29+
"github.com/openshift/cluster-capi-operator/pkg/controllers/machinemigration"
30+
"github.com/openshift/cluster-capi-operator/pkg/controllers/machinesetmigration"
2931
"github.com/openshift/cluster-capi-operator/pkg/controllers/machinesetsync"
3032
"github.com/openshift/cluster-capi-operator/pkg/controllers/machinesync"
3133
"github.com/openshift/cluster-capi-operator/pkg/util"
@@ -243,6 +245,26 @@ func main() {
243245
os.Exit(1)
244246
}
245247

248+
machineMigrationReconciler := machinemigration.MachineMigrationReconciler{
249+
MAPINamespace: *mapiManagedNamespace,
250+
CAPINamespace: *capiManagedNamespace,
251+
}
252+
253+
if err := machineMigrationReconciler.SetupWithManager(mgr); err != nil {
254+
klog.Error(err, "failed to set up machine migration reconciler with manager")
255+
os.Exit(1)
256+
}
257+
258+
machineSetMigrationReconciler := machinesetmigration.MachineSetMigrationReconciler{
259+
MAPINamespace: *mapiManagedNamespace,
260+
CAPINamespace: *capiManagedNamespace,
261+
}
262+
263+
if err := machineSetMigrationReconciler.SetupWithManager(mgr); err != nil {
264+
klog.Error(err, "failed to set up machineset migration reconciler with manager")
265+
os.Exit(1)
266+
}
267+
246268
klog.Info("Starting manager")
247269

248270
if err := mgr.Start(stop); err != nil {

pkg/controllers/machinemigration/machine_migration_controller.go

+492
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright 2025 Red Hat, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package machinemigration
18+
19+
import (
20+
"context"
21+
"testing"
22+
"time"
23+
24+
. "github.com/onsi/ginkgo/v2"
25+
. "github.com/onsi/gomega"
26+
27+
configv1builder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/config/v1"
28+
"github.com/openshift/cluster-capi-operator/pkg/test"
29+
30+
"k8s.io/apimachinery/pkg/api/meta"
31+
"k8s.io/apimachinery/pkg/runtime"
32+
"k8s.io/client-go/rest"
33+
"k8s.io/klog/v2"
34+
"k8s.io/klog/v2/textlogger"
35+
36+
"sigs.k8s.io/controller-runtime/pkg/client"
37+
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
38+
"sigs.k8s.io/controller-runtime/pkg/envtest"
39+
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
40+
logf "sigs.k8s.io/controller-runtime/pkg/log"
41+
//+kubebuilder:scaffold:imports
42+
)
43+
44+
const (
45+
timeout = time.Second * 2
46+
)
47+
48+
var cfg *rest.Config
49+
var k8sClient client.Client
50+
var testEnv *envtest.Environment
51+
var testScheme *runtime.Scheme
52+
var testRESTMapper meta.RESTMapper
53+
var ctx = context.Background()
54+
55+
func TestAPIs(t *testing.T) {
56+
RegisterFailHandler(Fail)
57+
58+
RunSpecs(t, "Controller Suite")
59+
}
60+
61+
var _ = BeforeSuite(func() {
62+
klog.SetOutput(GinkgoWriter)
63+
64+
logf.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
65+
66+
By("bootstrapping test environment")
67+
var err error
68+
testEnv = &envtest.Environment{}
69+
cfg, k8sClient, err = test.StartEnvTest(testEnv)
70+
71+
Expect(err).NotTo(HaveOccurred())
72+
Expect(cfg).NotTo(BeNil())
73+
Expect(k8sClient).NotTo(BeNil())
74+
75+
infrastructure := configv1builder.Infrastructure().AsAWS("test", "eu-west-2").WithName("cluster").Build()
76+
Expect(k8sClient.Create(ctx, infrastructure)).To(Succeed())
77+
78+
httpClient, err := rest.HTTPClientFor(cfg)
79+
Expect(err).NotTo(HaveOccurred())
80+
Expect(httpClient).NotTo(BeNil())
81+
82+
testRESTMapper, err = apiutil.NewDynamicRESTMapper(cfg, httpClient)
83+
Expect(err).NotTo(HaveOccurred())
84+
85+
komega.SetClient(k8sClient)
86+
komega.SetContext(ctx)
87+
})
88+
89+
var _ = AfterSuite(func() {
90+
By("tearing down the test environment")
91+
err := testEnv.Stop()
92+
Expect(err).NotTo(HaveOccurred())
93+
})

0 commit comments

Comments
 (0)