Skip to content

Commit

Permalink
Remove leftovers from controller-gen migration (rancher#1920)
Browse files Browse the repository at this point in the history
Co-authored-by: raul <[email protected]>
  • Loading branch information
aruiz14 and raulcabello authored Oct 31, 2023
1 parent 8173b4a commit d463f59
Show file tree
Hide file tree
Showing 23 changed files with 202 additions and 424 deletions.
1 change: 1 addition & 0 deletions cmd/codegen/hack/generate_and_sort_crds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ if ! $CONTROLLERGEN --version | grep -q "${CONTROLLERGEN_VERSION}" ; then
fi

# Run controller-gen
${CONTROLLERGEN} object:headerFile=scripts/boilerplate.go.txt,year="$(date +%Y)" paths="./pkg/apis/..."
${CONTROLLERGEN} crd webhook paths="./pkg/apis/..." output:stdout > $CRDS_YAML
# Sort
run_yq --slurp --sort-keys --explicit-start --yaml-output -i 'sort_by(.metadata.name)[]' $CRDS_YAML
1 change: 0 additions & 1 deletion cmd/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func main() {
Types: []interface{}{
"./pkg/apis/fleet.cattle.io/v1alpha1",
},
GenerateTypes: true,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/rancher/fleet/internal/config"
fname "github.com/rancher/fleet/internal/name"
"github.com/rancher/fleet/internal/registration"
fleetgroup "github.com/rancher/fleet/pkg/apis/fleet.cattle.io"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/durations"
fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
Expand Down Expand Up @@ -235,8 +234,8 @@ func (h *handler) OnChange(request *fleet.ClusterRegistration, status fleet.Clus
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"patch"},
APIGroups: []string{fleetgroup.GroupName},
Resources: []string{fleet.ClusterResourceName + "/status"},
APIGroups: []string{fleet.SchemeGroupVersion.Group},
Resources: []string{fleet.ClusterResourceNamePlural + "/status"},
ResourceNames: []string{cluster.Name},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

secretutil "github.com/rancher/fleet/internal/cmd/controller/secret"
"github.com/rancher/fleet/internal/config"
fleetgroup "github.com/rancher/fleet/pkg/apis/fleet.cattle.io"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1"

Expand Down Expand Up @@ -154,8 +153,8 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"create"},
APIGroups: []string{fleetgroup.GroupName},
Resources: []string{fleet.ClusterRegistrationResourceName},
APIGroups: []string{fleet.SchemeGroupVersion.Group},
Resources: []string{fleet.ClusterRegistrationResourceNamePlural},
},
},
},
Expand Down
13 changes: 6 additions & 7 deletions internal/cmd/controller/controllers/resources/data.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package resources

import (
fleetgroup "github.com/rancher/fleet/pkg/apis/fleet.cattle.io"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"

"github.com/rancher/wrangler/v2/pkg/apply"
Expand All @@ -27,13 +26,13 @@ func ApplyBootstrapResources(systemNamespace, systemRegistrationNamespace string
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"get", "list", "watch"},
APIGroups: []string{fleetgroup.GroupName},
Resources: []string{fleet.BundleDeploymentResourceName},
APIGroups: []string{fleet.SchemeGroupVersion.Group},
Resources: []string{fleet.BundleDeploymentResourceNamePlural},
},
{
Verbs: []string{"update"},
APIGroups: []string{fleetgroup.GroupName},
Resources: []string{fleet.BundleDeploymentResourceName + "/status"},
APIGroups: []string{fleet.SchemeGroupVersion.Group},
Resources: []string{fleet.BundleDeploymentResourceNamePlural + "/status"},
},
},
},
Expand All @@ -45,8 +44,8 @@ func ApplyBootstrapResources(systemNamespace, systemRegistrationNamespace string
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
APIGroups: []string{fleetgroup.GroupName},
Resources: []string{fleet.ContentResourceName},
APIGroups: []string{fleet.SchemeGroupVersion.Group},
Resources: []string{fleet.ContentResourceNamePlural},
},
},
},
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/bundle_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

func init() {
SchemeBuilder.Register(&Bundle{}, &BundleList{})
}

var (
// Ready: Bundles have been deployed and all resources are ready.
Ready BundleState = "Ready"
Expand Down Expand Up @@ -70,6 +74,15 @@ type Bundle struct {
Status BundleStatus `json:"status"`
}

// +kubebuilder:object:root=true

// BundleList contains a list of Bundle
type BundleList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Bundle `json:"items"`
}

type BundleSpec struct {
BundleDeploymentOptions `json:",inline"`

Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/bundledeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
"k8s.io/apimachinery/pkg/types"
)

const BundleDeploymentResourceNamePlural = "bundledeployments"

func init() {
SchemeBuilder.Register(&BundleDeployment{}, &BundleDeploymentList{})
}

// MaxHelmReleaseNameLen is the maximum length of a Helm release name.
// See https://github.com/helm/helm/blob/293b50c65d4d56187cd4e2f390f0ada46b4c4737/pkg/chartutil/validate_name.go#L54-L61
const MaxHelmReleaseNameLen = 53
Expand All @@ -36,6 +42,15 @@ type BundleDeployment struct {
Status BundleDeploymentStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// BundleDeploymentList contains a list of BundleDeployment
type BundleDeploymentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BundleDeployment `json:"items"`
}

type BundleDeploymentOptions struct {
// DefaultNamespace is the namespace to use for resources that do not
// specify a namespace. This field is not used to enforce or lock down
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/bundlenamespacemapping_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&BundleNamespaceMapping{}, &BundleNamespaceMappingList{})
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
Expand All @@ -19,3 +23,12 @@ type BundleNamespaceMapping struct {
// +nullable
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
}

// +kubebuilder:object:root=true

// BundleNamespaceMappingList contains a list of BundleNamespaceMapping
type BundleNamespaceMappingList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BundleNamespaceMapping `json:"items"`
}
15 changes: 15 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&Cluster{}, &ClusterList{})
}

const ClusterResourceNamePlural = "clusters"

var (
// ClusterConditionReady indicates that all bundles in this cluster
// have been deployed and all resources are ready.
Expand Down Expand Up @@ -57,6 +63,15 @@ type Cluster struct {
Status ClusterStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// ClusterList contains a list of Cluster
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cluster `json:"items"`
}

type ClusterSpec struct {
// Paused if set to true, will stop any BundleDeployments from being updated.
Paused bool `json:"paused,omitempty"`
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/clustergroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&ClusterGroup{}, &ClusterGroupList{})
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
Expand All @@ -25,6 +29,15 @@ type ClusterGroup struct {
Status ClusterGroupStatus `json:"status"`
}

// +kubebuilder:object:root=true

// ClusterGroupList contains a list of ClusterGroup
type ClusterGroupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterGroup `json:"items"`
}

type ClusterGroupSpec struct {
// Selector is a label selector, used to select clusters for this group.
// +nullable
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/clusterregistration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const ClusterRegistrationResourceNamePlural = "clusterregistrations"

func init() {
SchemeBuilder.Register(&ClusterRegistration{}, &ClusterRegistrationList{})
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
Expand All @@ -20,6 +26,15 @@ type ClusterRegistration struct {
Status ClusterRegistrationStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// ClusterRegistrationList contains a list of ClusterRegistration
type ClusterRegistrationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterRegistration `json:"items"`
}

type ClusterRegistrationSpec struct {
// ClientID is a unique string that will identify the cluster. The
// agent either uses the configured ID or the kubeSystem.UID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&ClusterRegistrationToken{}, &ClusterRegistrationTokenList{})
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
Expand All @@ -19,6 +23,15 @@ type ClusterRegistrationToken struct {
Status ClusterRegistrationTokenStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// ClusterRegistrationTokenList contains a list of ClusterRegistrationToken
type ClusterRegistrationTokenList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterRegistrationToken `json:"items"`
}

type ClusterRegistrationTokenSpec struct {
// TTL is the time to live for the token. It is used to calculate the
// expiration time. If the token expires, it will be deleted.
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/content_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const ContentResourceNamePlural = "contents"

func init() {
SchemeBuilder.Register(&Content{}, &ContentList{})
}

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -23,3 +29,12 @@ type Content struct {
// +nullable
Content []byte `json:"content,omitempty"`
}

// +kubebuilder:object:root=true

// ContentList contains a list of Content
type ContentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Content `json:"items"`
}
13 changes: 13 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/gitrepo_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&GitRepo{}, &GitRepoList{})
}

var (
RepoLabel = "fleet.cattle.io/repo-name"
BundleLabel = "fleet.cattle.io/bundle-name"
Expand Down Expand Up @@ -32,6 +36,15 @@ type GitRepo struct {
Status GitRepoStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// GitRepoList contains a list of GitRepo
type GitRepoList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GitRepo `json:"items"`
}

type GitRepoSpec struct {
// Repo is a URL to a git repo to clone and index.
// +nullable
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/gitreporestriction_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&GitRepoRestriction{}, &GitRepoRestrictionList{})
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
Expand Down Expand Up @@ -41,3 +45,12 @@ type GitRepoRestriction struct {
// +nullable
AllowedTargetNamespaces []string `json:"allowedTargetNamespaces,omitempty"`
}

// +kubebuilder:object:root=true

// GitRepoRestrictionList contains a list of GitRepoRestriction
type GitRepoRestrictionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GitRepoRestriction `json:"items"`
}
27 changes: 27 additions & 0 deletions pkg/apis/fleet.cattle.io/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2021-2023 SUSE LLC

// Package v1alpha1 contains API Schema definitions for the fleet.cattle.io v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=fleet.cattle.io
package v1alpha1

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

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "fleet.cattle.io", Version: "v1alpha1"}

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

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

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Loading

0 comments on commit d463f59

Please sign in to comment.