From dd84d5a4bc1017c23a471e4d38c1edad01b4427f Mon Sep 17 00:00:00 2001 From: rajeshmohanty-leanix <92529824+rajeshmohanty-leanix@users.noreply.github.com> Date: Sun, 2 Jan 2022 23:29:13 +0100 Subject: [PATCH 1/7] HEL 1270 ConnectorLogs --- cmd/leanix-k8s-connector/main.go | 61 ++++++++++++++++++-------------- pkg/leanix/integration_hub.go | 3 +- pkg/storage/azureblob.go | 12 +++++++ 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/cmd/leanix-k8s-connector/main.go b/cmd/leanix-k8s-connector/main.go index 1e8e412a..30aa1c1e 100644 --- a/cmd/leanix-k8s-connector/main.go +++ b/cmd/leanix-k8s-connector/main.go @@ -56,21 +56,34 @@ func main() { stdoutLogger, debugLogBuffer := initLogger() err := parseFlags() if err != nil { - log.Fatal(err) + log.Error(err) } enableVerbose(stdoutLogger, viper.GetBool(verboseFlag)) + // use the current context in kubeconfig + startResponse, err := kubernetesScan(debugLogBuffer) + if err != nil { + log.Error(err) + } + log.Info("Uploading connector logs to iHub") + _, err = storage.UploadConnectorLog(startResponse.ConnectorLoggingUrl, debugLogBuffer.Bytes()) + if err != nil { + log.Error(err) + } +} + +func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartResponse, err error) { log.Info("----------Attempting to Self Start via Integration Hub----------") accessToken, err := leanix.Authenticate(viper.GetString(integrationAPIFqdnFlag), viper.GetString(integrationAPITokenFlag)) if err != nil { - log.Fatal(err) + log.Error(err) } log.Info("Integration Hub authentication successful.") startResponse, err := leanix.SelfStartRun(viper.GetString(integrationAPIFqdnFlag), accessToken, viper.GetString(integrationAPIDatasourceNameFlag)) if err != nil { log.Info("Failed to start Integration Hub. Terminating..") - log.Fatal(err) + log.Error(err) return } log.Info("Getting connector config...") @@ -95,13 +108,13 @@ func main() { if viper.GetBool(localFlag) { config, err = clientcmd.BuildConfigFromFlags("", filepath.Join(homedir.HomeDir(), ".kube", "config")) if err != nil { - log.Fatal(err) + log.Error(err) } } else { - // use the current context in kubeconfig + config, err = restclient.InClusterConfig() if err != nil { - log.Fatalf("Failed to load kube config. Running in Kubernetes?\n%s", err) + log.Errorf("Failed to load kube config. Running in Kubernetes?\n%s", err) } } @@ -109,29 +122,29 @@ func main() { kubernetesAPI, err := kubernetes.NewAPI(config) if err != nil { - log.Fatal(err) + log.Error(err) } dynClient, err := dynamic.NewForConfig(config) if err != nil { - log.Fatal(err) + log.Error(err) } log.Debug("Get blacklist namespaces list...") blacklistedNamespacesList := viper.GetStringSlice(blacklistNamespacesFlag) blacklistedNamespaces, err := kubernetesAPI.Namespaces(blacklistedNamespacesList) if err != nil { - log.Fatal(err) + log.Error(err) } log.Debug("Getting blacklist namespaces list done.") log.Infof("Namespace blacklist: %v", reflect.ValueOf(blacklistedNamespaces).MapKeys()) resourcesList, err := ServerPreferredListableResources(kubernetesAPI.Client.Discovery()) if err != nil { - log.Fatal(err) + log.Error(err) } groupVersionResources, err := discovery.GroupVersionResources(resourcesList) if err != nil { - log.Panic(err) + log.Error(err) } _, err = leanix.UpdateInProgressStatus(startResponse.ProgressCallbackUrl, "Discovery of Version Resources is done. Moving on to mapping nodes") if err != nil { @@ -140,7 +153,7 @@ func main() { log.Debug("Listing nodes...") nodes, err := kubernetesAPI.Nodes() if err != nil { - log.Fatal(err) + log.Error(err) } log.Debug("Listing nodes done.") log.Debug("Map nodes to Kubernetes object") @@ -149,7 +162,7 @@ func main() { nodes, ) if err != nil { - log.Fatal(err) + log.Error(err) } kubernetesObjects := make([]mapper.KubernetesObject, 0) kubernetesObjects = append(kubernetesObjects, *clusterKubernetesObject) @@ -210,7 +223,7 @@ func main() { } instances, err := dynClient.Resource(gvr).List(context.Background(), metav1.ListOptions{}) if err != nil { - log.Panic(err) + log.Error(err) } for _, i := range instances.Items { if _, ok := blacklistedNamespaces[i.GetNamespace()]; ok { @@ -252,7 +265,7 @@ func main() { ldifByte, err := storage.Marshal(ldif) if err != nil { _, err = leanix.UpdateFailedProgressStatus(startResponse.ProgressCallbackUrl, "Failed to marshal ldif") - log.Fatal(err) + log.Error(err) } if viper.GetBool(enableCustomStorageFlag) { @@ -273,23 +286,17 @@ func main() { uploader, err := storage.NewBackend(viper.GetString("storage-backend"), &azureOpts, &localFileOpts) if err != nil { _, err = leanix.UpdateFailedProgressStatus(startResponse.ProgressCallbackUrl, "Failed to create uploader for backend storage") - log.Fatal(err) + log.Error(err) } err = uploader.UploadLdif(ldifByte) if err != nil { - log.Fatal(err) + log.Error(err) _, err := leanix.UpdateFailedProgressStatus(startResponse.ProgressCallbackUrl, "Failed to upload ldif to backend storage configured storage backend - "+viper.GetString("storage-backend")) if err != nil { - return + return nil, err } } - log.Info("Uploading log file to configured backend storage") - err = uploader.UploadLog(debugLogBuffer.Bytes()) - if err != nil { - log.Fatal(err) - } - _, err = leanix.UpdateInProgressStatus(startResponse.ProgressCallbackUrl, "Successfully uploaded ldif to configured storage backend - "+viper.GetString("storage-backend")) if err != nil { log.Infof("Failed to update progress[%s] to Integration Hub", leanix.IN_PROGRESS) @@ -303,8 +310,8 @@ func main() { if err != nil { log.Debug("Failed to upload ldif to Integration Hub ldif SAS Url") _, err := leanix.UpdateFailedProgressStatus(startResponse.ProgressCallbackUrl, "Failed to upload ldif to Integration Hub ldif SAS Url") - log.Fatal(err) - return + log.Error(err) + return nil, err } _, err = leanix.UpdateProgress(startResponse.ProgressCallbackUrl, leanix.FINISHED, "") if err != nil { @@ -312,6 +319,7 @@ func main() { } log.Debug("-----------End-----------") log.Info("-----------End-----------") + return startResponse, err } func ServerPreferredListableResources(d discovery.DiscoveryInterface) ([]*metav1.APIResourceList, error) { @@ -339,6 +347,7 @@ func parseFlags() error { // Let flags overwrite configs in viper err := viper.BindPFlags(flag.CommandLine) if err != nil { + log.Error(err) return err } // Check for config values in env vars diff --git a/pkg/leanix/integration_hub.go b/pkg/leanix/integration_hub.go index 9d485fd3..7d9812df 100644 --- a/pkg/leanix/integration_hub.go +++ b/pkg/leanix/integration_hub.go @@ -17,6 +17,7 @@ type SelfStartResponse struct { ConnectorConfiguration ConnectorConfiguration `json:"connectorConfiguration"` LdifResultUrl string `json:"ldifResultUrl"` ProgressCallbackUrl string `json:"progressCallbackUrl"` + ConnectorLoggingUrl string `json:"connectorLoggingUrl"` } type ConnectorConfiguration struct { @@ -80,7 +81,7 @@ func validateConnectorConfiguration(configuration ConnectorConfiguration) (bool, return false, fmt.Errorf("INVALID CONNECTOR CONFIGURATION: RESOLVE LABEL CANNOT BE EMPTY IF THE RESOLVE STRATEGY IS 'LABEL'") } - if configuration.ResolveStrategy == "label" && configuration.ClusterName == "" { + if configuration.ClusterName == "" { return false, fmt.Errorf("INVALID CONNECTOR CONFIGURATION: CLUSTER NAME CANNOT BE EMPTY") } diff --git a/pkg/storage/azureblob.go b/pkg/storage/azureblob.go index 40ad2a92..0a7e8f86 100644 --- a/pkg/storage/azureblob.go +++ b/pkg/storage/azureblob.go @@ -87,3 +87,15 @@ func UploadFileToSasUrl(blobSasUrl url.URL, content []byte) error { } return nil } + +func UploadConnectorLog(connectorLoggingUrl string, logs []byte) (string, error) { + parse, err := url.Parse(connectorLoggingUrl) + if err != nil { + return "", err + } + err = UploadFileToSasUrl(*parse, logs) + if err != nil { + return "", err + } + return "", nil +} From 9dc47cd4beda837948b300ea9ec48679d5bd2365 Mon Sep 17 00:00:00 2001 From: rajeshmohanty-leanix <92529824+rajeshmohanty-leanix@users.noreply.github.com> Date: Mon, 3 Jan 2022 13:14:32 +0100 Subject: [PATCH 2/7] hel1270 6.3.0 version created --- CHANGELOG.md | 3 +++ Makefile | 2 +- README.md | 3 ++- helm/index.yaml | 36 +++++++++++++++++---------- helm/leanix-k8s-connector-6.3.0.tgz | Bin 0 -> 2944 bytes helm/leanix-k8s-connector/Chart.yaml | 4 +-- 6 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 helm/leanix-k8s-connector-6.3.0.tgz diff --git a/CHANGELOG.md b/CHANGELOG.md index 5267ccc8..5a407657 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # LeanIX Kubernetes Connector Changelog +## Release 2022-01-03 - 6.3.0 +* Connector Logs can be accessed in iHub (w.r.t specific dataSource name) `Show Log` button for troubleshooting and monitoring purpose. + ## Release 2022-01-03 - 6.2.0 * To ensure support for multiple helm release on same cluster, all the existing K8s workloads are suffixed with the Helm release name. * Support multiple workspace ID for same cluster via different helm releases diff --git a/Makefile b/Makefile index 9996fe70..39bc90de 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PROJECT ?= leanix-k8s-connector DOCKER_NAMESPACE ?= leanixacrpublic.azurecr.io -VERSION := 6.2.0 +VERSION := 6.3.0 FULL_VERSION := $(VERSION)-$(shell git describe --tags --always) IMAGE := $(DOCKER_NAMESPACE)/$(PROJECT):$(VERSION) diff --git a/README.md b/README.md index e75b06b8..ed366753 100644 --- a/README.md +++ b/README.md @@ -553,7 +553,7 @@ Issue `kubectl delete jobs.batch leanix-k8s-connector-1563961200` and you should - This migration involves changes to make the helm configurations much simpler. The operator does not have to worry about such parameters while scanning the data source. - The following helm values can not be set as parameters anymore. Therefore, no need to use them either in helm commands or values.yaml. - `args.clustername` : The iHUB connector configuration for the k8s integration is extended to capture the 'clusterName'. - - `args.connectorID`, `args.connectorVersion`, `args.processingMode` : Here these values are set by default and no need to set with helm commands or values.yaml + - `args.connectorID`, `args.connectorVersion`, `args.processingMode` : Here these values are set by default and no need to set with helm commands or values.yaml ### 4.0.0 to 5.0.0 - New flag `enableCustomStorage` is introduced. This flags allows to disable the option to upload LDIF to custom storage backend. Disabling the flag will not affect the functionality of the connector. @@ -578,6 +578,7 @@ e.g `--set args.storageBackend=file` | Release date | Connector version | Integration version | Helm chart version | Container image tag | | :----------: | :---------------: | :-----------------: | :----------------: | :-----------------: | +| 2022-01-03 | 6.3.0 | 1.0.0 | 6.3.0 | 6.3.0 | | 2021-12-08 | 6.1.0 | 1.0.0 | 6.1.0 | 6.1.0 | | 2021-12-06 | 6.0.3 | 1.0.0 | 6.0.3 | 6.0.3 | | 2021-12-19 | 6.0.2 | 1.0.0 | 6.0.2 | 6.0.2 | diff --git a/helm/index.yaml b/helm/index.yaml index 8bd495b2..7e2be46b 100644 --- a/helm/index.yaml +++ b/helm/index.yaml @@ -1,9 +1,19 @@ apiVersion: v1 entries: leanix-k8s-connector: + - apiVersion: v1 + appVersion: 6.3.0 + created: "2022-01-03T13:13:26.726066+01:00" + description: Retrieves information from Kubernetes cluster + digest: 44973672d6054cd0660a94e71b23bf9cf472f27bc532133981af6f6055e87424 + kubeVersion: '>= 1.19.0-0' + name: leanix-k8s-connector + urls: + - leanix-k8s-connector-6.3.0.tgz + version: 6.3.0 - apiVersion: v1 appVersion: 6.2.0 - created: "2021-12-23T14:40:59.713818+01:00" + created: "2022-01-03T13:13:26.723288+01:00" description: Retrieves information from Kubernetes cluster digest: 5774478e89bc749ba21ec7f2477bb348788f2bbf6e8b76956eee5c4739de9e46 kubeVersion: '>= 1.19.0-0' @@ -13,7 +23,7 @@ entries: version: 6.2.0 - apiVersion: v1 appVersion: 6.1.0 - created: "2021-12-23T14:40:59.711566+01:00" + created: "2022-01-03T13:13:26.721701+01:00" description: Retrieves information from Kubernetes cluster digest: eabf3e49a9d4a0722228cb24872e6dfcc7b9db6b764bc714a74c0941f0d3ea4f name: leanix-k8s-connector @@ -22,7 +32,7 @@ entries: version: 6.1.0 - apiVersion: v1 appVersion: 6.0.3 - created: "2021-12-23T14:40:59.710467+01:00" + created: "2022-01-03T13:13:26.720341+01:00" description: Retrieves information from Kubernetes cluster digest: 5f1be6a80fc173d45ca60f5da8937abc0fcb2cc14652d6149d9ff2e405568a71 name: leanix-k8s-connector @@ -31,7 +41,7 @@ entries: version: 6.0.3 - apiVersion: v1 appVersion: 6.0.2 - created: "2021-12-23T14:40:59.709385+01:00" + created: "2022-01-03T13:13:26.718644+01:00" description: Retrieves information from Kubernetes cluster digest: ccd112d1de601bfa796c4413ddc2b394f93ec4b66604338a736593168523b327 name: leanix-k8s-connector @@ -40,7 +50,7 @@ entries: version: 6.0.2 - apiVersion: v1 appVersion: 6.0.1 - created: "2021-12-23T14:40:59.708288+01:00" + created: "2022-01-03T13:13:26.716584+01:00" description: Retrieves information from Kubernetes cluster digest: f3b959e24bdbf55314fa6d0a05681ec41dd34b1493b026a3450bf147e62a4b1b name: leanix-k8s-connector @@ -49,7 +59,7 @@ entries: version: 6.0.1 - apiVersion: v1 appVersion: 6.0.0 - created: "2021-12-23T14:40:59.70717+01:00" + created: "2022-01-03T13:13:26.715001+01:00" description: Retrieves information from Kubernetes cluster digest: c51f68b592c6f608a2f982e8c322280b8fc3aa4ac6ed0d823b2baf24b0877e6b name: leanix-k8s-connector @@ -58,7 +68,7 @@ entries: version: 6.0.0 - apiVersion: v1 appVersion: 5.0.0 - created: "2021-12-23T14:40:59.705136+01:00" + created: "2022-01-03T13:13:26.712156+01:00" description: Retrieves information from Kubernetes cluster digest: 549a753cf9875ca4eeaf5ecb5c64e76149b30bb8e82eee821f6c81cca27c37cf name: leanix-k8s-connector @@ -67,7 +77,7 @@ entries: version: 5.0.0 - apiVersion: v1 appVersion: 4.0.0 - created: "2021-12-23T14:40:59.704044+01:00" + created: "2022-01-03T13:13:26.710963+01:00" description: Retrieves information from Kubernetes cluster digest: adf5c8ef024857c4a0845a5c659f27bd7f21cdf568fff3445a192425c44fc9a8 name: leanix-k8s-connector @@ -76,7 +86,7 @@ entries: version: 4.0.0 - apiVersion: v1 appVersion: 3.0.0 - created: "2021-12-23T14:40:59.703176+01:00" + created: "2022-01-03T13:13:26.710195+01:00" description: Retrieves information from Kubernetes cluster digest: 2927aebc215a1c5175e986135e36a10101e90fa69e7ab22a183049d086f7eddb name: leanix-k8s-connector @@ -85,7 +95,7 @@ entries: version: 3.0.0 - apiVersion: v1 appVersion: 2.0.0 - created: "2021-12-23T14:40:59.702333+01:00" + created: "2022-01-03T13:13:26.709008+01:00" description: Retrieves information from Kubernetes cluster digest: 3481723d2374757038495117518c47f634054408ccbd55112a6260d5a15e18c9 name: leanix-k8s-connector @@ -94,7 +104,7 @@ entries: version: 2.0.0 - apiVersion: v1 appVersion: 2.0.0-beta7 - created: "2021-12-23T14:40:59.701445+01:00" + created: "2022-01-03T13:13:26.707932+01:00" description: Retrieves information from Kubernetes cluster digest: 0ade89d01236286f11ebf70290e2c4c82740fac11ec755be9dddd2375c74246f name: leanix-k8s-connector @@ -103,11 +113,11 @@ entries: version: 2.0.0-beta7 - apiVersion: v1 appVersion: 1.1.0 - created: "2021-12-23T14:40:59.700206+01:00" + created: "2022-01-03T13:13:26.706693+01:00" description: Retrieves information from Kubernetes cluster digest: aa3ee10eefe30e61e37058762b031bdee11cb9dd67afecdf6e831335d5c16e0f name: leanix-k8s-connector urls: - leanix-k8s-connector-1.0.0.tgz version: 1.0.0 -generated: "2021-12-23T14:40:59.698587+01:00" +generated: "2022-01-03T13:13:26.705274+01:00" diff --git a/helm/leanix-k8s-connector-6.3.0.tgz b/helm/leanix-k8s-connector-6.3.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..7f2d024e4458e2146031656d39a0f9dc065dcd0d GIT binary patch literal 2944 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 literal 0 HcmV?d00001 diff --git a/helm/leanix-k8s-connector/Chart.yaml b/helm/leanix-k8s-connector/Chart.yaml index b5b32e38..cac52dcc 100644 --- a/helm/leanix-k8s-connector/Chart.yaml +++ b/helm/leanix-k8s-connector/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 -appVersion: "6.2.0" +appVersion: "6.3.0" description: Retrieves information from Kubernetes cluster name: leanix-k8s-connector -version: 6.2.0 +version: 6.3.0 kubeVersion: '>= 1.19.0-0' \ No newline at end of file From b40fbd6d739ed85004ee018b84dd130a732ea513 Mon Sep 17 00:00:00 2001 From: rajeshmohanty-leanix <92529824+rajeshmohanty-leanix@users.noreply.github.com> Date: Mon, 3 Jan 2022 14:52:27 +0100 Subject: [PATCH 3/7] Release table updated with missing version v6.2.0 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ed366753..7c1974ea 100644 --- a/README.md +++ b/README.md @@ -579,6 +579,7 @@ e.g `--set args.storageBackend=file` | Release date | Connector version | Integration version | Helm chart version | Container image tag | | :----------: | :---------------: | :-----------------: | :----------------: | :-----------------: | | 2022-01-03 | 6.3.0 | 1.0.0 | 6.3.0 | 6.3.0 | +| 2022-01-03 | 6.2.0 | 1.0.0 | 6.2.0 | 6.2.0 | | 2021-12-08 | 6.1.0 | 1.0.0 | 6.1.0 | 6.1.0 | | 2021-12-06 | 6.0.3 | 1.0.0 | 6.0.3 | 6.0.3 | | 2021-12-19 | 6.0.2 | 1.0.0 | 6.0.2 | 6.0.2 | From 35c53851b4b72de7ad2c3ebb82aae094c884e76f Mon Sep 17 00:00:00 2001 From: rajeshmohanty-leanix <92529824+rajeshmohanty-leanix@users.noreply.github.com> Date: Mon, 3 Jan 2022 15:04:38 +0100 Subject: [PATCH 4/7] HEL1270 return statements added in fallback scenarios --- cmd/leanix-k8s-connector/main.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/leanix-k8s-connector/main.go b/cmd/leanix-k8s-connector/main.go index 0a7f7d04..66a5c32b 100644 --- a/cmd/leanix-k8s-connector/main.go +++ b/cmd/leanix-k8s-connector/main.go @@ -108,13 +108,14 @@ func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes if viper.GetBool(localFlag) { config, err = clientcmd.BuildConfigFromFlags("", filepath.Join(homedir.HomeDir(), ".kube", "config")) if err != nil { - log.Error(err) + return nil, err } } else { config, err = restclient.InClusterConfig() if err != nil { log.Errorf("Failed to load kube config. Running in Kubernetes?\n%s", err) + return nil, err } } @@ -122,7 +123,7 @@ func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes kubernetesAPI, err := kubernetes.NewAPI(config) if err != nil { - log.Error(err) + return nil, err } dynClient, err := dynamic.NewForConfig(config) if err != nil { @@ -133,18 +134,18 @@ func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes blacklistedNamespacesList := viper.GetStringSlice(blacklistNamespacesFlag) blacklistedNamespaces, err := kubernetesAPI.Namespaces(blacklistedNamespacesList) if err != nil { - log.Error(err) + return nil, err } log.Debug("Getting blacklist namespaces list done.") log.Infof("Namespace blacklist: %v", reflect.ValueOf(blacklistedNamespaces).MapKeys()) resourcesList, err := ServerPreferredListableResources(kubernetesAPI.Client.Discovery()) if err != nil { - log.Error(err) + return nil, err } groupVersionResources, err := discovery.GroupVersionResources(resourcesList) if err != nil { - log.Error(err) + return nil, err } _, err = leanix.UpdateInProgressStatus(startResponse.ProgressCallbackUrl, "Discovery of Version Resources is done. Moving on to mapping nodes") if err != nil { @@ -153,7 +154,7 @@ func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes log.Debug("Listing nodes...") nodes, err := kubernetesAPI.Nodes() if err != nil { - log.Error(err) + return nil, err } log.Debug("Listing nodes done.") log.Debug("Map nodes to Kubernetes object") @@ -162,7 +163,7 @@ func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes nodes, ) if err != nil { - log.Error(err) + return nil, err } kubernetesObjects := make([]mapper.KubernetesObject, 0) kubernetesObjects = append(kubernetesObjects, *clusterKubernetesObject) @@ -223,7 +224,7 @@ func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes } instances, err := dynClient.Resource(gvr).List(context.Background(), metav1.ListOptions{}) if err != nil { - log.Error(err) + return nil, err } for _, i := range instances.Items { if _, ok := blacklistedNamespaces[i.GetNamespace()]; ok { @@ -266,6 +267,7 @@ func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes if err != nil { _, err = leanix.UpdateFailedProgressStatus(startResponse.ProgressCallbackUrl, "Failed to marshal ldif") log.Error(err) + return nil, err } if viper.GetBool(enableCustomStorageFlag) { @@ -286,7 +288,7 @@ func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes uploader, err := storage.NewBackend(viper.GetString("storage-backend"), &azureOpts, &localFileOpts) if err != nil { _, err = leanix.UpdateFailedProgressStatus(startResponse.ProgressCallbackUrl, "Failed to create uploader for backend storage") - log.Error(err) + return nil, err } err = uploader.UploadLdif(ldifByte, storage.LdifFileName+viper.GetString(lxWorkspaceFlag)+storage.LdifFileExtension) if err != nil { From b774bfaa83183a981b6c19245b296de658e419bb Mon Sep 17 00:00:00 2001 From: rajeshmohanty-leanix <92529824+rajeshmohanty-leanix@users.noreply.github.com> Date: Wed, 5 Jan 2022 15:35:58 +0100 Subject: [PATCH 5/7] HEL1270 Updated as per the review comment --- pkg/storage/azureblob.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/storage/azureblob.go b/pkg/storage/azureblob.go index 3715e7f6..463ba038 100644 --- a/pkg/storage/azureblob.go +++ b/pkg/storage/azureblob.go @@ -88,14 +88,14 @@ func UploadFileToSasUrl(blobSasUrl url.URL, content []byte) error { return nil } -func UploadConnectorLog(connectorLoggingUrl string, logs []byte) (string, error) { +func UploadConnectorLog(connectorLoggingUrl string, logs []byte) error { parse, err := url.Parse(connectorLoggingUrl) if err != nil { - return "", err + return err } err = UploadFileToSasUrl(*parse, logs) if err != nil { - return "", err + return err } - return "", nil + return nil } From 7afe42f07e18c6cb7e56463404485b3b904f4648 Mon Sep 17 00:00:00 2001 From: rajeshmohanty-leanix <92529824+rajeshmohanty-leanix@users.noreply.github.com> Date: Wed, 5 Jan 2022 15:47:13 +0100 Subject: [PATCH 6/7] HEL1270 Updated implementation of UploadConnectorLog function --- cmd/leanix-k8s-connector/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/leanix-k8s-connector/main.go b/cmd/leanix-k8s-connector/main.go index 66a5c32b..b5d1e8ca 100644 --- a/cmd/leanix-k8s-connector/main.go +++ b/cmd/leanix-k8s-connector/main.go @@ -66,7 +66,7 @@ func main() { log.Error(err) } log.Info("Uploading connector logs to iHub") - _, err = storage.UploadConnectorLog(startResponse.ConnectorLoggingUrl, debugLogBuffer.Bytes()) + err = storage.UploadConnectorLog(startResponse.ConnectorLoggingUrl, debugLogBuffer.Bytes()) if err != nil { log.Error(err) } From 4fbe03a5f6e55ba6c7fc0df5f09a13d3af169e9c Mon Sep 17 00:00:00 2001 From: rajeshmohanty-leanix <92529824+rajeshmohanty-leanix@users.noreply.github.com> Date: Thu, 6 Jan 2022 15:51:29 +0100 Subject: [PATCH 7/7] HEL1270 change func name as per the go standard --- cmd/leanix-k8s-connector/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/leanix-k8s-connector/main.go b/cmd/leanix-k8s-connector/main.go index b5d1e8ca..9bc060bb 100644 --- a/cmd/leanix-k8s-connector/main.go +++ b/cmd/leanix-k8s-connector/main.go @@ -61,7 +61,7 @@ func main() { enableVerbose(stdoutLogger, viper.GetBool(verboseFlag)) // use the current context in kubeconfig - startResponse, err := kubernetesScan(debugLogBuffer) + startResponse, err := KubernetesScan(debugLogBuffer) if err != nil { log.Error(err) } @@ -72,7 +72,7 @@ func main() { } } -func kubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartResponse, err error) { +func KubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartResponse, err error) { log.Info("----------Attempting to Self Start via Integration Hub----------") accessToken, err := leanix.Authenticate(viper.GetString(integrationAPIFqdnFlag), viper.GetString(integrationAPITokenFlag))