Skip to content

Commit a86a739

Browse files
authored
Merge pull request #11968 from sbueringer/pr-crs-follow-up
🌱 Cleanup after CRS move
2 parents 01bc3b5 + c7274b6 commit a86a739

File tree

14 files changed

+57
-75
lines changed

14 files changed

+57
-75
lines changed

.golangci-kal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ issues:
108108
text: "field Ref is marked as required, should not be a pointer"
109109
linters:
110110
- kal
111-
- path: "api/v1alpha1/*|api/v1beta1/*|api/v1alpha3/*"
111+
- path: "api/v1alpha1/*|api/v1beta1/*|api/v1alpha3/*|api/addons/v1beta1/*"
112112
text: "field Items must be marked as optional or required"
113113
linters:
114114
- kal

.golangci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,6 @@ issues:
282282
- linters:
283283
- staticcheck
284284
text: "SA1019: feature.ClusterResourceSet is deprecated: ClusterResourceSet feature is now GA and the corresponding feature flag will be removed in 1.12 release."
285-
- linters:
286-
- revive
287-
text: "exported: type name will be used as clusterresourceset.ClusterResourceSetBindingReconciler by other packages, and that stutters; consider calling this BindingReconciler"
288-
- linters:
289-
- revive
290-
text: "exported: type name will be used as clusterresourceset.ClusterResourceSetReconciler by other packages, and that stutters; consider calling this Reconciler"
291285
- linters:
292286
- revive
293287
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,12 @@ generate-go-deepcopy: ## Run all generate-go-deepcopy-* targets
387387

388388
.PHONY: generate-go-deepcopy-core
389389
generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for core
390-
$(MAKE) clean-generated-deepcopy SRC_DIRS="./api,./internal/apis/addons,./$(EXP_DIR)/api,./$(EXP_DIR)/runtime/api,./$(EXP_DIR)/runtime/hooks/api"
390+
$(MAKE) clean-generated-deepcopy SRC_DIRS="./api,./internal/apis/addons,./internal/apis/core,./$(EXP_DIR)/api,./$(EXP_DIR)/runtime/api,./$(EXP_DIR)/runtime/hooks/api"
391391
$(CONTROLLER_GEN) \
392392
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
393393
paths=./api/... \
394394
paths=./internal/apis/addons/... \
395+
paths=./internal/apis/core/... \
395396
paths=./$(EXP_DIR)/api/... \
396397
paths=./$(EXP_DIR)/ipam/api/... \
397398
paths=./$(EXP_DIR)/runtime/api/... \
@@ -533,7 +534,7 @@ generate-go-conversions-test-extension: $(CONVERSION_GEN) ## Generate conversion
533534
.PHONY: generate-go-openapi
534535
generate-go-openapi: $(OPENAPI_GEN) ## Generate openapi go code for runtime SDK
535536
@mkdir -p ./tmp/sigs.k8s.io; ln -s $(ROOT_DIR) ./tmp/sigs.k8s.io/; cd ./tmp; \
536-
for pkg in "api/v1beta1" "api/addons/v1beta1" "$(EXP_DIR)/runtime/hooks/api/v1alpha1"; do \
537+
for pkg in "api/v1beta1" "$(EXP_DIR)/runtime/hooks/api/v1alpha1"; do \
537538
(cd ../ && $(MAKE) clean-generated-openapi-definitions SRC_DIRS="./$${pkg}"); \
538539
echo "** Generating openapi schema for types in ./$${pkg} **"; \
539540
$(OPENAPI_GEN) \

api/addons/v1beta1/clusterresourceset_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ type ClusterResourceSetList struct {
205205
// +optional
206206
metav1.ListMeta `json:"metadata,omitempty"`
207207
// items is the list of ClusterResourceSets.
208-
// +required
209208
Items []ClusterResourceSet `json:"items"`
210209
}
211210

api/addons/v1beta1/clusterresourcesetbinding_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ type ClusterResourceSetBindingList struct {
219219
// +optional
220220
metav1.ListMeta `json:"metadata,omitempty"`
221221
// items is the list of ClusterResourceSetBindings.
222-
// +required
223222
Items []ClusterResourceSetBinding `json:"items"`
224223
}
225224

controllers/alias.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
clustercontroller "sigs.k8s.io/cluster-api/internal/controllers/cluster"
3434
clusterclasscontroller "sigs.k8s.io/cluster-api/internal/controllers/clusterclass"
3535
"sigs.k8s.io/cluster-api/internal/controllers/clusterresourceset"
36+
"sigs.k8s.io/cluster-api/internal/controllers/clusterresourcesetbinding"
3637
machinecontroller "sigs.k8s.io/cluster-api/internal/controllers/machine"
3738
machinedeploymentcontroller "sigs.k8s.io/cluster-api/internal/controllers/machinedeployment"
3839
machinehealthcheckcontroller "sigs.k8s.io/cluster-api/internal/controllers/machinehealthcheck"
@@ -255,7 +256,7 @@ type ClusterResourceSetReconciler struct {
255256
}
256257

257258
func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options, partialSecretCache cache.Cache) error {
258-
return (&clusterresourceset.ClusterResourceSetReconciler{
259+
return (&clusterresourceset.Reconciler{
259260
Client: r.Client,
260261
ClusterCache: r.ClusterCache,
261262
WatchFilterValue: r.WatchFilterValue,
@@ -271,7 +272,7 @@ type ClusterResourceSetBindingReconciler struct {
271272
}
272273

273274
func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
274-
return (&clusterresourceset.ClusterResourceSetBindingReconciler{
275+
return (&clusterresourcesetbinding.Reconciler{
275276
Client: r.Client,
276277
WatchFilterValue: r.WatchFilterValue,
277278
}).SetupWithManager(ctx, mgr, options)

internal/controllers/clusterresourceset/clusterresourceset_controller.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ var ErrSecretTypeNotSupported = errors.New("unsupported secret type")
6161
// +kubebuilder:rbac:groups=addons.cluster.x-k8s.io,resources=*,verbs=get;list;watch;create;update;patch;delete
6262
// +kubebuilder:rbac:groups=addons.cluster.x-k8s.io,resources=clusterresourcesets/status;clusterresourcesets/finalizers,verbs=get;update;patch
6363

64-
// ClusterResourceSetReconciler reconciles a ClusterResourceSet object.
65-
type ClusterResourceSetReconciler struct {
64+
// Reconciler reconciles a ClusterResourceSet object.
65+
type Reconciler struct {
6666
Client client.Client
6767
ClusterCache clustercache.ClusterCache
6868

6969
// WatchFilterValue is the label value used to filter events prior to reconciliation.
7070
WatchFilterValue string
7171
}
7272

73-
func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options, partialSecretCache cache.Cache) error {
73+
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options, partialSecretCache cache.Cache) error {
7474
if r.Client == nil || r.ClusterCache == nil {
7575
return errors.New("Client and ClusterCache must not be nil")
7676
}
@@ -122,7 +122,7 @@ func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr
122122
return nil
123123
}
124124

125-
func (r *ClusterResourceSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
125+
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
126126
log := ctrl.LoggerFrom(ctx)
127127

128128
// Fetch the ClusterResourceSet instance.
@@ -214,7 +214,7 @@ func (r *ClusterResourceSetReconciler) Reconcile(ctx context.Context, req ctrl.R
214214
}
215215

216216
// reconcileDelete removes the deleted ClusterResourceSet from all the ClusterResourceSetBindings it is added to.
217-
func (r *ClusterResourceSetReconciler) reconcileDelete(ctx context.Context, clusters []*clusterv1.Cluster, crs *addonsv1.ClusterResourceSet) error {
217+
func (r *Reconciler) reconcileDelete(ctx context.Context, clusters []*clusterv1.Cluster, crs *addonsv1.ClusterResourceSet) error {
218218
for _, cluster := range clusters {
219219
log := ctrl.LoggerFrom(ctx, "Cluster", klog.KObj(cluster))
220220

@@ -260,7 +260,7 @@ func (r *ClusterResourceSetReconciler) reconcileDelete(ctx context.Context, clus
260260
}
261261

262262
// getClustersByClusterResourceSetSelector fetches Clusters matched by the ClusterResourceSet's label selector that are in the same namespace as the ClusterResourceSet object.
263-
func (r *ClusterResourceSetReconciler) getClustersByClusterResourceSetSelector(ctx context.Context, clusterResourceSet *addonsv1.ClusterResourceSet) ([]*clusterv1.Cluster, error) {
263+
func (r *Reconciler) getClustersByClusterResourceSetSelector(ctx context.Context, clusterResourceSet *addonsv1.ClusterResourceSet) ([]*clusterv1.Cluster, error) {
264264
log := ctrl.LoggerFrom(ctx)
265265

266266
clusterList := &clusterv1.ClusterList{}
@@ -296,7 +296,7 @@ func (r *ClusterResourceSetReconciler) getClustersByClusterResourceSetSelector(c
296296
// In Reconcile strategy, resources are re-applied to a particular cluster when their definition changes. The hash in ClusterResourceSetBinding is used to check
297297
// if a resource has changed or not.
298298
// TODO: If a resource already exists in the cluster but not applied by ClusterResourceSet, the resource will be updated ?
299-
func (r *ClusterResourceSetReconciler) ApplyClusterResourceSet(ctx context.Context, cluster *clusterv1.Cluster, clusterResourceSet *addonsv1.ClusterResourceSet) (rerr error) {
299+
func (r *Reconciler) ApplyClusterResourceSet(ctx context.Context, cluster *clusterv1.Cluster, clusterResourceSet *addonsv1.ClusterResourceSet) (rerr error) {
300300
log := ctrl.LoggerFrom(ctx, "Cluster", klog.KObj(cluster))
301301
ctx = ctrl.LoggerInto(ctx, log)
302302

@@ -466,7 +466,7 @@ func (r *ClusterResourceSetReconciler) ApplyClusterResourceSet(ctx context.Conte
466466
// getResource retrieves the requested resource and convert it to unstructured type.
467467
// Unsupported resource kinds are not denied by validation webhook, hence no need to check here.
468468
// Only supports Secrets/Configmaps as resource types and allow using resources in the same namespace with the cluster.
469-
func (r *ClusterResourceSetReconciler) getResource(ctx context.Context, resourceRef addonsv1.ResourceRef, namespace string) (*unstructured.Unstructured, error) {
469+
func (r *Reconciler) getResource(ctx context.Context, resourceRef addonsv1.ResourceRef, namespace string) (*unstructured.Unstructured, error) {
470470
resourceName := types.NamespacedName{Name: resourceRef.Name, Namespace: namespace}
471471

472472
var resourceInterface interface{}
@@ -500,7 +500,7 @@ func (r *ClusterResourceSetReconciler) getResource(ctx context.Context, resource
500500
}
501501

502502
// ensureResourceOwnerRef adds the ClusterResourceSet as a OwnerReference to the resource.
503-
func (r *ClusterResourceSetReconciler) ensureResourceOwnerRef(ctx context.Context, clusterResourceSet *addonsv1.ClusterResourceSet, resource *unstructured.Unstructured) error {
503+
func (r *Reconciler) ensureResourceOwnerRef(ctx context.Context, clusterResourceSet *addonsv1.ClusterResourceSet, resource *unstructured.Unstructured) error {
504504
obj := resource.DeepCopy()
505505
patchHelper, err := patch.NewHelper(obj, r.Client)
506506
if err != nil {
@@ -517,7 +517,7 @@ func (r *ClusterResourceSetReconciler) ensureResourceOwnerRef(ctx context.Contex
517517
}
518518

519519
// clusterToClusterResourceSet is mapper function that maps clusters to ClusterResourceSet.
520-
func (r *ClusterResourceSetReconciler) clusterToClusterResourceSet(ctx context.Context, o client.Object) []ctrl.Request {
520+
func (r *Reconciler) clusterToClusterResourceSet(ctx context.Context, o client.Object) []ctrl.Request {
521521
result := []ctrl.Request{}
522522

523523
cluster, ok := o.(*clusterv1.Cluster)

internal/controllers/clusterresourceset/clusterresourceset_helpers.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
apierrors "k8s.io/apimachinery/pkg/api/errors"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
35-
"k8s.io/apimachinery/pkg/runtime/schema"
3635
"k8s.io/apimachinery/pkg/types"
3736
"k8s.io/klog/v2"
3837
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -108,7 +107,7 @@ func createUnstructured(ctx context.Context, c client.Client, obj *unstructured.
108107
}
109108

110109
// getOrCreateClusterResourceSetBinding retrieves ClusterResourceSetBinding resource owned by the cluster or create a new one if not found.
111-
func (r *ClusterResourceSetReconciler) getOrCreateClusterResourceSetBinding(ctx context.Context, cluster *clusterv1.Cluster, clusterResourceSet *addonsv1.ClusterResourceSet) (*addonsv1.ClusterResourceSetBinding, error) {
110+
func (r *Reconciler) getOrCreateClusterResourceSetBinding(ctx context.Context, cluster *clusterv1.Cluster, clusterResourceSet *addonsv1.ClusterResourceSet) (*addonsv1.ClusterResourceSetBinding, error) {
112111
clusterResourceSetBinding := &addonsv1.ClusterResourceSetBinding{
113112
ObjectMeta: metav1.ObjectMeta{
114113
Name: cluster.Name,
@@ -223,27 +222,6 @@ func normalizeData(resource *unstructured.Unstructured) ([][]byte, error) {
223222
return dataList, nil
224223
}
225224

226-
func getClusterNameFromOwnerRef(obj metav1.ObjectMeta) (string, error) {
227-
for _, ref := range obj.GetOwnerReferences() {
228-
if ref.Kind != "Cluster" {
229-
continue
230-
}
231-
gv, err := schema.ParseGroupVersion(ref.APIVersion)
232-
if err != nil {
233-
return "", errors.Wrap(err, "failed to find cluster name in ownerRefs")
234-
}
235-
236-
if gv.Group != clusterv1.GroupVersion.Group {
237-
continue
238-
}
239-
if ref.Name == "" {
240-
return "", errors.New("failed to find cluster name in ownerRefs: ref name is empty")
241-
}
242-
return ref.Name, nil
243-
}
244-
return "", errors.New("failed to find cluster name in ownerRefs: no cluster ownerRef")
245-
}
246-
247225
// ensureKubernetesServiceCreated ensures that the Service for Kubernetes API Server has been created.
248226
func ensureKubernetesServiceCreated(ctx context.Context, client client.Client) error {
249227
err := client.Get(ctx, types.NamespacedName{

internal/controllers/clusterresourceset/clusterresourceset_helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestGetorCreateClusterResourceSetBinding(t *testing.T) {
8080
c := fake.NewClientBuilder().
8181
WithObjects(testClusterResourceSetBinding).
8282
Build()
83-
r := &ClusterResourceSetReconciler{
83+
r := &Reconciler{
8484
Client: c,
8585
}
8686

internal/controllers/clusterresourceset/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package clusterresourceset implements experimental addon controllers.
17+
// Package clusterresourceset implements the ClusterResourceSet controller.
1818
package clusterresourceset

0 commit comments

Comments
 (0)