From 13f51bb02579fa83daf97d07ab8f1cb3e91d31db Mon Sep 17 00:00:00 2001 From: Yannick Stevenin Date: Fri, 4 Nov 2022 15:24:54 -0300 Subject: [PATCH 1/3] fix: rename jwt kind to auth role --- CONTRIBUTING.md | 4 +- .../v1alpha1/{jwt_types.go => role_types.go} | 46 ++++++++-------- apis/auth/v1alpha1/zz_generated.deepcopy.go | 54 +++++++++---------- apis/auth/v1alpha1/zz_generated.managed.go | 48 ++++++++--------- .../auth/v1alpha1/zz_generated.managedlist.go | 4 +- examples/auth/jwt_role.yaml | 2 +- .../{jwt/jwt.go => auth/role/role.go} | 33 ++++++------ .../jwt_test.go => auth/role/role_test.go} | 39 +++++++------- .../controller/{jwt => auth/role}/vault.go | 4 +- internal/controller/vault.go | 4 +- ...ml => auth.vault.crossplane.io_roles.yaml} | 21 ++++---- 11 files changed, 130 insertions(+), 129 deletions(-) rename apis/auth/v1alpha1/{jwt_types.go => role_types.go} (89%) rename internal/controller/{jwt/jwt.go => auth/role/role.go} (92%) rename internal/controller/{jwt/jwt_test.go => auth/role/role_test.go} (97%) rename internal/controller/{jwt => auth/role}/vault.go (98%) rename package/crds/{auth.vault.crossplane.io_jwts.yaml => auth.vault.crossplane.io_roles.yaml} (97%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3755f51..1370037 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,12 +5,14 @@ - [gomplate](https://docs.gomplate.ca/) - Docker +### TODO: Add missing steps (make submodules -> make generate -> make go.build ) + ### Adding new Kind to the controller - `GOMPLATE=gomplate KIND=your_kind GROUP=your_group PROVIDER=Vault hack/helpers/addtype.sh` - Define your resource spec under `apis//_types.go` - `make generate` - Proper define the `Observe`, `Create`, `Update`, `Delete` methods in `internal/controller//.go` -- Add your resource controller in the `Setup` method [here](.internal/controller/vault.go). +- Add your resource controller in the `Setup` method [here](internal/controller/vault.go). ### Testing locally diff --git a/apis/auth/v1alpha1/jwt_types.go b/apis/auth/v1alpha1/role_types.go similarity index 89% rename from apis/auth/v1alpha1/jwt_types.go rename to apis/auth/v1alpha1/role_types.go index df426a1..9612798 100644 --- a/apis/auth/v1alpha1/jwt_types.go +++ b/apis/auth/v1alpha1/role_types.go @@ -25,8 +25,8 @@ import ( xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" ) -// JwtParameters are the configurable fields of a Jwt Auth Backend Role. -type JwtParameters struct { +// RoleParameters are the configurable fields of Auth Role +type RoleParameters struct { // The namespace to provision the resource in. The value should not contain // leading or trailing forward slashes. The namespace is always relative to @@ -175,57 +175,57 @@ type JwtParameters struct { TokenType *string `json:"tokenType,omitempty"` } -// JwtObservation are the observable fields of a Jwt. -type JwtObservation struct { +// RoleObservation are the observable fields of a Role. +type RoleObservation struct { ObservableField string `json:"observableField,omitempty"` } -// A JwtSpec defines the desired state of a Jwt. -type JwtSpec struct { +// A RoleSpec defines the desired state of a Role. +type RoleSpec struct { xpv1.ResourceSpec `json:",inline"` - ForProvider JwtParameters `json:"forProvider"` + ForProvider RoleParameters `json:"forProvider"` } -// A JwtStatus represents the observed state of a Jwt. -type JwtStatus struct { +// A RoleStatus represents the observed state of a Role. +type RoleStatus struct { xpv1.ResourceStatus `json:",inline"` - AtProvider JwtObservation `json:"atProvider,omitempty"` + AtProvider RoleObservation `json:"atProvider,omitempty"` } // +kubebuilder:object:root=true -// A Jwt is an example API type. +// A Role is an example API type. // +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" // +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" // +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" // +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:subresource:status // +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,vault} -type Jwt struct { +type Role struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec JwtSpec `json:"spec"` - Status JwtStatus `json:"status,omitempty"` + Spec RoleSpec `json:"spec"` + Status RoleStatus `json:"status,omitempty"` } // +kubebuilder:object:root=true -// JwtList contains a list of Jwt -type JwtList struct { +// RoleList contains a list of Role +type RoleList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []Jwt `json:"items"` + Items []Role `json:"items"` } -// Jwt type metadata. +// Role type metadata. var ( - JwtKind = reflect.TypeOf(Jwt{}).Name() - JwtGroupKind = schema.GroupKind{Group: Group, Kind: JwtKind}.String() - JwtKindAPIVersion = JwtKind + "." + SchemeGroupVersion.String() - JwtGroupVersionKind = SchemeGroupVersion.WithKind(JwtKind) + RoleKind = reflect.TypeOf(Role{}).Name() + RoleGroupKind = schema.GroupKind{Group: Group, Kind: RoleKind}.String() + RoleKindAPIVersion = RoleKind + "." + SchemeGroupVersion.String() + RoleGroupVersionKind = SchemeGroupVersion.WithKind(RoleKind) ) func init() { - SchemeBuilder.Register(&Jwt{}, &JwtList{}) + SchemeBuilder.Register(&Role{}, &RoleList{}) } diff --git a/apis/auth/v1alpha1/zz_generated.deepcopy.go b/apis/auth/v1alpha1/zz_generated.deepcopy.go index ced0302..e5a94b1 100644 --- a/apis/auth/v1alpha1/zz_generated.deepcopy.go +++ b/apis/auth/v1alpha1/zz_generated.deepcopy.go @@ -26,7 +26,7 @@ import ( ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Jwt) DeepCopyInto(out *Jwt) { +func (in *Role) DeepCopyInto(out *Role) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -34,18 +34,18 @@ func (in *Jwt) DeepCopyInto(out *Jwt) { in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Jwt. -func (in *Jwt) DeepCopy() *Jwt { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Role. +func (in *Role) DeepCopy() *Role { if in == nil { return nil } - out := new(Jwt) + out := new(Role) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Jwt) DeepCopyObject() runtime.Object { +func (in *Role) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -53,31 +53,31 @@ func (in *Jwt) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *JwtList) DeepCopyInto(out *JwtList) { +func (in *RoleList) DeepCopyInto(out *RoleList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]Jwt, len(*in)) + *out = make([]Role, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JwtList. -func (in *JwtList) DeepCopy() *JwtList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoleList. +func (in *RoleList) DeepCopy() *RoleList { if in == nil { return nil } - out := new(JwtList) + out := new(RoleList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *JwtList) DeepCopyObject() runtime.Object { +func (in *RoleList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -85,22 +85,22 @@ func (in *JwtList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *JwtObservation) DeepCopyInto(out *JwtObservation) { +func (in *RoleObservation) DeepCopyInto(out *RoleObservation) { *out = *in } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JwtObservation. -func (in *JwtObservation) DeepCopy() *JwtObservation { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoleObservation. +func (in *RoleObservation) DeepCopy() *RoleObservation { if in == nil { return nil } - out := new(JwtObservation) + out := new(RoleObservation) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *JwtParameters) DeepCopyInto(out *JwtParameters) { +func (in *RoleParameters) DeepCopyInto(out *RoleParameters) { *out = *in if in.Namespace != nil { in, out := &in.Namespace, &out.Namespace @@ -243,46 +243,46 @@ func (in *JwtParameters) DeepCopyInto(out *JwtParameters) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JwtParameters. -func (in *JwtParameters) DeepCopy() *JwtParameters { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoleParameters. +func (in *RoleParameters) DeepCopy() *RoleParameters { if in == nil { return nil } - out := new(JwtParameters) + out := new(RoleParameters) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *JwtSpec) DeepCopyInto(out *JwtSpec) { +func (in *RoleSpec) DeepCopyInto(out *RoleSpec) { *out = *in in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) in.ForProvider.DeepCopyInto(&out.ForProvider) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JwtSpec. -func (in *JwtSpec) DeepCopy() *JwtSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoleSpec. +func (in *RoleSpec) DeepCopy() *RoleSpec { if in == nil { return nil } - out := new(JwtSpec) + out := new(RoleSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *JwtStatus) DeepCopyInto(out *JwtStatus) { +func (in *RoleStatus) DeepCopyInto(out *RoleStatus) { *out = *in in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) out.AtProvider = in.AtProvider } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JwtStatus. -func (in *JwtStatus) DeepCopy() *JwtStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoleStatus. +func (in *RoleStatus) DeepCopy() *RoleStatus { if in == nil { return nil } - out := new(JwtStatus) + out := new(RoleStatus) in.DeepCopyInto(out) return out } diff --git a/apis/auth/v1alpha1/zz_generated.managed.go b/apis/auth/v1alpha1/zz_generated.managed.go index 5ff22d3..3fce563 100644 --- a/apis/auth/v1alpha1/zz_generated.managed.go +++ b/apis/auth/v1alpha1/zz_generated.managed.go @@ -19,68 +19,68 @@ package v1alpha1 import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" -// GetCondition of this Jwt. -func (mg *Jwt) GetCondition(ct xpv1.ConditionType) xpv1.Condition { +// GetCondition of this Role. +func (mg *Role) GetCondition(ct xpv1.ConditionType) xpv1.Condition { return mg.Status.GetCondition(ct) } -// GetDeletionPolicy of this Jwt. -func (mg *Jwt) GetDeletionPolicy() xpv1.DeletionPolicy { +// GetDeletionPolicy of this Role. +func (mg *Role) GetDeletionPolicy() xpv1.DeletionPolicy { return mg.Spec.DeletionPolicy } -// GetProviderConfigReference of this Jwt. -func (mg *Jwt) GetProviderConfigReference() *xpv1.Reference { +// GetProviderConfigReference of this Role. +func (mg *Role) GetProviderConfigReference() *xpv1.Reference { return mg.Spec.ProviderConfigReference } /* -GetProviderReference of this Jwt. +GetProviderReference of this Role. Deprecated: Use GetProviderConfigReference. */ -func (mg *Jwt) GetProviderReference() *xpv1.Reference { +func (mg *Role) GetProviderReference() *xpv1.Reference { return mg.Spec.ProviderReference } -// GetPublishConnectionDetailsTo of this Jwt. -func (mg *Jwt) GetPublishConnectionDetailsTo() *xpv1.PublishConnectionDetailsTo { +// GetPublishConnectionDetailsTo of this Role. +func (mg *Role) GetPublishConnectionDetailsTo() *xpv1.PublishConnectionDetailsTo { return mg.Spec.PublishConnectionDetailsTo } -// GetWriteConnectionSecretToReference of this Jwt. -func (mg *Jwt) GetWriteConnectionSecretToReference() *xpv1.SecretReference { +// GetWriteConnectionSecretToReference of this Role. +func (mg *Role) GetWriteConnectionSecretToReference() *xpv1.SecretReference { return mg.Spec.WriteConnectionSecretToReference } -// SetConditions of this Jwt. -func (mg *Jwt) SetConditions(c ...xpv1.Condition) { +// SetConditions of this Role. +func (mg *Role) SetConditions(c ...xpv1.Condition) { mg.Status.SetConditions(c...) } -// SetDeletionPolicy of this Jwt. -func (mg *Jwt) SetDeletionPolicy(r xpv1.DeletionPolicy) { +// SetDeletionPolicy of this Role. +func (mg *Role) SetDeletionPolicy(r xpv1.DeletionPolicy) { mg.Spec.DeletionPolicy = r } -// SetProviderConfigReference of this Jwt. -func (mg *Jwt) SetProviderConfigReference(r *xpv1.Reference) { +// SetProviderConfigReference of this Role. +func (mg *Role) SetProviderConfigReference(r *xpv1.Reference) { mg.Spec.ProviderConfigReference = r } /* -SetProviderReference of this Jwt. +SetProviderReference of this Role. Deprecated: Use SetProviderConfigReference. */ -func (mg *Jwt) SetProviderReference(r *xpv1.Reference) { +func (mg *Role) SetProviderReference(r *xpv1.Reference) { mg.Spec.ProviderReference = r } -// SetPublishConnectionDetailsTo of this Jwt. -func (mg *Jwt) SetPublishConnectionDetailsTo(r *xpv1.PublishConnectionDetailsTo) { +// SetPublishConnectionDetailsTo of this Role. +func (mg *Role) SetPublishConnectionDetailsTo(r *xpv1.PublishConnectionDetailsTo) { mg.Spec.PublishConnectionDetailsTo = r } -// SetWriteConnectionSecretToReference of this Jwt. -func (mg *Jwt) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { +// SetWriteConnectionSecretToReference of this Role. +func (mg *Role) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { mg.Spec.WriteConnectionSecretToReference = r } diff --git a/apis/auth/v1alpha1/zz_generated.managedlist.go b/apis/auth/v1alpha1/zz_generated.managedlist.go index db66ea8..76eddd2 100644 --- a/apis/auth/v1alpha1/zz_generated.managedlist.go +++ b/apis/auth/v1alpha1/zz_generated.managedlist.go @@ -19,8 +19,8 @@ package v1alpha1 import resource "github.com/crossplane/crossplane-runtime/pkg/resource" -// GetItems of this JwtList. -func (l *JwtList) GetItems() []resource.Managed { +// GetItems of this RoleList. +func (l *RoleList) GetItems() []resource.Managed { items := make([]resource.Managed, len(l.Items)) for i := range l.Items { items[i] = &l.Items[i] diff --git a/examples/auth/jwt_role.yaml b/examples/auth/jwt_role.yaml index 3fc9680..2c572de 100644 --- a/examples/auth/jwt_role.yaml +++ b/examples/auth/jwt_role.yaml @@ -1,5 +1,5 @@ apiVersion: auth.vault.crossplane.io/v1alpha1 -kind: Jwt +kind: Role metadata: name: test0 spec: diff --git a/internal/controller/jwt/jwt.go b/internal/controller/auth/role/role.go similarity index 92% rename from internal/controller/jwt/jwt.go rename to internal/controller/auth/role/role.go index 2548c03..7341545 100644 --- a/internal/controller/jwt/jwt.go +++ b/internal/controller/auth/role/role.go @@ -14,11 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package jwt +package role import ( "context" "encoding/json" + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "reflect" "strings" @@ -26,7 +27,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "github.com/crossplane/crossplane-runtime/pkg/connection" "github.com/crossplane/crossplane-runtime/pkg/controller" "github.com/crossplane/crossplane-runtime/pkg/event" @@ -34,7 +34,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" "github.com/crossplane/crossplane-runtime/pkg/resource" - "github.com/topfreegames/crossplane-provider-vault/apis/auth/v1alpha1" apisv1alpha1 "github.com/topfreegames/crossplane-provider-vault/apis/v1alpha1" "github.com/topfreegames/crossplane-provider-vault/internal/clients" @@ -42,7 +41,7 @@ import ( ) const ( - errNotJwt = "managed resource is not a Jwt custom resource" + errNotRole = "managed resource is not a AuthRole custom resource" errNewExternalClient = "cannot create vault client from config" errCreation = "cannot create JWT/OIDC role" @@ -66,7 +65,7 @@ var ( // Setup adds a controller that reconciles Jwt managed resources. func Setup(mgr ctrl.Manager, o controller.Options) error { - name := managed.ControllerName(v1alpha1.JwtGroupKind) + name := managed.ControllerName(v1alpha1.RoleGroupKind) cps := []managed.ConnectionPublisher{managed.NewAPISecretPublisher(mgr.GetClient(), mgr.GetScheme())} if o.Features.Enabled(features.EnableAlphaExternalSecretStores) { @@ -74,7 +73,7 @@ func Setup(mgr ctrl.Manager, o controller.Options) error { } r := managed.NewReconciler(mgr, - resource.ManagedKind(v1alpha1.JwtGroupVersionKind), + resource.ManagedKind(v1alpha1.RoleGroupVersionKind), managed.WithExternalConnecter(&connector{ kube: mgr.GetClient(), usage: resource.NewProviderConfigUsageTracker(mgr.GetClient(), &apisv1alpha1.ProviderConfigUsage{}), @@ -87,7 +86,7 @@ func Setup(mgr ctrl.Manager, o controller.Options) error { return ctrl.NewControllerManagedBy(mgr). Named(name). WithOptions(o.ForControllerRuntime()). - For(&v1alpha1.Jwt{}). + For(&v1alpha1.Role{}). Complete(ratelimiter.NewReconciler(name, r, o.GlobalRateLimiter)) } @@ -106,9 +105,9 @@ type connector struct { // 3. Getting the credentials specified by the ProviderConfig. // 4. Using the credentials to form a client. func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.ExternalClient, error) { - cr, ok := mg.(*v1alpha1.Jwt) + cr, ok := mg.(*v1alpha1.Role) if !ok { - return nil, errors.New(errNotJwt) + return nil, errors.New(errNotRole) } vaultClient, err := clients.NewVaultClient(ctx, c.kube, cr) @@ -133,9 +132,9 @@ type external struct { } func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.ExternalObservation, error) { - role, ok := mg.(*v1alpha1.Jwt) + role, ok := mg.(*v1alpha1.Role) if !ok { - return managed.ExternalObservation{}, errors.New(errNotJwt) + return managed.ExternalObservation{}, errors.New(errNotRole) } exists := false @@ -180,9 +179,9 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex } func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.ExternalCreation, error) { - role, ok := mg.(*v1alpha1.Jwt) + role, ok := mg.(*v1alpha1.Role) if !ok { - return managed.ExternalCreation{}, errors.New(errNotJwt) + return managed.ExternalCreation{}, errors.New(errNotRole) } r := fromCrossplane(role) @@ -208,9 +207,9 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext } func (c *external) Update(ctx context.Context, mg resource.Managed) (managed.ExternalUpdate, error) { - role, ok := mg.(*v1alpha1.Jwt) + role, ok := mg.(*v1alpha1.Role) if !ok { - return managed.ExternalUpdate{}, errors.New(errNotJwt) + return managed.ExternalUpdate{}, errors.New(errNotRole) } r := fromCrossplane(role) @@ -237,9 +236,9 @@ func (c *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext } func (c *external) Delete(ctx context.Context, mg resource.Managed) error { - role, ok := mg.(*v1alpha1.Jwt) + role, ok := mg.(*v1alpha1.Role) if !ok { - return errors.New(errNotJwt) + return errors.New(errNotRole) } path := jwtAuthBackendRolePath(*role.Spec.ForProvider.Backend, role.Name) diff --git a/internal/controller/jwt/jwt_test.go b/internal/controller/auth/role/role_test.go similarity index 97% rename from internal/controller/jwt/jwt_test.go rename to internal/controller/auth/role/role_test.go index 4aca4d9..db8fd5b 100644 --- a/internal/controller/jwt/jwt_test.go +++ b/internal/controller/auth/role/role_test.go @@ -14,18 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package jwt +package role import ( "context" - "testing" - xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" - "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" - "github.com/crossplane/crossplane-runtime/pkg/resource" - "github.com/crossplane/crossplane-runtime/pkg/test" "github.com/golang/mock/gomock" - "github.com/google/go-cmp/cmp" "github.com/hashicorp/vault/api" "github.com/pkg/errors" "github.com/topfreegames/crossplane-provider-vault/apis/auth/v1alpha1" @@ -33,6 +27,13 @@ import ( "github.com/topfreegames/crossplane-provider-vault/internal/clients/fake" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/pointer" + "testing" + + "github.com/google/go-cmp/cmp" + + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + "github.com/crossplane/crossplane-runtime/pkg/resource" + "github.com/crossplane/crossplane-runtime/pkg/test" ) // Unlike many Kubernetes projects Crossplane does not use third party testing @@ -496,20 +497,20 @@ func TestDelete(t *testing.T) { } } -func getTestRole() *v1alpha1.Jwt { - return &v1alpha1.Jwt{ +func getTestRole() *v1alpha1.Role { + return &v1alpha1.Role{ TypeMeta: metav1.TypeMeta{ - Kind: v1alpha1.JwtKind, - APIVersion: v1alpha1.JwtKindAPIVersion, + Kind: v1alpha1.RoleKind, + APIVersion: v1alpha1.RoleKindAPIVersion, }, ObjectMeta: metav1.ObjectMeta{ Name: "roleTest", }, - Spec: v1alpha1.JwtSpec{ + Spec: v1alpha1.RoleSpec{ ResourceSpec: xpv1.ResourceSpec{ DeletionPolicy: "Delete", }, - ForProvider: v1alpha1.JwtParameters{ + ForProvider: v1alpha1.RoleParameters{ Backend: pointer.String("gitlab"), RoleType: pointer.String("jwt"), BoundAudiences: []string{"test"}, @@ -518,20 +519,20 @@ func getTestRole() *v1alpha1.Jwt { } } -func getInvalidTestRole() *v1alpha1.Jwt { - return &v1alpha1.Jwt{ +func getInvalidTestRole() *v1alpha1.Role { + return &v1alpha1.Role{ TypeMeta: metav1.TypeMeta{ - Kind: v1alpha1.JwtKind, - APIVersion: v1alpha1.JwtKindAPIVersion, + Kind: v1alpha1.RoleKind, + APIVersion: v1alpha1.RoleKindAPIVersion, }, ObjectMeta: metav1.ObjectMeta{ Name: roleName, }, - Spec: v1alpha1.JwtSpec{ + Spec: v1alpha1.RoleSpec{ ResourceSpec: xpv1.ResourceSpec{ DeletionPolicy: "Delete", }, - ForProvider: v1alpha1.JwtParameters{ + ForProvider: v1alpha1.RoleParameters{ Backend: pointer.String("gitlab"), RoleType: pointer.String("jwt"), }, diff --git a/internal/controller/jwt/vault.go b/internal/controller/auth/role/vault.go similarity index 98% rename from internal/controller/jwt/vault.go rename to internal/controller/auth/role/vault.go index 5f63b28..c47e987 100644 --- a/internal/controller/jwt/vault.go +++ b/internal/controller/auth/role/vault.go @@ -1,4 +1,4 @@ -package jwt +package role import ( "encoding/json" @@ -79,7 +79,7 @@ func ternary[T any](exp bool, a T, b T) T { return b } -func fromCrossplane(crossplane *v1alpha1.Jwt) *Role { +func fromCrossplane(crossplane *v1alpha1.Role) *Role { d := crossplane.Spec.ForProvider r := &Role{ Name: crossplane.Name, diff --git a/internal/controller/vault.go b/internal/controller/vault.go index 373d1c2..a177c5e 100644 --- a/internal/controller/vault.go +++ b/internal/controller/vault.go @@ -20,8 +20,8 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/controller" ctrl "sigs.k8s.io/controller-runtime" + authRole "github.com/topfreegames/crossplane-provider-vault/internal/controller/auth/role" "github.com/topfreegames/crossplane-provider-vault/internal/controller/config" - "github.com/topfreegames/crossplane-provider-vault/internal/controller/jwt" "github.com/topfreegames/crossplane-provider-vault/internal/controller/policy" "github.com/topfreegames/crossplane-provider-vault/internal/controller/role" ) @@ -33,7 +33,7 @@ func Setup(mgr ctrl.Manager, o controller.Options) error { config.Setup, policy.Setup, role.Setup, - jwt.Setup, + authRole.Setup, } { if err := setup(mgr, o); err != nil { return err diff --git a/package/crds/auth.vault.crossplane.io_jwts.yaml b/package/crds/auth.vault.crossplane.io_roles.yaml similarity index 97% rename from package/crds/auth.vault.crossplane.io_jwts.yaml rename to package/crds/auth.vault.crossplane.io_roles.yaml index 73eb43f..cba0a4d 100644 --- a/package/crds/auth.vault.crossplane.io_jwts.yaml +++ b/package/crds/auth.vault.crossplane.io_roles.yaml @@ -5,7 +5,7 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.8.0 creationTimestamp: null - name: jwts.auth.vault.crossplane.io + name: roles.auth.vault.crossplane.io spec: group: auth.vault.crossplane.io names: @@ -13,10 +13,10 @@ spec: - crossplane - managed - vault - kind: Jwt - listKind: JwtList - plural: jwts - singular: jwt + kind: Role + listKind: RoleList + plural: roles + singular: role scope: Cluster versions: - additionalPrinterColumns: @@ -35,7 +35,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: A Jwt is an example API type. + description: A Role is an example API type. properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -50,7 +50,7 @@ spec: metadata: type: object spec: - description: A JwtSpec defines the desired state of a Jwt. + description: A RoleSpec defines the desired state of a Role. properties: deletionPolicy: default: Delete @@ -62,8 +62,7 @@ spec: - Delete type: string forProvider: - description: JwtParameters are the configurable fields of a Jwt Auth - Backend Role. + description: RoleParameters are the configurable fields of Auth Role properties: allowedRedirectURIs: description: The list of allowed values for redirect_uri during @@ -411,10 +410,10 @@ spec: - forProvider type: object status: - description: A JwtStatus represents the observed state of a Jwt. + description: A RoleStatus represents the observed state of a Role. properties: atProvider: - description: JwtObservation are the observable fields of a Jwt. + description: RoleObservation are the observable fields of a Role. properties: observableField: type: string From b823249c47878bb0599eaced02cf02db311db7b4 Mon Sep 17 00:00:00 2001 From: Yannick Stevenin Date: Fri, 4 Nov 2022 15:46:39 -0300 Subject: [PATCH 2/3] fix: linter --- apis/auth/v1alpha1/role_types.go | 3 +-- internal/controller/auth/role/role.go | 9 ++++----- internal/controller/role/role.go | 8 +++----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/apis/auth/v1alpha1/role_types.go b/apis/auth/v1alpha1/role_types.go index 9612798..89175a7 100644 --- a/apis/auth/v1alpha1/role_types.go +++ b/apis/auth/v1alpha1/role_types.go @@ -19,10 +19,9 @@ package v1alpha1 import ( "reflect" + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" - - xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" ) // RoleParameters are the configurable fields of Auth Role diff --git a/internal/controller/auth/role/role.go b/internal/controller/auth/role/role.go index 7341545..602d6c7 100644 --- a/internal/controller/auth/role/role.go +++ b/internal/controller/auth/role/role.go @@ -19,14 +19,10 @@ package role import ( "context" "encoding/json" - xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "reflect" "strings" - "github.com/pkg/errors" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" "github.com/crossplane/crossplane-runtime/pkg/connection" "github.com/crossplane/crossplane-runtime/pkg/controller" "github.com/crossplane/crossplane-runtime/pkg/event" @@ -34,10 +30,13 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" "github.com/crossplane/crossplane-runtime/pkg/resource" + "github.com/pkg/errors" "github.com/topfreegames/crossplane-provider-vault/apis/auth/v1alpha1" apisv1alpha1 "github.com/topfreegames/crossplane-provider-vault/apis/v1alpha1" "github.com/topfreegames/crossplane-provider-vault/internal/clients" "github.com/topfreegames/crossplane-provider-vault/internal/controller/features" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" ) const ( diff --git a/internal/controller/role/role.go b/internal/controller/role/role.go index 7116597..abbfd51 100644 --- a/internal/controller/role/role.go +++ b/internal/controller/role/role.go @@ -26,10 +26,6 @@ import ( "reflect" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" - "github.com/pkg/errors" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/crossplane/crossplane-runtime/pkg/connection" "github.com/crossplane/crossplane-runtime/pkg/controller" "github.com/crossplane/crossplane-runtime/pkg/event" @@ -37,11 +33,13 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" "github.com/crossplane/crossplane-runtime/pkg/resource" - + "github.com/pkg/errors" "github.com/topfreegames/crossplane-provider-vault/apis/aws/v1alpha1" apisv1alpha1 "github.com/topfreegames/crossplane-provider-vault/apis/v1alpha1" "github.com/topfreegames/crossplane-provider-vault/internal/clients" "github.com/topfreegames/crossplane-provider-vault/internal/controller/features" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" ) const ( From 6f50b82e6f58466ff1938a942c26b236ea0d94ea Mon Sep 17 00:00:00 2001 From: Yannick Stevenin Date: Fri, 4 Nov 2022 15:49:02 -0300 Subject: [PATCH 3/3] fix: import order --- CONTRIBUTING.md | 2 -- internal/controller/auth/role/role_test.go | 13 ++++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1370037..053f110 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,8 +5,6 @@ - [gomplate](https://docs.gomplate.ca/) - Docker -### TODO: Add missing steps (make submodules -> make generate -> make go.build ) - ### Adding new Kind to the controller - `GOMPLATE=gomplate KIND=your_kind GROUP=your_group PROVIDER=Vault hack/helpers/addtype.sh` - Define your resource spec under `apis//_types.go` diff --git a/internal/controller/auth/role/role_test.go b/internal/controller/auth/role/role_test.go index db8fd5b..edfb643 100644 --- a/internal/controller/auth/role/role_test.go +++ b/internal/controller/auth/role/role_test.go @@ -18,8 +18,14 @@ package role import ( "context" + "testing" + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" + "github.com/crossplane/crossplane-runtime/pkg/resource" + "github.com/crossplane/crossplane-runtime/pkg/test" "github.com/golang/mock/gomock" + "github.com/google/go-cmp/cmp" "github.com/hashicorp/vault/api" "github.com/pkg/errors" "github.com/topfreegames/crossplane-provider-vault/apis/auth/v1alpha1" @@ -27,13 +33,6 @@ import ( "github.com/topfreegames/crossplane-provider-vault/internal/clients/fake" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/pointer" - "testing" - - "github.com/google/go-cmp/cmp" - - "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" - "github.com/crossplane/crossplane-runtime/pkg/resource" - "github.com/crossplane/crossplane-runtime/pkg/test" ) // Unlike many Kubernetes projects Crossplane does not use third party testing