Skip to content

Commit

Permalink
Promote ManagementPolicies to beta
Browse files Browse the repository at this point in the history
Signed-off-by: Cyrill Näf <[email protected]>
  • Loading branch information
BigGold1310 committed Dec 10, 2024
1 parent c33c853 commit fbc4c39
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 51 deletions.
4 changes: 2 additions & 2 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func main() {
}

if *enableManagementPolicies {
o.Features.Enable(features.EnableAlphaManagementPolicies)
log.Info("Alpha feature enabled", "flag", features.EnableAlphaManagementPolicies)
o.Features.Enable(feature.EnableBetaManagementPolicies)
log.Info("Beta feature enabled", "flag", feature.EnableBetaManagementPolicies)
}

kingpin.FatalIfError(controller.Setup(mgr, o), "Cannot setup Gitlab controllers")
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/groups/accesstokens/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
Expand Down Expand Up @@ -72,7 +73,7 @@ func SetupAccessToken(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -168,7 +169,6 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
groups.GenerateCreateGroupAccessTokenOptions(cr.Name, &cr.Spec.ForProvider),
gitlab.WithContext(ctx),
)

if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, errCreateFailed)
}
Expand All @@ -193,7 +193,6 @@ func (e *external) Delete(ctx context.Context, mg resource.Managed) (managed.Ext
}

accessTokenID, err := strconv.Atoi(meta.GetExternalName(cr))

if err != nil {
return managed.ExternalDelete{}, errors.New(errExternalNameNotInt)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/groups/deploytokens/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
Expand Down Expand Up @@ -69,7 +70,7 @@ func SetupDeployToken(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -190,7 +191,6 @@ func (e *external) Delete(ctx context.Context, mg resource.Managed) (managed.Ext
}

deployTokenID, err := strconv.Atoi(meta.GetExternalName(cr))

if err != nil {
return managed.ExternalDelete{}, errors.New(errNotDeployToken)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/groups/groups/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
Expand Down Expand Up @@ -76,7 +77,7 @@ func SetupGroup(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/groups/members/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/crossplane-runtime/pkg/statemetrics"
Expand Down Expand Up @@ -62,15 +63,16 @@ func SetupMember(mgr ctrl.Manager, o controller.Options) error {
managed.WithExternalConnecter(&connector{
kube: mgr.GetClient(),
newGitlabClientFn: groups.NewMemberClient,
newUserClientFn: users.NewUserClient}),
newUserClientFn: users.NewUserClient,
}),
managed.WithInitializers(),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -231,7 +233,6 @@ func (e *external) Disconnect(ctx context.Context) error {

// isMemberUpToDate checks whether there is a change in any of the modifiable fields.
func isMemberUpToDate(p *v1alpha1.MemberParameters, g *gitlab.GroupMember) bool {

if !cmp.Equal(int(p.AccessLevel), int(g.AccessLevel)) {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/groups/samlgrouplinks/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
Expand Down Expand Up @@ -67,7 +68,7 @@ func SetupSamlGroupLink(mgr ctrl.Manager, o controller.Options) error {
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
}
if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -126,7 +127,6 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
}

groupLink, _, err := e.client.GetGroupSAMLLink(*cr.Spec.ForProvider.GroupID, samlGroupName)

if err != nil {
return managed.ExternalObservation{}, errors.Wrap(resource.Ignore(groups.IsErrorSamlGroupLinkNotFound, err), errGetFailed)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/groups/variables/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/errors"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/crossplane-runtime/pkg/statemetrics"
Expand Down Expand Up @@ -70,7 +71,7 @@ func SetupVariable(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -124,7 +125,6 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
*cr.Spec.ForProvider.GroupID,
cr.Spec.ForProvider.Key,
gitlab.WithContext(ctx))

if err != nil {
if clients.IsResponseNotFound(res) {
return managed.ExternalObservation{}, nil
Expand Down Expand Up @@ -170,7 +170,6 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
*cr.Spec.ForProvider.GroupID,
groups.GenerateCreateVariableOptions(&cr.Spec.ForProvider),
gitlab.WithContext(ctx))

if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, errCreateFailed)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/projects/accesstokens/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
Expand Down Expand Up @@ -72,7 +73,7 @@ func SetupAccessToken(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -168,7 +169,6 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
projects.GenerateCreateProjectAccessTokenOptions(cr.Name, &cr.Spec.ForProvider),
gitlab.WithContext(ctx),
)

if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, errCreateFailed)
}
Expand All @@ -193,7 +193,6 @@ func (e *external) Delete(ctx context.Context, mg resource.Managed) (managed.Ext
}

accessTokenID, err := strconv.Atoi(meta.GetExternalName(cr))

if err != nil {
return managed.ExternalDelete{}, errors.New(errExternalNameNotInt)
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/controller/projects/deploykeys/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
crpc "github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
Expand Down Expand Up @@ -68,7 +69,7 @@ func SetupDeployKey(mgr ctrl.Manager, o crpc.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand All @@ -95,7 +96,6 @@ func (c *connector) Connect(ctx context.Context, mgd resource.Managed) (managed.
}

config, err := clients.GetConfig(ctx, c.kube, cr)

if err != nil {
return nil, err
}
Expand All @@ -115,7 +115,6 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
}

id, err := strconv.Atoi(meta.GetExternalName(cr))

if err != nil {
return managed.ExternalObservation{}, errors.New(errIDNotAnInt)
}
Expand All @@ -124,7 +123,6 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
*cr.Spec.ForProvider.ProjectID,
id,
)

if err != nil {
if clients.IsResponseNotFound(res) {
return managed.ExternalObservation{}, nil
Expand Down Expand Up @@ -171,7 +169,6 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext

secret := &corev1.Secret{}
err := e.kube.Get(ctx, namespacedName, secret)

if err != nil {
return managed.ExternalCreation{},
errors.Wrap(err, errKeyMissing)
Expand All @@ -182,7 +179,6 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
generateCreateOptions(string(secret.Data[keySecretRef.Key]), &cr.Spec.ForProvider),
gitlab.WithContext(ctx),
)

if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, errCreateFail)
}
Expand All @@ -206,7 +202,6 @@ func (e *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext

idString := meta.GetExternalName(cr)
id, err := strconv.Atoi(idString)

if err != nil {
return managed.ExternalUpdate{}, errors.Wrap(err, errIDNotAnInt)
}
Expand All @@ -233,7 +228,6 @@ func (e *external) Delete(ctx context.Context, mg resource.Managed) (managed.Ext

keyIDString := meta.GetExternalName(cr)
keyID, err := strconv.Atoi(keyIDString)

if err != nil {
return managed.ExternalDelete{}, errors.Wrap(err, errIDNotAnInt)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/projects/deploytokens/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
Expand Down Expand Up @@ -69,7 +70,7 @@ func SetupDeployToken(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -131,7 +132,6 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
}

dt, res, err := e.client.GetProjectDeployToken(*cr.Spec.ForProvider.ProjectID, id)

if err != nil {
if clients.IsResponseNotFound(res) {
return managed.ExternalObservation{}, nil
Expand Down Expand Up @@ -166,7 +166,6 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
projects.GenerateCreateProjectDeployTokenOptions(cr.Name, &cr.Spec.ForProvider),
gitlab.WithContext(ctx),
)

if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, errCreateFailed)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/controller/projects/hooks/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
Expand Down Expand Up @@ -70,7 +71,7 @@ func SetupHook(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -160,13 +161,11 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext

cr.Status.SetConditions(xpv1.Creating())
hookOptions, err := projects.GenerateCreateHookOptions(&cr.Spec.ForProvider, e.kube, ctx)

if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, errSecretRefInvalid)
}

hook, _, err := e.client.AddProjectHook(*cr.Spec.ForProvider.ProjectID, hookOptions, gitlab.WithContext(ctx))

if err != nil {
return managed.ExternalCreation{}, errors.Wrap(err, errCreateFailed)
}
Expand All @@ -190,7 +189,6 @@ func (e *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext
}

editHookOptions, err := projects.GenerateEditHookOptions(&cr.Spec.ForProvider, e.kube, ctx)

if err != nil {
return managed.ExternalUpdate{}, errors.New(errSecretRefInvalid)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/projects/members/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/crossplane/crossplane-runtime/pkg/feature"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/crossplane-runtime/pkg/statemetrics"
Expand Down Expand Up @@ -70,7 +71,7 @@ func SetupMember(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...),
}

if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
if o.Features.Enabled(feature.EnableBetaManagementPolicies) {
reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
}

Expand Down Expand Up @@ -138,7 +139,6 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
*cr.Spec.ForProvider.ProjectID,
*cr.Spec.ForProvider.UserID,
)

if err != nil {
if clients.IsResponseNotFound(res) {
return managed.ExternalObservation{}, nil
Expand Down
Loading

0 comments on commit fbc4c39

Please sign in to comment.