Skip to content

Commit

Permalink
Merge pull request #158 from leanix/bugfix/HEL-1693
Browse files Browse the repository at this point in the history
More logging
  • Loading branch information
DennisBerthold-leanix authored Mar 7, 2022
2 parents 797ffce + 5da4c39 commit eba3e40
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# LeanIX Kubernetes Connector Changelog

## Release 2022-03-07 - 6.3.3
* Increased logging and added more precise log messages

## Release 2022-01-20 - 6.3.2
* Error messages can be captured and accessed via connector logs in iHub, if the connector configuration is not correct.

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROJECT ?= leanix-k8s-connector
DOCKER_NAMESPACE ?= leanixacrpublic.azurecr.io

VERSION := 6.3.2
VERSION := 6.3.3
FULL_VERSION := $(VERSION)-$(shell git describe --tags --always)

IMAGE := $(DOCKER_NAMESPACE)/$(PROJECT):$(VERSION)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ e.g `--set args.storageBackend=file`

| Release date | Connector version | Integration version | Helm chart version | Container image tag |
| :----------: | :---------------: | :-----------------: | :----------------: | :-----------------: |
| 2022-03-07 | 6.3.3 | 1.0.0 | 6.3.3 | 6.3.3 |
| 2022-01-20 | 6.3.2 | 1.0.0 | 6.3.2 | 6.3.2 |
| 2022-01-10 | 6.3.1 | 1.0.0 | 6.3.1 | 6.3.1 |
| 2022-01-03 | 6.3.0 | 1.0.0 | 6.3.0 | 6.3.0 |
Expand Down
17 changes: 10 additions & 7 deletions cmd/leanix-k8s-connector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {
if err != nil {
log.Error(err)
}
log.Debug("Uploading connector logs to iHub")
log.Info("Uploading connector logs to iHub")
err = storage.UploadConnectorLog(startResponse.ConnectorLoggingUrl, debugLogBuffer.Bytes())
if err != nil {
log.Error(err)
Expand All @@ -78,19 +78,22 @@ func KubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes
accessToken, err := leanix.Authenticate(viper.GetString(integrationAPIFqdnFlag), viper.GetString(integrationAPITokenFlag))
if err != nil {
log.Error(err)
log.Info("Failed to authenticate. Terminating..")
return nil, 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.Info("Main: Failed to start Integration Hub. Terminating..")
return startResponse, err
}
log.Info("Getting connector config...")
if startResponse != nil {
log.Infof("Successfully self started via Integration Hub. Progress call back - %s", startResponse.ProgressCallbackUrl)
_, err = leanix.UpdateInProgressStatus(startResponse.ProgressCallbackUrl, "Successfully self started via Integration Hub. Connector is in progress")
if err != nil {
log.Infof("Failed to update progress[%s] to Integration Hub", leanix.IN_PROGRESS)
log.Infof("KubernetesScan: Failed to update progress[%s] to Integration Hub", leanix.IN_PROGRESS)
}
}

Expand Down Expand Up @@ -148,7 +151,7 @@ func KubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes
}
_, err = leanix.UpdateInProgressStatus(startResponse.ProgressCallbackUrl, "Discovery of Version Resources is done. Moving on to mapping nodes")
if err != nil {
log.Infof("Failed to update progress[%s] to Integration Hub", leanix.IN_PROGRESS)
log.Infof("KubernetesScan: Before scan: Failed to update progress[%s] to Integration Hub", leanix.IN_PROGRESS)
}
log.Debug("Listing nodes...")
nodes, err := kubernetesAPI.Nodes()
Expand All @@ -168,7 +171,7 @@ func KubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes
kubernetesObjects = append(kubernetesObjects, *clusterKubernetesObject)
_, err = leanix.UpdateInProgressStatus(startResponse.ProgressCallbackUrl, "Mapping nodes is done. Moving on to collecting kubernetes objects from Version Resources.")
if err != nil {
log.Infof("Failed to update progress[%s] to Integration Hub", leanix.IN_PROGRESS)
log.Infof("KubernetesScan: After Scan: Failed to update progress[%s] to Integration Hub", leanix.IN_PROGRESS)
}
resourceGroupWhitelist := map[string]map[string]interface{}{
"": map[string]interface{}{
Expand Down Expand Up @@ -218,7 +221,7 @@ func KubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes

for gvr := range groupVersionResources {
if _, ok := resourceGroupWhitelist[gvr.Group][gvr.Resource]; !ok {
log.Debugf("Not scanning resouce %s", strings.Join([]string{gvr.Group, gvr.Version, gvr.Resource}, "/"))
log.Debugf("Not scanning resource %s", strings.Join([]string{gvr.Group, gvr.Version, gvr.Resource}, "/"))
continue
}
instances, err := dynClient.Resource(gvr).List(context.Background(), metav1.ListOptions{})
Expand Down Expand Up @@ -259,7 +262,7 @@ func KubernetesScan(debugLogBuffer *bytes.Buffer) (response *leanix.SelfStartRes

_, err = leanix.UpdateInProgressStatus(startResponse.ProgressCallbackUrl, "Successfully collected required kubernetes data.")
if err != nil {
log.Infof("Failed to progress[%s] to Integration Hub", leanix.IN_PROGRESS)
log.Infof("KubernetesScan: After mapping: Failed to progress[%s] to Integration Hub", leanix.IN_PROGRESS)
}
log.Debug("Marshal ldif")
ldifByte, err := storage.Marshal(ldif)
Expand Down
42 changes: 26 additions & 16 deletions helm/index.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
apiVersion: v1
entries:
leanix-k8s-connector:
- apiVersion: v1
appVersion: 6.3.3
created: "2022-03-07T13:02:45.487725+01:00"
description: Retrieves information from Kubernetes cluster
digest: f0785c889298cac1eb58ae9380e62457c2b1b73fbfbdccb35f2d85410b50293c
kubeVersion: '>= 1.19.0-0'
name: leanix-k8s-connector
urls:
- leanix-k8s-connector-6.3.3.tgz
version: 6.3.3
- apiVersion: v1
appVersion: 6.3.2
created: "2022-01-20T15:50:11.994812+01:00"
created: "2022-03-07T13:02:45.487146+01:00"
description: Retrieves information from Kubernetes cluster
digest: 918ec561f0ab03c5039144e7d151e447dac40ad1bace19435ae4be0c21ab6ad2
kubeVersion: '>= 1.19.0-0'
Expand All @@ -13,7 +23,7 @@ entries:
version: 6.3.2
- apiVersion: v1
appVersion: 6.3.1
created: "2022-01-20T15:50:11.990534+01:00"
created: "2022-03-07T13:02:45.486187+01:00"
description: Retrieves information from Kubernetes cluster
digest: e4ff6114e41c6f7694be5ab006f64ae6620758774610fcbb41357feb71da547c
kubeVersion: '>= 1.19.0-0'
Expand All @@ -23,7 +33,7 @@ entries:
version: 6.3.1
- apiVersion: v1
appVersion: 6.3.0
created: "2022-01-20T15:50:11.989594+01:00"
created: "2022-03-07T13:02:45.485163+01:00"
description: Retrieves information from Kubernetes cluster
digest: 44973672d6054cd0660a94e71b23bf9cf472f27bc532133981af6f6055e87424
kubeVersion: '>= 1.19.0-0'
Expand All @@ -33,7 +43,7 @@ entries:
version: 6.3.0
- apiVersion: v1
appVersion: 6.2.0
created: "2022-01-20T15:50:11.988611+01:00"
created: "2022-03-07T13:02:45.483783+01:00"
description: Retrieves information from Kubernetes cluster
digest: 5774478e89bc749ba21ec7f2477bb348788f2bbf6e8b76956eee5c4739de9e46
kubeVersion: '>= 1.19.0-0'
Expand All @@ -43,7 +53,7 @@ entries:
version: 6.2.0
- apiVersion: v1
appVersion: 6.1.0
created: "2022-01-20T15:50:11.98794+01:00"
created: "2022-03-07T13:02:45.483027+01:00"
description: Retrieves information from Kubernetes cluster
digest: eabf3e49a9d4a0722228cb24872e6dfcc7b9db6b764bc714a74c0941f0d3ea4f
name: leanix-k8s-connector
Expand All @@ -52,7 +62,7 @@ entries:
version: 6.1.0
- apiVersion: v1
appVersion: 6.0.3
created: "2022-01-20T15:50:11.987089+01:00"
created: "2022-03-07T13:02:45.482201+01:00"
description: Retrieves information from Kubernetes cluster
digest: 5f1be6a80fc173d45ca60f5da8937abc0fcb2cc14652d6149d9ff2e405568a71
name: leanix-k8s-connector
Expand All @@ -61,7 +71,7 @@ entries:
version: 6.0.3
- apiVersion: v1
appVersion: 6.0.2
created: "2022-01-20T15:50:11.985469+01:00"
created: "2022-03-07T13:02:45.4812+01:00"
description: Retrieves information from Kubernetes cluster
digest: ccd112d1de601bfa796c4413ddc2b394f93ec4b66604338a736593168523b327
name: leanix-k8s-connector
Expand All @@ -70,7 +80,7 @@ entries:
version: 6.0.2
- apiVersion: v1
appVersion: 6.0.1
created: "2022-01-20T15:50:11.984088+01:00"
created: "2022-03-07T13:02:45.480092+01:00"
description: Retrieves information from Kubernetes cluster
digest: f3b959e24bdbf55314fa6d0a05681ec41dd34b1493b026a3450bf147e62a4b1b
name: leanix-k8s-connector
Expand All @@ -79,7 +89,7 @@ entries:
version: 6.0.1
- apiVersion: v1
appVersion: 6.0.0
created: "2022-01-20T15:50:11.982122+01:00"
created: "2022-03-07T13:02:45.479027+01:00"
description: Retrieves information from Kubernetes cluster
digest: c51f68b592c6f608a2f982e8c322280b8fc3aa4ac6ed0d823b2baf24b0877e6b
name: leanix-k8s-connector
Expand All @@ -88,7 +98,7 @@ entries:
version: 6.0.0
- apiVersion: v1
appVersion: 5.0.0
created: "2022-01-20T15:50:11.981207+01:00"
created: "2022-03-07T13:02:45.478112+01:00"
description: Retrieves information from Kubernetes cluster
digest: 549a753cf9875ca4eeaf5ecb5c64e76149b30bb8e82eee821f6c81cca27c37cf
name: leanix-k8s-connector
Expand All @@ -97,7 +107,7 @@ entries:
version: 5.0.0
- apiVersion: v1
appVersion: 4.0.0
created: "2022-01-20T15:50:11.979753+01:00"
created: "2022-03-07T13:02:45.476295+01:00"
description: Retrieves information from Kubernetes cluster
digest: adf5c8ef024857c4a0845a5c659f27bd7f21cdf568fff3445a192425c44fc9a8
name: leanix-k8s-connector
Expand All @@ -106,7 +116,7 @@ entries:
version: 4.0.0
- apiVersion: v1
appVersion: 3.0.0
created: "2022-01-20T15:50:11.978602+01:00"
created: "2022-03-07T13:02:45.474897+01:00"
description: Retrieves information from Kubernetes cluster
digest: 2927aebc215a1c5175e986135e36a10101e90fa69e7ab22a183049d086f7eddb
name: leanix-k8s-connector
Expand All @@ -115,7 +125,7 @@ entries:
version: 3.0.0
- apiVersion: v1
appVersion: 2.0.0
created: "2022-01-20T15:50:11.97724+01:00"
created: "2022-03-07T13:02:45.473985+01:00"
description: Retrieves information from Kubernetes cluster
digest: 3481723d2374757038495117518c47f634054408ccbd55112a6260d5a15e18c9
name: leanix-k8s-connector
Expand All @@ -124,7 +134,7 @@ entries:
version: 2.0.0
- apiVersion: v1
appVersion: 2.0.0-beta7
created: "2022-01-20T15:50:11.976073+01:00"
created: "2022-03-07T13:02:45.473088+01:00"
description: Retrieves information from Kubernetes cluster
digest: 0ade89d01236286f11ebf70290e2c4c82740fac11ec755be9dddd2375c74246f
name: leanix-k8s-connector
Expand All @@ -133,11 +143,11 @@ entries:
version: 2.0.0-beta7
- apiVersion: v1
appVersion: 1.1.0
created: "2022-01-20T15:50:11.975278+01:00"
created: "2022-03-07T13:02:45.471974+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: "2022-01-20T15:50:11.971746+01:00"
generated: "2022-03-07T13:02:45.47074+01:00"
Binary file added helm/leanix-k8s-connector-6.3.3.tgz
Binary file not shown.
4 changes: 2 additions & 2 deletions helm/leanix-k8s-connector/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
appVersion: "6.3.2"
appVersion: "6.3.3"
description: Retrieves information from Kubernetes cluster
name: leanix-k8s-connector
version: 6.3.2
version: 6.3.3
kubeVersion: '>= 1.19.0-0'
2 changes: 1 addition & 1 deletion helm/leanix-k8s-connector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ schedule:

image:
repository: leanixacrpublic.azurecr.io/leanix-k8s-connector
tag: 6.3.2
tag: 6.3.3
pullPolicy: Always

securityContext:
Expand Down
1 change: 1 addition & 0 deletions pkg/leanix/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type SyncRunResponse struct {
func Authenticate(fqdn string, token string) (string, error) {
body := strings.NewReader("grant_type=client_credentials")
req, err := http.NewRequest("POST", "https://"+fqdn+"/services/mtm/v1/oauth2/token", body)
log.Infof("LeanIX integration api fqdn : %s", fqdn)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
if err != nil {
return "", err
Expand Down
3 changes: 2 additions & 1 deletion pkg/leanix/integration_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func SelfStartRun(fqdn string, accessToken string, datasource string) (*SelfStar
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+accessToken)
if err != nil {
log.Infof("SelfStartRun: Error while starting run for datasource: %s", datasourceRunUrl)
return nil, err
}
log.Infof("Initiating connection to Integration Hub API with dataSource name: %s with region value: %s\n", datasource, fqdn)
Expand Down Expand Up @@ -69,7 +70,7 @@ func SelfStartRun(fqdn string, accessToken string, datasource string) (*SelfStar
if error != nil {
_, err = UpdateFailedProgressStatus(startResponse.ProgressCallbackUrl, "INVALID CONNECTOR CONFIGURATION: ABORTING IHUB RUN.")
if err != nil {
log.Errorf("Failed to update progress[%s] to Integration Hub", FAILED)
log.Errorf("SelfStartRun: Failed to update progress[%s] to Integration Hub", FAILED)
}
return &startResponse, error
}
Expand Down

0 comments on commit eba3e40

Please sign in to comment.