Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ require (
github.com/go-openapi/validate v0.19.10
github.com/gorilla/websocket v1.4.2
github.com/jessevdk/go-flags v1.4.0
github.com/json-iterator/go v1.1.9
github.com/json-iterator/go v1.1.10
github.com/minio/cli v1.22.0
github.com/minio/mc v0.0.0-20200515235434-3b479cf92ed6
github.com/minio/minio v0.0.0-20200603201854-5686a7e27319
github.com/minio/minio-go/v6 v6.0.56
github.com/minio/minio-operator v0.0.0-20200520220606-60eca6e7beab
github.com/minio/mc v0.0.0-20200719194630-c8a3b7bff08c
github.com/minio/minio v0.0.0-20200714163805-778e9c864f67
github.com/minio/minio-go/v6 v6.0.58-0.20200612001654-a57fec8037ec
github.com/minio/minio-go/v7 v7.0.2-0.20200718235721-f0e2f3ae3678
github.com/minio/minio-operator v0.0.0-20200713191021-de7c5283f7e5
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.6.1
github.com/unrolled/secure v1.0.7
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
k8s.io/api v0.18.0
k8s.io/apimachinery v0.18.0
Expand Down
193 changes: 132 additions & 61 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion k8s/console/base/minio-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ spec:
serviceAccountName: minio-operator
containers:
- name: minio-operator
image: minio/k8s-operator:2.0.8
image: minio/k8s-operator:2.0.9
imagePullPolicy: IfNotPresent
# To specify cluster domain, un comment the following:
# env:
Expand Down
2 changes: 1 addition & 1 deletion k8s/getoperator.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
# Get's the latest deployment file from MinIO Operator
curl https://raw.githubusercontent.com/minio/minio-operator/master/minio-operator.yaml > base/minio-operator.yaml
curl https://raw.githubusercontent.com/minio/minio-operator/master/minio-operator.yaml > operator-console/base/minio-operator.yaml
2 changes: 1 addition & 1 deletion k8s/operator-console/base/minio-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ spec:
serviceAccountName: minio-operator
containers:
- name: minio-operator
image: minio/k8s-operator:2.0.8
image: minio/k8s-operator:2.0.9
imagePullPolicy: IfNotPresent
# To specify cluster domain, un comment the following:
# env:
Expand Down
6 changes: 3 additions & 3 deletions restapi/admin_tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func getDeleteTenantResponse(session *models.Principal, params admin_api.DeleteT
return deleteTenantAction(context.Background(), opClient, params.Namespace, params.Tenant)
}

func identifyMinioInstanceScheme(mi *operator.MinIOInstance) string {
func getMinioInstanceScheme(mi *operator.MinIOInstance) string {
scheme := "http"
if mi.RequiresAutoCertSetup() || mi.RequiresExternalCertSetup() {
if mi.AutoCert() || mi.ExternalCert() {
scheme = "https"
}
return scheme
Expand Down Expand Up @@ -239,7 +239,7 @@ func getTenantInfoResponse(session *models.Principal, params admin_api.TenantInf
log.Println("error getting minioInstance:", err)
return nil, err
}
minioInstanceScheme := identifyMinioInstanceScheme(minInst)
minioInstanceScheme := getMinioInstanceScheme(minInst)
mAdmin, err := getTenantAdminClient(ctx, k8sClient, params.Namespace, params.Tenant, minInst.Spec.ServiceName, minioInstanceScheme)
if err != nil {
log.Println("error getting tenant's admin client:", err)
Expand Down
2 changes: 1 addition & 1 deletion restapi/client-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
mcCmd "github.com/minio/mc/cmd"
"github.com/minio/mc/pkg/probe"
"github.com/minio/mcs/models"
"github.com/minio/minio-go/v6/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/credentials"
mauth "github.com/minio/minio/pkg/auth"
iampolicy "github.com/minio/minio/pkg/iam/policy"
"github.com/minio/minio/pkg/madmin"
Expand Down
18 changes: 9 additions & 9 deletions restapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func (c minioClient) getBucketPolicy(bucketName string) (string, error) {
// by mock when testing, it should include all mc/S3Client respective api calls
// that are used within this project.
type MCS3Client interface {
addNotificationConfig(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error
removeNotificationConfig(arn string, event string, prefix string, suffix string) *probe.Error
watch(options mc.WatchOptions) (*mc.WatchObject, *probe.Error)
addNotificationConfig(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error
removeNotificationConfig(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error
watch(ctx context.Context, options mc.WatchOptions) (*mc.WatchObject, *probe.Error)
}

// Interface implementation
Expand All @@ -108,17 +108,17 @@ type mcS3Client struct {
}

// implements S3Client.AddNotificationConfig()
func (c mcS3Client) addNotificationConfig(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
return c.client.AddNotificationConfig(arn, events, prefix, suffix, ignoreExisting)
func (c mcS3Client) addNotificationConfig(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
return c.client.AddNotificationConfig(ctx, arn, events, prefix, suffix, ignoreExisting)
}

// implements S3Client.RemoveNotificationConfig()
func (c mcS3Client) removeNotificationConfig(arn string, event string, prefix string, suffix string) *probe.Error {
return c.client.RemoveNotificationConfig(arn, event, prefix, suffix)
func (c mcS3Client) removeNotificationConfig(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error {
return c.client.RemoveNotificationConfig(ctx, arn, event, prefix, suffix)
}

func (c mcS3Client) watch(options mc.WatchOptions) (*mc.WatchObject, *probe.Error) {
return c.client.Watch(options)
func (c mcS3Client) watch(ctx context.Context, options mc.WatchOptions) (*mc.WatchObject, *probe.Error) {
return c.client.Watch(ctx, options)
}

// MCSCredentials interface with all functions to be implemented
Expand Down
15 changes: 9 additions & 6 deletions restapi/user_buckets_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package restapi

import (
"context"
"log"
"strings"

Expand Down Expand Up @@ -152,7 +153,7 @@ func getListBucketEventsResponse(session *models.Principal, params user_api.List
// If notificationEvents is empty, by default will set [get, put, delete], else the provided
// ones will be set.
// this function follows same behavior as minio/mc for adding a bucket event
func createBucketEvent(client MCS3Client, arn string, notificationEvents []models.NotificationEventType, prefix, suffix string, ignoreExisting bool) error {
func createBucketEvent(ctx context.Context, client MCS3Client, arn string, notificationEvents []models.NotificationEventType, prefix, suffix string, ignoreExisting bool) error {
var events []string
if len(notificationEvents) == 0 {
// default event values are [get, put, delete]
Expand All @@ -169,7 +170,7 @@ func createBucketEvent(client MCS3Client, arn string, notificationEvents []model
}
}

perr := client.addNotificationConfig(arn, events, prefix, suffix, ignoreExisting)
perr := client.addNotificationConfig(ctx, arn, events, prefix, suffix, ignoreExisting)
if perr != nil {
return perr.Cause
}
Expand All @@ -178,6 +179,7 @@ func createBucketEvent(client MCS3Client, arn string, notificationEvents []model

// getCreateBucketEventsResponse calls createBucketEvent to add a bucket event notification
func getCreateBucketEventsResponse(session *models.Principal, bucketName string, eventReq *models.BucketEventRequest) error {
ctx := context.Background()
s3Client, err := newS3BucketClient(session, bucketName)
if err != nil {
log.Println("error creating S3Client:", err)
Expand All @@ -186,7 +188,7 @@ func getCreateBucketEventsResponse(session *models.Principal, bucketName string,
// create a mc S3Client interface implementation
// defining the client to be used
mcS3Client := mcS3Client{client: s3Client}
err = createBucketEvent(mcS3Client, *eventReq.Configuration.Arn, eventReq.Configuration.Events, eventReq.Configuration.Prefix, eventReq.Configuration.Suffix, eventReq.IgnoreExisting)
err = createBucketEvent(ctx, mcS3Client, *eventReq.Configuration.Arn, eventReq.Configuration.Events, eventReq.Configuration.Prefix, eventReq.Configuration.Suffix, eventReq.IgnoreExisting)
if err != nil {
log.Println("error creating bucket event:", err)
return err
Expand All @@ -195,9 +197,9 @@ func getCreateBucketEventsResponse(session *models.Principal, bucketName string,
}

// deleteBucketEventNotification calls S3Client.RemoveNotificationConfig to remove a bucket event notification
func deleteBucketEventNotification(client MCS3Client, arn string, events []models.NotificationEventType, prefix, suffix *string) error {
func deleteBucketEventNotification(ctx context.Context, client MCS3Client, arn string, events []models.NotificationEventType, prefix, suffix *string) error {
eventSingleString := joinNotificationEvents(events)
perr := client.removeNotificationConfig(arn, eventSingleString, *prefix, *suffix)
perr := client.removeNotificationConfig(ctx, arn, eventSingleString, *prefix, *suffix)
if perr != nil {
return perr.Cause
}
Expand All @@ -214,6 +216,7 @@ func joinNotificationEvents(events []models.NotificationEventType) string {

// getDeleteBucketEventsResponse calls deleteBucketEventNotification() to delete a bucket event notification
func getDeleteBucketEventsResponse(session *models.Principal, bucketName string, arn string, events []models.NotificationEventType, prefix, suffix *string) error {
ctx := context.Background()
s3Client, err := newS3BucketClient(session, bucketName)
if err != nil {
log.Println("error creating S3Client:", err)
Expand All @@ -222,7 +225,7 @@ func getDeleteBucketEventsResponse(session *models.Principal, bucketName string,
// create a mc S3Client interface implementation
// defining the client to be used
mcS3Client := mcS3Client{client: s3Client}
err = deleteBucketEventNotification(mcS3Client, arn, events, prefix, suffix)
err = deleteBucketEventNotification(ctx, mcS3Client, arn, events, prefix, suffix)
if err != nil {
log.Println("error deleting bucket event:", err)
return err
Expand Down
35 changes: 19 additions & 16 deletions restapi/user_buckets_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package restapi

import (
"context"
"fmt"
"testing"

Expand All @@ -38,26 +39,27 @@ func (mc minioClientMock) getBucketNotification(bucketName string) (bucketNotifi
}

//// Mock mc S3Client functions ////
var mcAddNotificationConfigMock func(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error
var mcRemoveNotificationConfigMock func(arn string, event string, prefix string, suffix string) *probe.Error
var mcAddNotificationConfigMock func(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error
var mcRemoveNotificationConfigMock func(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error

// Define a mock struct of mc S3Client interface implementation
type s3ClientMock struct {
}

// implements mc.S3Client.AddNotificationConfigMock()
func (c s3ClientMock) addNotificationConfig(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
return mcAddNotificationConfigMock(arn, events, prefix, suffix, ignoreExisting)
func (c s3ClientMock) addNotificationConfig(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
return mcAddNotificationConfigMock(ctx, arn, events, prefix, suffix, ignoreExisting)
}

// implements mc.S3Client.DeleteBucketEventNotification()
func (c s3ClientMock) removeNotificationConfig(arn string, event string, prefix string, suffix string) *probe.Error {
return mcRemoveNotificationConfigMock(arn, event, prefix, suffix)
func (c s3ClientMock) removeNotificationConfig(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error {
return mcRemoveNotificationConfigMock(ctx, arn, event, prefix, suffix)
}

func TestAddBucketNotification(t *testing.T) {
assert := assert.New(t)
// mock minIO client
ctx := context.Background()
client := s3ClientMock{}
function := "createBucketEvent()"
// Test-1: createBucketEvent() set an event with empty parameters and events, should set default values with no error
Expand All @@ -66,10 +68,10 @@ func TestAddBucketNotification(t *testing.T) {
testPrefix := ""
testSuffix := ""
testIgnoreExisting := false
mcAddNotificationConfigMock = func(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
mcAddNotificationConfigMock = func(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
return nil
}
if err := createBucketEvent(client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); err != nil {
if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); err != nil {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}

Expand All @@ -82,23 +84,24 @@ func TestAddBucketNotification(t *testing.T) {
testPrefix = "photos/"
testSuffix = ".jpg"
testIgnoreExisting = true
mcAddNotificationConfigMock = func(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
mcAddNotificationConfigMock = func(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
return nil
}
if err := createBucketEvent(client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); err != nil {
if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); err != nil {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}

// Test-3 createBucketEvent() S3Client.AddNotificationConfig returns an error and is handled correctly
mcAddNotificationConfigMock = func(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
mcAddNotificationConfigMock = func(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
return probe.NewError(errors.New("error"))
}
if err := createBucketEvent(client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); assert.Error(err) {
if err := createBucketEvent(ctx, client, testArn, testNotificationEvents, testPrefix, testSuffix, testIgnoreExisting); assert.Error(err) {
assert.Equal("error", err.Error())
}
}

func TestDeleteBucketNotification(t *testing.T) {
ctx := context.Background()
assert := assert.New(t)
// mock minIO client
client := s3ClientMock{}
Expand All @@ -112,18 +115,18 @@ func TestDeleteBucketNotification(t *testing.T) {
models.NotificationEventTypePut}
prefix := "/photos"
suffix := ".jpg"
mcRemoveNotificationConfigMock = func(arn string, event string, prefix string, suffix string) *probe.Error {
mcRemoveNotificationConfigMock = func(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error {
return nil
}
if err := deleteBucketEventNotification(client, testArn, events, swag.String(prefix), swag.String(suffix)); err != nil {
if err := deleteBucketEventNotification(ctx, client, testArn, events, swag.String(prefix), swag.String(suffix)); err != nil {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}

// Test-2 deleteBucketEventNotification() S3Client.DeleteBucketEventNotification returns an error and is handled correctly
mcRemoveNotificationConfigMock = func(arn string, event string, prefix string, suffix string) *probe.Error {
mcRemoveNotificationConfigMock = func(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error {
return probe.NewError(errors.New("error"))
}
if err := deleteBucketEventNotification(client, testArn, events, swag.String(prefix), swag.String(suffix)); assert.Error(err) {
if err := deleteBucketEventNotification(ctx, client, testArn, events, swag.String(prefix), swag.String(suffix)); assert.Error(err) {
assert.Equal("error", err.Error())
}

Expand Down
2 changes: 1 addition & 1 deletion restapi/user_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type watchOptions struct {
}

func startWatch(ctx context.Context, conn WSConn, wsc MCS3Client, options watchOptions) error {
wo, pErr := wsc.watch(options.WatchOptions)
wo, pErr := wsc.watch(ctx, options.WatchOptions)
if pErr != nil {
fmt.Println("error initializing watch:", pErr.Cause)
return pErr.Cause
Expand Down
Loading