-
Notifications
You must be signed in to change notification settings - Fork 126
CSPL-821 Implement Init Container Image #350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
smohan-splunk
merged 1 commit into
feature-appframework
from
feature/CSPL-821-app_initContainer
May 28, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/minio/minio-go/v7" | ||
| "github.com/minio/minio-go/v7/pkg/credentials" | ||
| ) | ||
|
|
||
| // blank assignment to verify that MinioClient implements S3Client | ||
| var _ S3Client = &MinioClient{} | ||
|
|
||
| // MinioClient is a client to implement S3 specific APIs | ||
| type MinioClient struct { | ||
| BucketName string | ||
| S3AccessKeyID string | ||
| S3SecretAccessKey string | ||
| Prefix string | ||
| StartAfter string | ||
| Endpoint string | ||
| } | ||
|
|
||
| // NewMinioClient returns an Minio client | ||
| func NewMinioClient(bucketName string, accessKeyID string, secretAccessKey string, prefix string, startAfter string, endpoint string) S3Client { | ||
| return &MinioClient{ | ||
| BucketName: bucketName, | ||
| S3AccessKeyID: accessKeyID, | ||
| S3SecretAccessKey: secretAccessKey, | ||
| Prefix: prefix, | ||
| StartAfter: startAfter, | ||
| Endpoint: endpoint, | ||
| } | ||
| } | ||
|
|
||
| //RegisterMinioClient will add the corresponding function pointer to the map | ||
| func RegisterMinioClient() { | ||
| S3Clients["minio"] = NewMinioClient | ||
| } | ||
|
|
||
| // InitMinioClientSession initializes and returns a client session object | ||
| func InitMinioClientSession(appS3Endpoint string, accessKeyID string, secretAccessKey string, isNotInTestContext *bool) (*minio.Client, error) { | ||
| scopedLog := log.WithName("InitMinioClientSession") | ||
| *isNotInTestContext = true | ||
|
|
||
| // Check if SSL is needed | ||
| useSSL := true | ||
| if strings.HasPrefix(appS3Endpoint, "http://") { | ||
| useSSL = false | ||
| appS3Endpoint = strings.TrimPrefix(appS3Endpoint, "http://") | ||
| } else if strings.HasPrefix(appS3Endpoint, "https://") { | ||
| appS3Endpoint = strings.TrimPrefix(appS3Endpoint, "https://") | ||
| } else { | ||
| // Unsupported endpoint | ||
| scopedLog.Info("Unsupported endpoint for Minio S3 client", "appS3Endpoint", appS3Endpoint) | ||
| return nil, nil | ||
| } | ||
|
|
||
| // New returns an Minio compatible client object. API compatibility (v2 or v4) is automatically | ||
| // determined based on the Endpoint value. | ||
| scopedLog.Info("Connecting to Minio S3 for apps", "appS3Endpoint", appS3Endpoint) | ||
| s3Client, err := minio.New(appS3Endpoint, &minio.Options{ | ||
jryb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), | ||
| Secure: useSSL, | ||
| }) | ||
| if err != nil { | ||
| scopedLog.Info("Error creating new Minio Client Session", "err", err) | ||
| } | ||
|
|
||
| return s3Client, err | ||
| } | ||
|
|
||
| // GetAppsList get the list of apps from remote storage | ||
| func (client *MinioClient) GetAppsList() (S3Response, error) { | ||
| scopedLog := log.WithName("GetAppsList") | ||
|
|
||
| scopedLog.Info("Getting Apps list", " S3 Bucket", client.BucketName) | ||
| s3Resp := S3Response{} | ||
| appS3Endpoint := client.Endpoint | ||
|
|
||
| isNotInTestContext := true | ||
| s3Client, err := InitMinioClientSession(appS3Endpoint, client.S3AccessKeyID, client.S3SecretAccessKey, &isNotInTestContext) | ||
| if err != nil { | ||
| scopedLog.Info("Error creating new Minio Client Session", "err", err) | ||
| return s3Resp, err | ||
| } | ||
|
|
||
| // Create a bucket list command for all files in bucket | ||
| opts := minio.ListObjectsOptions{ | ||
| UseV1: true, | ||
gaurav-splunk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Prefix: client.Prefix, | ||
| Recursive: false, | ||
gaurav-splunk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // List all objects from a bucket-name with a matching prefix. | ||
| for object := range s3Client.ListObjects(context.Background(), client.BucketName, opts) { | ||
| if object.Err != nil { | ||
| scopedLog.Info("Got an object error", "object.Err", object.Err, "client.BucketName", client.BucketName) | ||
| return s3Resp, nil | ||
| } | ||
| scopedLog.Info("Got an object", "object", object) | ||
| s3Resp.Objects = append(s3Resp.Objects, &RemoteObject{Etag: &object.ETag, Key: &object.Key, LastModified: &object.LastModified, Size: &object.Size, StorageClass: &object.StorageClass}) | ||
| } | ||
|
|
||
| return s3Resp, nil | ||
| } | ||
|
|
||
| // GetInitContainerImage returns the initContainer image to be used with this s3 client | ||
| func (client *MinioClient) GetInitContainerImage() string { | ||
| return ("amazon/aws-cli") | ||
| } | ||
|
|
||
| // GetInitContainerCmd returns the init container command on a per app source basis to be used by the initContainer | ||
| func (client *MinioClient) GetInitContainerCmd(endpoint string, bucket string, path string, appSrcName string, appMnt string) []string { | ||
| return ([]string{fmt.Sprintf("--endpoint-url=%s", endpoint), "s3", "sync", fmt.Sprintf("s3://%s/%s", bucket, path), fmt.Sprintf("%s/%s", appMnt, appSrcName)}) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.