Skip to content

Commit

Permalink
add minio server's api call to set user's password
Browse files Browse the repository at this point in the history
it's important feature as we had a bug where password was lost/broken
for some reason and caused operational issues in our cluster.
  • Loading branch information
[email protected] committed Jul 15, 2024
1 parent 2e83541 commit 0b53aae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions operator/user/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type connector struct {

type userClient struct {
ma *madmin.AdminClient
kube client.Client
recorder event.Recorder
}

Expand Down Expand Up @@ -56,6 +57,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E

uc := &userClient{
ma: ma,
kube: c.kube,
recorder: c.recorder,
}

Expand Down
24 changes: 24 additions & 0 deletions operator/user/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/minio/madmin-go/v3"
miniov1 "github.com/vshn/provider-minio/apis/minio/v1"
k8svi "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)

const (
Expand Down Expand Up @@ -59,6 +61,28 @@ func (u *userClient) Observe(ctx context.Context, mg resource.Managed) (managed.
user.SetConditions(miniov1.Disabled())
}

if mg.GetDeletionTimestamp() == nil {

secret := k8svi.Secret{}

err = u.kube.Get(ctx, types.NamespacedName{
Namespace: mg.GetWriteConnectionSecretToReference().Namespace,
Name: mg.GetWriteConnectionSecretToReference().Name,
}, &secret)
if err != nil {
return managed.ExternalObservation{}, err
}

// this here prevents painful user errors with password generation using bash shell and `echo`
// if You want to use `echo` to generate a password, use `echo -n` to prevent adding a newline
strippedFromNewline := strings.ReplaceAll(string(secret.Data[AccessKeyName]), "\n", "")

err = u.ma.SetUser(ctx, string(secret.Data[AccessKeyName]), strippedFromNewline, madmin.AccountEnabled)
if err != nil {
return managed.ExternalObservation{}, err
}
}

return managed.ExternalObservation{ResourceExists: true, ResourceUpToDate: true}, nil
}

Expand Down

0 comments on commit 0b53aae

Please sign in to comment.