Skip to content

Commit

Permalink
ACM-13470: upgrade hive in clc repos for MCE 2.7 [Train 18]
Browse files Browse the repository at this point in the history
- Upgraded to latest hive api from mce-2.7 branch
- Upgraded to go 1.22
- Changed code due to changes in the behaviour of runtime-controller library
- remove unncessary dependencies from go.mod

See related issues on changes for runtime-controller that needed to be addressed:
- kubernetes-sigs/controller-runtime#2788
- kubernetes-sigs/controller-runtime#1517
  • Loading branch information
dtthuynh committed Sep 5, 2024
1 parent 145f190 commit a1db71d
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 119 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.prow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.ci.openshift.org/stolostron/builder:go1.21-linux AS builder
FROM registry.ci.openshift.org/stolostron/builder:go1.22-linux AS builder

WORKDIR /go/src/github.com/stolostron/clusterclaims-controller
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.rhtap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.20 AS builder
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.22 AS builder

WORKDIR /go/src/github.com/stolostron/clusterclaims-controller
COPY . .
Expand Down
8 changes: 5 additions & 3 deletions cmd/clusterclaims/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
mcv1 "open-cluster-management.io/api/cluster/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
)
Expand All @@ -39,7 +40,7 @@ func main() {
var leaderElectionLeaseDuration time.Duration
var leaderElectionRenewDeadline time.Duration
var leaderElectionRetryPeriod time.Duration
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&metricsAddr, "metrics-addr", ":9443", "The address the metric endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand Down Expand Up @@ -80,8 +81,9 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
//MetricsBindAddress: metricsAddr,
Port: 9443,
Metrics: server.Options{
BindAddress: metricsAddr,
},
LeaderElection: enableLeaderElection,
LeaderElectionID: "clusterclaims-controller.open-cluster-management.io",
LeaseDuration: &leaderElectionLeaseDuration,
Expand Down
5 changes: 4 additions & 1 deletion cmd/clusterpools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
mcv1 "open-cluster-management.io/api/cluster/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
)
Expand Down Expand Up @@ -91,7 +92,9 @@ func main() {
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Metrics: server.Options{
BindAddress: metricsAddr,
},
LeaderElection: enableLeaderElection,
LeaderElectionID: "clusterpools-controller.open-cluster-management.io",
LeaseDuration: &leaderElectionLeaseDuration,
Expand Down
3 changes: 1 addition & 2 deletions controllers/clusterclaims/clusterclaims-controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ func GetClusterClaimsReconciler() *ClusterClaimsReconciler {

// Log levels: DebugLevel DebugLevel
ctrl.SetLogger(zap.New(zap.UseDevMode(true), zap.Level(zapcore.DebugLevel)))

return &ClusterClaimsReconciler{
Client: clientfake.NewFakeClientWithScheme(s),
Client: clientfake.NewClientBuilder().WithScheme(s).Build(),
Log: ctrl.Log.WithName("controllers").WithName("ClusterClaimsReconciler"),
Scheme: s,
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/clusterpools/clusterpools-controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func GetClusterPoolsReconciler() *ClusterPoolsReconciler {

return &ClusterPoolsReconciler{
KubeClient: kubefake.NewSimpleClientset(),
Client: clientfake.NewFakeClientWithScheme(s),
Client: clientfake.NewClientBuilder().WithScheme(s).Build(),
Log: ctrl.Log.WithName("controllers").WithName("ClusterPoolsReconciler"),
Scheme: s,
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/managedcluster/managedcluster-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func (r *ManagedClusterReconciler) Reconcile(ctx context.Context, request ctrl.R
return ctrl.Result{}, err
}

// annotation format is <name>.<namespace>.<kind>.<apiversion>
expectedProvisioner := fmt.Sprintf("%s.%s.%s.%s", claimName, claimNamespace, clusterClaim.Kind, clusterClaim.APIVersion)
// annotation format is <name>.<namespace>
expectedProvisioner := fmt.Sprintf("%s.%s", claimName, claimNamespace)

patch := client.MergeFrom(cluster.DeepCopy())

Expand Down
18 changes: 12 additions & 6 deletions controllers/managedcluster/managedcluster-controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ func TestReconcile(t *testing.T) {
ctx := context.Background()

c := &ManagedClusterReconciler{
Client: clientfake.NewFakeClientWithScheme(testScheme),
Client: clientfake.NewClientBuilder().WithScheme(testScheme).Build(),
Log: ctrl.Log.WithName("controllers").WithName("ManagedClusterReconciler"),
Scheme: testScheme,
}

if err := c.Client.Create(ctx, &hivev1.ClusterClaim{
// TypeMeta: metav1.TypeMeta{
// Kind: "ClusterClaim",
// APIVersion: hivev1.SchemeGroupVersion.String(),
// },
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "testns"},
Spec: hivev1.ClusterClaimSpec{},
}, &client.CreateOptions{}); err != nil {
Expand Down Expand Up @@ -68,8 +72,10 @@ func TestReconcile(t *testing.T) {
t.Fatal(err)
}

if cluster.Annotations["cluster.open-cluster-management.io/provisioner"] != "test.testns.ClusterClaim.hive.openshift.io/v1" {
t.Errorf("unexpected annotation %v", cluster.Annotations["provisioner"])
// the crd.king and api version is not appearing in the annotation
expectedAnnotation := "test.testns"
if cluster.Annotations["cluster.open-cluster-management.io/provisioner"] != expectedAnnotation {
t.Errorf("unexpected annotation, expected: %v, got: %v", expectedAnnotation, cluster.Annotations["cluster.open-cluster-management.io/provisioner"])
}
c.SetupWithManager(nil)
}
Expand All @@ -78,7 +84,7 @@ func TestReconcileClusterDeleteing(t *testing.T) {
ctx := context.Background()

c := &ManagedClusterReconciler{
Client: clientfake.NewFakeClientWithScheme(testScheme),
Client: clientfake.NewClientBuilder().WithScheme(testScheme).Build(),
Log: ctrl.Log.WithName("controllers").WithName("ManagedClusterReconciler"),
Scheme: testScheme,
}
Expand Down Expand Up @@ -114,7 +120,7 @@ func TestReconcileCDDeleteing(t *testing.T) {
ctx := context.Background()

c := &ManagedClusterReconciler{
Client: clientfake.NewFakeClientWithScheme(testScheme),
Client: clientfake.NewClientBuilder().WithScheme(testScheme).Build(),
Log: ctrl.Log.WithName("controllers").WithName("ManagedClusterReconciler"),
Scheme: testScheme,
}
Expand Down Expand Up @@ -155,7 +161,7 @@ func TestReconcileCLDeleteing(t *testing.T) {
ctx := context.Background()

c := &ManagedClusterReconciler{
Client: clientfake.NewFakeClientWithScheme(testScheme),
Client: clientfake.NewClientBuilder().WithScheme(testScheme).Build(),
Log: ctrl.Log.WithName("controllers").WithName("ManagedClusterReconciler"),
Scheme: testScheme,
}
Expand Down
52 changes: 25 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,69 @@ require (
github.com/go-logr/logr v1.4.2
github.com/openshift/hive/apis v0.0.0-20240821011206-1ec27ad45d5a
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.24.0
go.uber.org/zap v1.26.0
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
open-cluster-management.io/api v0.11.0
sigs.k8s.io/controller-runtime v0.15.1
sigs.k8s.io/controller-runtime v0.19.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openshift/api v3.9.1-0.20191111211345-a27ff30ebf09+incompatible // indirect
github.com/openshift/custom-resource-status v1.1.3-0.20220503160415-f2fdb4999d87 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/client_golang v1.20.2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.58.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
golang.org/x/time v0.6.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/component-base v0.27.2 // indirect
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240821151609-f90d01438635 // indirect
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 // indirect
k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down
Loading

0 comments on commit a1db71d

Please sign in to comment.