Skip to content

Commit

Permalink
dev: unify keeper and CHI scheme building approach
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsingerus committed Nov 17, 2023
1 parent ac27759 commit c585a8c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
22 changes: 12 additions & 10 deletions pkg/apis/clickhouse.altinity.com/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,41 @@ const (
APIVersion = "v1"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{
// GroupVersion is group version used to register these objects
var GroupVersion = schema.GroupVersion{
Group: clickhousealtinitycom.APIGroupName,
Version: APIVersion,
}

// Resource returns schema.GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
return GroupVersion.WithResource(resource).GroupResource()
}

var (
// SchemeBuilder collects scheme builder functions
SchemeBuilder runtime.SchemeBuilder
// localSchemeBuilder is an instance of SchemeBuilder
localSchemeBuilder = new(runtime.SchemeBuilder)

// AddToScheme applies SchemeBuilder functions to the specified scheme
AddToScheme = localSchemeBuilder.AddToScheme
localSchemeBuilder = &SchemeBuilder
// This function is called from the generated client code
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
localSchemeBuilder.Register(addKnownTypes)
}

// Adds a list of known types to the api.Scheme object
// addKnownTypes adds list of known types to the api.Scheme object
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
scheme.AddKnownTypes(
GroupVersion,
&ClickHouseInstallation{},
&ClickHouseInstallationList{},
&ClickHouseInstallationTemplate{},
&ClickHouseInstallationTemplateList{},
&ClickHouseOperatorConfiguration{},
&ClickHouseOperatorConfigurationList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
metav1.AddToGroupVersion(scheme, GroupVersion)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "clickhouse.com", Version: "v1alpha1"}
GroupVersion = schema.GroupVersion{
Group: "clickhouse.com",
Version: "v1alpha1",
}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
SchemeBuilder = &scheme.Builder{
GroupVersion: GroupVersion,
}

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

func init() {
SchemeBuilder.Register(
&ClickHouseKeeper{},
&ClickHouseKeeperList{},
)
}
4 changes: 0 additions & 4 deletions pkg/apis/clickhouse.com/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&ClickHouseKeeper{}, &ClickHouseKeeperList{})
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClickHouseKeeper defines a ClickHouse Keeper Cluster
Expand Down

0 comments on commit c585a8c

Please sign in to comment.