Skip to content
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

[release-ocm-2.9] MGMT-14838: Use CAPI Agent new v1beta1 APIs #87

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Build the manager binary
FROM golang:1.17 as builder
FROM registry.ci.openshift.org/openshift/release:golang-1.20 as builder

WORKDIR /workspace
COPY . .
# Build
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

FROM registry.ci.openshift.org/ocp/4.10:base
FROM registry.ci.openshift.org/ocp/4.14:base
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mockgen: ## Download mockgen locally if necessary.

GOLINT = $(shell pwd)/bin/golangci-lint
golint: ## Download golangci-lint locally if necessary.
$(call go-get-tool,$(GOLINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2)
$(call go-get-tool,$(GOLINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down
18 changes: 9 additions & 9 deletions controllers/agentcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/go-openapi/swag"
hiveext "github.com/openshift/assisted-service/api/hiveextension/v1beta1"
capiproviderv1alpha1 "github.com/openshift/cluster-api-provider-agent/api/v1alpha1"
capiproviderv1 "github.com/openshift/cluster-api-provider-agent/api/v1beta1"
hivev1 "github.com/openshift/hive/apis/hive/v1"
"github.com/openshift/hive/apis/hive/v1/agent"
"github.com/pkg/errors"
Expand Down Expand Up @@ -78,7 +78,7 @@ func (r *AgentClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
}()
log.Info("AgentCluster Reconcile start")

agentCluster := &capiproviderv1alpha1.AgentCluster{}
agentCluster := &capiproviderv1.AgentCluster{}
if err := r.Get(ctx, req.NamespacedName, agentCluster); err != nil {
log.WithError(err).Errorf("Failed to get agentCluster %s", req.NamespacedName)
return ctrl.Result{}, client.IgnoreNotFound(err)
Expand Down Expand Up @@ -124,7 +124,7 @@ func getNestedStringObject(log logrus.FieldLogger, obj *unstructured.Unstructure
}

func (r *AgentClusterReconciler) getControlPlane(ctx context.Context, log logrus.FieldLogger,
agentCluster *capiproviderv1alpha1.AgentCluster) (*ControlPlane, error) {
agentCluster *capiproviderv1.AgentCluster) (*ControlPlane, error) {

log.Info("Getting control plane")
// Fetch the CAPI Cluster.
Expand Down Expand Up @@ -175,7 +175,7 @@ func (r *AgentClusterReconciler) getControlPlane(ctx context.Context, log logrus
return &controlPlane, nil
}

func (r *AgentClusterReconciler) createClusterDeploymentObject(agentCluster *capiproviderv1alpha1.AgentCluster,
func (r *AgentClusterReconciler) createClusterDeploymentObject(agentCluster *capiproviderv1.AgentCluster,
controlPlane *ControlPlane) *hivev1.ClusterDeployment {
var kubeadminPassword *corev1.LocalObjectReference
if controlPlane.KubeadminPassword != "" {
Expand Down Expand Up @@ -222,7 +222,7 @@ func (r *AgentClusterReconciler) createClusterDeploymentObject(agentCluster *cap
return clusterDeployment
}

func (r *AgentClusterReconciler) createClusterDeployment(ctx context.Context, log logrus.FieldLogger, agentCluster *capiproviderv1alpha1.AgentCluster) (ctrl.Result, error) {
func (r *AgentClusterReconciler) createClusterDeployment(ctx context.Context, log logrus.FieldLogger, agentCluster *capiproviderv1.AgentCluster) (ctrl.Result, error) {
controlPlane, err := r.getControlPlane(ctx, log, agentCluster)
if err != nil || controlPlane == nil {
return ctrl.Result{RequeueAfter: agentClusterDependenciesWaitTime}, err
Expand Down Expand Up @@ -250,7 +250,7 @@ func (r *AgentClusterReconciler) createClusterDeployment(ctx context.Context, lo
return ctrl.Result{}, nil
}

func (r *AgentClusterReconciler) ensureAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, clusterDeployment *hivev1.ClusterDeployment, agentCluster *capiproviderv1alpha1.AgentCluster) error {
func (r *AgentClusterReconciler) ensureAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, clusterDeployment *hivev1.ClusterDeployment, agentCluster *capiproviderv1.AgentCluster) error {
log.Info("Setting AgentClusterInstall")
agentClusterInstall := &hiveext.AgentClusterInstall{}
if err := r.Get(ctx, types.NamespacedName{Namespace: clusterDeployment.Namespace, Name: clusterDeployment.Name}, agentClusterInstall); err != nil {
Expand All @@ -269,7 +269,7 @@ func (r *AgentClusterReconciler) ensureAgentClusterInstall(ctx context.Context,
return nil
}

func (r *AgentClusterReconciler) createAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, clusterDeployment *hivev1.ClusterDeployment, agentCluster *capiproviderv1alpha1.AgentCluster) error {
func (r *AgentClusterReconciler) createAgentClusterInstall(ctx context.Context, log logrus.FieldLogger, clusterDeployment *hivev1.ClusterDeployment, agentCluster *capiproviderv1.AgentCluster) error {
log.Infof("Creating AgentClusterInstall for clusterDeployment: %s %s", clusterDeployment.Namespace, clusterDeployment.Name)
agentClusterInstall := &hiveext.AgentClusterInstall{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -305,7 +305,7 @@ func (r *AgentClusterReconciler) createAgentClusterInstall(ctx context.Context,
return r.Client.Create(ctx, agentClusterInstall)
}

func (r *AgentClusterReconciler) updateClusterStatus(ctx context.Context, log logrus.FieldLogger, agentCluster *capiproviderv1alpha1.AgentCluster) (ctrl.Result, error) {
func (r *AgentClusterReconciler) updateClusterStatus(ctx context.Context, log logrus.FieldLogger, agentCluster *capiproviderv1.AgentCluster) (ctrl.Result, error) {
log.Infof("Updating agentCluster status according to %s", agentCluster.Status.ClusterDeploymentRef.Name)
// Once the cluster have clusterDeploymentRef and ClusterInstallRef we should set the status to Ready
agentCluster.Status.Ready = true
Expand All @@ -320,7 +320,7 @@ func (r *AgentClusterReconciler) updateClusterStatus(ctx context.Context, log lo
// SetupWithManager sets up the controller with the Manager.
func (r *AgentClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&capiproviderv1alpha1.AgentCluster{}).
For(&capiproviderv1.AgentCluster{}).
Complete(r)
}

Expand Down
41 changes: 21 additions & 20 deletions controllers/agentcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
hiveext "github.com/openshift/assisted-service/api/hiveextension/v1beta1"
capiproviderv1alpha1 "github.com/openshift/cluster-api-provider-agent/api/v1alpha1"
capiproviderv1 "github.com/openshift/cluster-api-provider-agent/api/v1beta1"
hivev1 "github.com/openshift/hive/apis/hive/v1"
"github.com/openshift/hive/apis/hive/v1/agent"
"github.com/sirupsen/logrus"
Expand All @@ -26,20 +26,20 @@ import (
func init() {
_ = hivev1.AddToScheme(scheme.Scheme)
_ = hiveext.AddToScheme(scheme.Scheme)
_ = capiproviderv1alpha1.AddToScheme(scheme.Scheme)
_ = capiproviderv1.AddToScheme(scheme.Scheme)
_ = clusterv1.AddToScheme(scheme.Scheme)
}

func newAgentClusterRequest(agentCluster *capiproviderv1alpha1.AgentCluster) ctrl.Request {
func newAgentClusterRequest(agentCluster *capiproviderv1.AgentCluster) ctrl.Request {
namespacedName := types.NamespacedName{
Namespace: agentCluster.ObjectMeta.Namespace,
Name: agentCluster.ObjectMeta.Name,
}
return ctrl.Request{NamespacedName: namespacedName}
}

func newAgentCluster(name, namespace string, spec capiproviderv1alpha1.AgentClusterSpec) *capiproviderv1alpha1.AgentCluster {
return &capiproviderv1alpha1.AgentCluster{
func newAgentCluster(name, namespace string, spec capiproviderv1.AgentClusterSpec) *capiproviderv1.AgentCluster {
return &capiproviderv1.AgentCluster{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Expand Down Expand Up @@ -116,11 +116,11 @@ func createControlPlane(namespacedName *types.NamespacedName, baseDomain, pullSe
return obj
}

func createDefaultResources(ctx context.Context, c client.Client, clusterName, testNamespace, baseDomain, pullSecretName, kubeconfig, kubeadminPassword string) *capiproviderv1alpha1.AgentCluster {
func createDefaultResources(ctx context.Context, c client.Client, clusterName, testNamespace, baseDomain, pullSecretName, kubeconfig, kubeadminPassword string) *capiproviderv1.AgentCluster {
namespaced := &types.NamespacedName{Name: clusterName, Namespace: testNamespace}
cluster := newCluster(namespaced)
agentCluster := newAgentCluster(clusterName, testNamespace, capiproviderv1alpha1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1alpha1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
agentCluster := newAgentCluster(clusterName, testNamespace, capiproviderv1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
})

agentCluster.OwnerReferences = []metav1.OwnerReference{{Name: cluster.Name, Kind: cluster.Kind, APIVersion: cluster.APIVersion}}
Expand All @@ -147,7 +147,8 @@ var _ = Describe("agentcluster reconcile", func() {
)

BeforeEach(func() {
c = fakeclient.NewClientBuilder().WithScheme(scheme.Scheme).Build()
agentCluster := &capiproviderv1.AgentCluster{}
c = fakeclient.NewClientBuilder().WithScheme(scheme.Scheme).WithStatusSubresource(agentCluster).Build()
mockCtrl = gomock.NewController(GinkgoT())

acr = &AgentClusterReconciler{
Expand All @@ -162,10 +163,10 @@ var _ = Describe("agentcluster reconcile", func() {
})

It("none existing agentCluster", func() {
agentCluster := newAgentCluster("agentCluster-1", testNamespace, capiproviderv1alpha1.AgentClusterSpec{})
agentCluster := newAgentCluster("agentCluster-1", testNamespace, capiproviderv1.AgentClusterSpec{})
Expect(c.Create(ctx, agentCluster)).To(BeNil())

noneExistingAgentCluster := newAgentCluster("agentCluster-2", testNamespace, capiproviderv1alpha1.AgentClusterSpec{})
noneExistingAgentCluster := newAgentCluster("agentCluster-2", testNamespace, capiproviderv1.AgentClusterSpec{})

result, err := acr.Reconcile(ctx, newAgentClusterRequest(noneExistingAgentCluster))
Expect(err).To(BeNil())
Expand Down Expand Up @@ -219,8 +220,8 @@ var _ = Describe("agentcluster reconcile", func() {

})
It("failed to find cluster", func() {
agentCluster := newAgentCluster("agentCluster-1", testNamespace, capiproviderv1alpha1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1alpha1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
agentCluster := newAgentCluster("agentCluster-1", testNamespace, capiproviderv1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
})
Expect(c.Create(ctx, agentCluster)).To(BeNil())
result, err := acr.Reconcile(ctx, newAgentClusterRequest(agentCluster))
Expand All @@ -233,8 +234,8 @@ var _ = Describe("agentcluster reconcile", func() {
cluster := newCluster(&types.NamespacedName{Name: clusterName, Namespace: testNamespace})
cluster.Spec.ControlPlaneRef = nil

agentCluster := newAgentCluster(clusterName, testNamespace, capiproviderv1alpha1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1alpha1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
agentCluster := newAgentCluster(clusterName, testNamespace, capiproviderv1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
})
agentCluster.OwnerReferences = []metav1.OwnerReference{{Name: cluster.Name, Kind: cluster.Kind, APIVersion: cluster.APIVersion}}

Expand All @@ -247,8 +248,8 @@ var _ = Describe("agentcluster reconcile", func() {
})

It("failed to find clusterDeployment", func() {
agentCluster := newAgentCluster("agentCluster-1", testNamespace, capiproviderv1alpha1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1alpha1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
agentCluster := newAgentCluster("agentCluster-1", testNamespace, capiproviderv1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
})
agentCluster.Status.ClusterDeploymentRef.Name = "missing-cluster-deployment-name"
Expect(c.Create(ctx, agentCluster)).To(BeNil())
Expand Down Expand Up @@ -276,8 +277,8 @@ var _ = Describe("agentcluster reconcile", func() {
Expect(*agentClusterInstall.Spec.Networking.UserManagedNetworking).To(BeTrue())
})
It("agentCluster missing controlPlaneEndpoint", func() {
agentCluster := newAgentCluster("agentCluster-1", testNamespace, capiproviderv1alpha1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1alpha1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
agentCluster := newAgentCluster("agentCluster-1", testNamespace, capiproviderv1.AgentClusterSpec{
IgnitionEndpoint: &capiproviderv1.IgnitionEndpoint{Url: "https://1.2.3.4:555/ignition"},
})

agentCluster.Status.ClusterDeploymentRef.Name = agentCluster.Name
Expand All @@ -293,7 +294,7 @@ var _ = Describe("agentcluster reconcile", func() {
})
})

func createClusterDeployment(c client.Client, ctx context.Context, agentCluster *capiproviderv1alpha1.AgentCluster, clusterName, baseDomain, pullSecretName string) {
func createClusterDeployment(c client.Client, ctx context.Context, agentCluster *capiproviderv1.AgentCluster, clusterName, baseDomain, pullSecretName string) {
clusterDeployment := &hivev1.ClusterDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: agentCluster.Name,
Expand Down
Loading