-
Notifications
You must be signed in to change notification settings - Fork 554
feat: upload and download logs/artifact from blob storage configured in external cluster #4138
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
Merged
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
72d3c3e
blob storage cm secret inducing internally and removed AWS creds set …
prakash100198 7db0738
some refactoring and UseExternalClusterBlob flag introduced in cicdco…
prakash100198 a23d3e8
added support fr fetching logs and artifacts from external cluster bl…
prakash100198 70cf43a
wire
prakash100198 45a614f
main sync
prakash100198 06ccbd1
minor fix
prakash100198 0915bd2
import fix
prakash100198 92557ad
code refactoring
prakash100198 bc249fd
info comment
prakash100198 cb174cb
fix
prakash100198 1da47a8
comments added
prakash100198 74165a8
comments fix
prakash100198 8ef0a28
decodeSecretKey
prakash100198 24152a1
code review oncorporation l1
prakash100198 c4dc66e
code review incorporation l2
prakash100198 d8ccf8b
Merge branch 'main' into ext-cluster-blob-issue
prakash100198 430c93f
code review incorporation l3
prakash100198 5f68d00
code review incorporation l4
prakash100198 23f2bbb
code review incorporation l5
prakash100198 734cc55
code review incorporation l6
prakash100198 e89a556
main branch sync
prakash100198 bd3e83d
minor fix for job tyoe
prakash100198 c616e88
minor fix
prakash100198 e25d2fc
code review incorporation
prakash100198 67cdff2
code review incorporation
prakash100198 7f82b16
code review incorporation
prakash100198 9ea6b38
Merge branch 'main' into ext-cluster-blob-issue
prakash100198 2bf4838
minor fix after debugging error
prakash100198 69f550e
main code sync
prakash100198 b5c05e4
common lib version upgrade from 0.0.3 to 0.0.4
prakash100198 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
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,107 @@ | ||
| package pipeline | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/base64" | ||
| "fmt" | ||
| blob_storage "github.com/devtron-labs/common-lib/blob-storage" | ||
| "github.com/devtron-labs/common-lib/utils/k8s" | ||
| bean2 "github.com/devtron-labs/devtron/pkg/pipeline/bean" | ||
| "go.uber.org/zap" | ||
| v12 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "strconv" | ||
| ) | ||
|
|
||
| type BlobStorageConfigService interface { | ||
| FetchCmAndSecretBlobConfigFromExternalCluster(clusterConfig *k8s.ClusterConfig, namespace string) (*bean2.CmBlobStorageConfig, *bean2.SecretBlobStorageConfig, error) | ||
| } | ||
| type BlobStorageConfigServiceImpl struct { | ||
| Logger *zap.SugaredLogger | ||
| k8sUtil *k8s.K8sUtil | ||
| ciCdConfig *CiCdConfig | ||
| } | ||
|
|
||
| func NewBlobStorageConfigServiceImpl(Logger *zap.SugaredLogger, k8sUtil *k8s.K8sUtil, ciCdConfig *CiCdConfig) *BlobStorageConfigServiceImpl { | ||
| return &BlobStorageConfigServiceImpl{ | ||
| Logger: Logger, | ||
| k8sUtil: k8sUtil, | ||
| ciCdConfig: ciCdConfig, | ||
| } | ||
| } | ||
|
|
||
| func (impl *BlobStorageConfigServiceImpl) FetchCmAndSecretBlobConfigFromExternalCluster(clusterConfig *k8s.ClusterConfig, namespace string) (*bean2.CmBlobStorageConfig, *bean2.SecretBlobStorageConfig, error) { | ||
| cmConfig := &bean2.CmBlobStorageConfig{} | ||
| secretConfig := &bean2.SecretBlobStorageConfig{} | ||
| _, _, kubeClient, err := impl.k8sUtil.GetK8sConfigAndClients(&k8s.ClusterConfig{}) | ||
| if err != nil { | ||
| impl.Logger.Errorw("FetchCmAndSecretBlobConfigFromExternalCluster, error in getting kubeClient by cluster config", "err", err) | ||
| return cmConfig, secretConfig, err | ||
| } | ||
| cv1 := kubeClient.CoreV1() | ||
| ctx := context.Background() | ||
| opts := v12.GetOptions{} | ||
| cmName := impl.ciCdConfig.ExtBlobStorageCmName | ||
| secretName := impl.ciCdConfig.ExtBlobStorageSecretName | ||
| cm, err := cv1.ConfigMaps(namespace).Get(ctx, cmName, opts) | ||
| if err != nil { | ||
| impl.Logger.Errorw("error in getting config map in external cluster", "err", err, "blobStorageCmName", impl.ciCdConfig.ExtBlobStorageCmName, "clusterName", clusterConfig.ClusterName) | ||
| return cmConfig, secretConfig, err | ||
| } | ||
| secret, err := cv1.Secrets(namespace).Get(ctx, secretName, opts) | ||
| if err != nil { | ||
| impl.Logger.Errorw("error in getting secret in external cluster", "err", err, "blobStorageSecretName", impl.ciCdConfig.ExtBlobStorageSecretName, "clusterName", clusterConfig.ClusterName) | ||
prakash100198 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return cmConfig, secretConfig, err | ||
| } | ||
| //for IAM configured in S3 in external cluster, get logs/artifact will not work | ||
| if cm.Data != nil && secret.Data != nil { | ||
| err = cmConfig.SetCmBlobStorageConfig(cm.Data) | ||
| if err != nil { | ||
| fmt.Println("error marshalling external blob storage cm data to struct:", err) | ||
| return cmConfig, secretConfig, err | ||
| } | ||
| err = secretConfig.SetSecretBlobStorageConfig(secret.Data) | ||
| if err != nil { | ||
| fmt.Println("error marshalling external blob storage secret data to struct:", err) | ||
| return cmConfig, secretConfig, err | ||
| } | ||
| } | ||
| if cm.Data == nil { | ||
| fmt.Println("Data field not found in config map") | ||
| } | ||
| if secret.Data == nil { | ||
| fmt.Println("Data field not found in secret") | ||
| } | ||
| impl.Logger.Infow("fetching cm and secret from external cluster cloud provider", "ext cluster config: ", cmConfig) | ||
| return cmConfig, secretConfig, nil | ||
| } | ||
|
|
||
| func updateRequestWithExtClusterCmAndSecret(request *blob_storage.BlobStorageRequest, cmConfig *bean2.CmBlobStorageConfig, secretConfig *bean2.SecretBlobStorageConfig) *blob_storage.BlobStorageRequest { | ||
| request.StorageType = cmConfig.CloudProvider | ||
|
|
||
| request.AwsS3BaseConfig.AccessKey = cmConfig.S3AccessKey | ||
| request.AwsS3BaseConfig.EndpointUrl = cmConfig.S3Endpoint | ||
| request.AwsS3BaseConfig.Passkey = decodeSecretKey(secretConfig.S3SecretKey) | ||
| isInSecure, _ := strconv.ParseBool(cmConfig.S3EndpointInsecure) | ||
| request.AwsS3BaseConfig.IsInSecure = isInSecure | ||
| request.AwsS3BaseConfig.BucketName = cmConfig.CdDefaultBuildLogsBucket | ||
| request.AwsS3BaseConfig.Region = cmConfig.CdDefaultCdLogsBucketRegion | ||
| s3BucketVersioned, _ := strconv.ParseBool(cmConfig.S3BucketVersioned) | ||
| request.AwsS3BaseConfig.VersioningEnabled = s3BucketVersioned | ||
|
|
||
| request.AzureBlobBaseConfig.AccountName = cmConfig.AzureAccountName | ||
| request.AzureBlobBaseConfig.AccountKey = decodeSecretKey(secretConfig.AzureAccountKey) | ||
| request.AzureBlobBaseConfig.BlobContainerName = cmConfig.AzureBlobContainerCiLog | ||
|
|
||
| request.GcpBlobBaseConfig.CredentialFileJsonData = decodeSecretKey(secretConfig.GcpBlobStorageCredentialJson) | ||
| request.GcpBlobBaseConfig.BucketName = cmConfig.CdDefaultBuildLogsBucket | ||
|
|
||
| return request | ||
| } | ||
|
|
||
| func decodeSecretKey(secretKey string) string { | ||
| decodedKey, err := base64.StdEncoding.DecodeString(secretKey) | ||
| if err != nil { | ||
| fmt.Println("error decoding base64 key:", err) | ||
| } | ||
| return string(decodedKey) | ||
| } | ||
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.