Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ linters:
- dupl
- errcheck
- ginkgolinter
- goconst
- gocyclo
- govet
- ineffassign
Expand Down Expand Up @@ -51,6 +50,9 @@ linters:
# Omit embedded fields from selector expression.
# https://staticcheck.dev/docs/checks/#QF1008
- -QF1008
# Use fmt.Fprintf.
# https://staticcheck.dev/docs/checks/#QF1008
- -QF1012
exclusions:
generated: lax
rules:
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ IMG ?= ghcr.io/controlplaneio-fluxcd/flux-operator:latest
FLUX_OPERATOR_VERSION ?= $(shell gh release view --json tagName -q '.tagName')
FLUX_OPERATOR_DEV_VERSION?=0.0.0-$(shell git rev-parse --abbrev-ref HEAD)-$(shell git rev-parse --short HEAD)-$(shell date +%s)
FLUX_VERSION = $(shell gh release view --repo fluxcd/flux2 --json tagName -q '.tagName')
ENVTEST_K8S_VERSION = 1.35.0
ENVTEST_K8S_VERSION = 1.36.0
GO_TEST_ARGS ?=

# Get the currently used golang install path
Expand Down Expand Up @@ -292,10 +292,10 @@ OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)
GOVULNCHECK ?= $(LOCALBIN)/govulncheck

## Tool Versions
KUSTOMIZE_VERSION ?= v5.8.0
CONTROLLER_TOOLS_VERSION ?= v0.20.0
KUSTOMIZE_VERSION ?= v5.8.1
CONTROLLER_TOOLS_VERSION ?= v0.21.0
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
GOLANGCI_LINT_VERSION ?= v2.9.0
GOLANGCI_LINT_VERSION ?= v2.12.2
OPERATOR_SDK_VERSION ?= v1.41.1

.PHONY: operator-sdk
Expand Down
27 changes: 23 additions & 4 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,36 @@
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "fluxcd.controlplane.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
// schemeBuilder accumulates the type registration functions for this API group.
schemeBuilder runtime.SchemeBuilder

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &groupVersionBuilder{}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
AddToScheme = schemeBuilder.AddToScheme
)

// groupVersionBuilder registers Go types with the package's GroupVersion.
// It replaces the deprecated sigs.k8s.io/controller-runtime/pkg/scheme.Builder
// so that this API package depends only on k8s.io/apimachinery.
type groupVersionBuilder struct{}

// Register schedules the given runtime.Object types to be added to the scheme
// under the package's GroupVersion when AddToScheme is called.
func (b *groupVersionBuilder) Register(objects ...runtime.Object) {
schemeBuilder.Register(func(s *runtime.Scheme) error {
s.AddKnownTypes(GroupVersion, objects...)
metav1.AddToGroupVersion(s, GroupVersion)
return nil
})
}
Comment on lines +19 to +42
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting approach, the comment on the deprecated scheme.Builder is the following:

(and that's what I did here... wondering if it's flawed...)

// Builder builds a new Scheme for mapping go types to Kubernetes GroupVersionKinds.
//
// Deprecated: This helper is only useful in api packages, but api packages should be
// easy to import and hence have minimal dependencies. Typically, these dependencies
// include only the standard library, k8s.io/apimachinery and other api packages.
//
// Use the apimachinery builder instead:
//
//	import (
//		metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
//		"k8s.io/apimachinery/pkg/runtime"
//		"k8s.io/apimachinery/pkg/runtime/schema"
//	)
//
//	const GroupName = ""
//
//	var (
//		SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
//		SchemeBuilder 		 = runtime.NewSchemeBuilder(addKnownTypes)
//		AddToScheme   		 = SchemeBuilder.AddToScheme
//	)
//
//	func addKnownTypes(scheme *runtime.Scheme) error {
//		scheme.AddKnownTypes(SchemeGroupVersion,
//			&Pod{},
//		)
//
//		metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
//		return nil
//	}
type Builder struct {
	GroupVersion schema.GroupVersion
	runtime.SchemeBuilder
}

Copy link
Copy Markdown
Member Author

@stefanprodan stefanprodan May 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that each type handles its own registration. Adding a new CRD and registering it happen in the same file.

2 changes: 1 addition & 1 deletion api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions cmd/cli/distro_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ func isNotFound(err error) bool {
if err == nil {
return false
}
var terr *transport.Error
if errors.As(err, &terr) {
if terr, ok := errors.AsType[*transport.Error](err); ok {
return terr.StatusCode == 404
}
return false
Expand Down
3 changes: 1 addition & 2 deletions cmd/cli/migrate_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ const (
)

func installMigrateTestCRD(ctx context.Context, g *WithT) func() {
preserve := true
schemaProps := &apiextensionsv1.JSONSchemaProps{
Type: "object",
Properties: map[string]apiextensionsv1.JSONSchemaProps{
"spec": {
Type: "object",
XPreserveUnknownFields: &preserve,
XPreserveUnknownFields: new(true),
},
},
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
ctrlcache "sigs.k8s.io/controller-runtime/pkg/cache"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -224,7 +223,7 @@ func main() {
RetryPeriod: &leaderElectionOptions.RetryPeriod,
Controller: ctrlcfg.Controller{
MaxConcurrentReconciles: concurrent,
RecoverPanic: ptr.To(true),
RecoverPanic: new(true),
},
Client: ctrlclient.Options{
Cache: &ctrlclient.CacheOptions{
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.20.0
controller-gen.kubebuilder.io/version: v0.21.0
name: fluxinstances.fluxcd.controlplane.io
spec:
group: fluxcd.controlplane.io
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/fluxcd.controlplane.io_fluxreports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.20.0
controller-gen.kubebuilder.io/version: v0.21.0
name: fluxreports.fluxcd.controlplane.io
spec:
group: fluxcd.controlplane.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.20.0
controller-gen.kubebuilder.io/version: v0.21.0
name: resourcesetinputproviders.fluxcd.controlplane.io
spec:
group: fluxcd.controlplane.io
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/fluxcd.controlplane.io_resourcesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.20.0
controller-gen.kubebuilder.io/version: v0.21.0
name: resourcesets.fluxcd.controlplane.io
spec:
group: fluxcd.controlplane.io
Expand Down
Loading
Loading