From 6cb9e82ed9916cdc621835f77d653a3f6803445c Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 16:45:06 +0200 Subject: [PATCH 01/22] logs --- pkg/defaults/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index 8d7e685..66a837e 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -46,7 +46,7 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) // Handle a deprecated case where resources are provided in config file return integration.CreateIntegration(portClient, applicationConfig.StateKey, applicationConfig.EventListenerType, defaultIntegrationConfig) } else { - klog.Infof("Integration exists, patching it") + klog.Infof("Integration with state key %s already exists, patching it", applicationConfig.StateKey) integrationPatch := &port.Integration{ EventListener: getEventListenerConfig(applicationConfig.EventListenerType), } From 358e52868dafc5e8bb12009ca236f6c887435625 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 16:47:39 +0200 Subject: [PATCH 02/22] logs --- pkg/defaults/init.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index 66a837e..e0f5521 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -26,7 +26,8 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) } if err != nil { - klog.Infof("Integration does not exist, creating a new one") + klog.Infof("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) + klog.Infof("Creating integration") // The exporter supports a deprecated case where resources are provided in config file and integration does not // exist. If this is not the case, we support the new way of creating the integration with the default resources. // Only one of the two cases can be true. From 151f6fcd623442cfb988431c23ee11317c7e5c45 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 16:50:33 +0200 Subject: [PATCH 03/22] logs --- pkg/defaults/init.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index e0f5521..6e9b3ba 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -47,6 +47,7 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) // Handle a deprecated case where resources are provided in config file return integration.CreateIntegration(portClient, applicationConfig.StateKey, applicationConfig.EventListenerType, defaultIntegrationConfig) } else { + klog.Infof("integration : %v", existingIntegration) klog.Infof("Integration with state key %s already exists, patching it", applicationConfig.StateKey) integrationPatch := &port.Integration{ EventListener: getEventListenerConfig(applicationConfig.EventListenerType), From 24caf0923c806d3503a68b97c8fd27c0bad5ee7a Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 16:54:11 +0200 Subject: [PATCH 04/22] logs --- pkg/port/cli/integration.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/port/cli/integration.go b/pkg/port/cli/integration.go index e158f6b..9db5604 100644 --- a/pkg/port/cli/integration.go +++ b/pkg/port/cli/integration.go @@ -3,6 +3,7 @@ package cli import ( "fmt" "github.com/port-labs/port-k8s-exporter/pkg/port" + "k8s.io/klog/v2" ) func parseIntegration(i *port.Integration) *port.Integration { @@ -43,6 +44,7 @@ func (c *PortClient) GetIntegration(stateKey string) (*port.Integration, error) resp, err := c.Client.R(). SetResult(&pb). Get(fmt.Sprintf("v1/integration/%s", stateKey)) + klog.Infof("Integration: %v", pb) if err != nil { return nil, err } From 8ea77e4b076fefd5ca2ac8f960eaf2a4d116bcd8 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 16:59:47 +0200 Subject: [PATCH 05/22] logs --- pkg/port/cli/integration.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/port/cli/integration.go b/pkg/port/cli/integration.go index 9db5604..a9fed93 100644 --- a/pkg/port/cli/integration.go +++ b/pkg/port/cli/integration.go @@ -28,8 +28,8 @@ func (c *PortClient) CreateIntegration(i *port.Integration) (*port.Integration, resp, err := c.Client.R(). SetBody(parseIntegration(i)). SetResult(&pb). - SetQueryParam("upsert", "true"). Post("v1/integration") + klog.Infof("Creating integration: %v", resp) if err != nil { return nil, err } @@ -44,7 +44,7 @@ func (c *PortClient) GetIntegration(stateKey string) (*port.Integration, error) resp, err := c.Client.R(). SetResult(&pb). Get(fmt.Sprintf("v1/integration/%s", stateKey)) - klog.Infof("Integration: %v", pb) + klog.Infof("Integration: %v", resp) if err != nil { return nil, err } From 31c9f7c2b983973e8048c44f79bf8955a3243523 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 19:15:31 +0200 Subject: [PATCH 06/22] assets and docker file --- Dockerfile | 2 ++ pkg/event_handler/event_handler.go | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7a9b264..ce32c8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM gcr.io/distroless/static-debian11 +COPY assets /usr/bin/assets + USER nonroot:nonroot ENTRYPOINT ["/usr/bin/port-k8s-exporter"] diff --git a/pkg/event_handler/event_handler.go b/pkg/event_handler/event_handler.go index b75e394..401887e 100644 --- a/pkg/event_handler/event_handler.go +++ b/pkg/event_handler/event_handler.go @@ -17,11 +17,14 @@ type IStoppableRsync interface { func Start(eventListener IListener, initControllerHandler func() (IStoppableRsync, error)) error { controllerHandler, err := initControllerHandler() if err != nil { - return err + utilruntime.HandleError(fmt.Errorf("error resyncing: %s", err.Error())) } return eventListener.Run(func() { klog.Infof("Resync request received. Recreating controllers for the new port configuration") + if controllerHandler != nil { + controllerHandler.Stop() + } controllerHandler.Stop() newController, resyncErr := initControllerHandler() controllerHandler = newController From ec4e6a7923d1a1136afac5fb5dd47f631cd26d5c Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 19:20:36 +0200 Subject: [PATCH 07/22] assets and docker file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ce32c8f..fa15b89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM gcr.io/distroless/static-debian11 -COPY assets /usr/bin/assets +COPY assets/ /usr/bin USER nonroot:nonroot From 7d15104dcbfc53e7e688ddaca366a907561f9ac3 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 19:29:32 +0200 Subject: [PATCH 08/22] assets and docker file --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5b76944..779c423 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,6 +49,7 @@ jobs: mkdir ../../musl-cross wget -P ~ https://musl.cc/aarch64-linux-musl-cross.tgz tar -xvf ~/aarch64-linux-musl-cross.tgz -C ../../musl-cross + ls assets - name: Run GoReleaser uses: goreleaser/goreleaser-action@v3 From 64c65f3ede5b28fcce20c51180be6d1b20671c37 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 19:31:23 +0200 Subject: [PATCH 09/22] assets and docker file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fa15b89..1882ae6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM gcr.io/distroless/static-debian11 -COPY assets/ /usr/bin +COPY assets /usr/bin USER nonroot:nonroot From 5cf661b48c7c2f052ac226ae8749f7a059666792 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 19:46:56 +0200 Subject: [PATCH 10/22] assets and docker file --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1882ae6..b2d968b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM gcr.io/distroless/static-debian11 +FROM alpine -COPY assets /usr/bin +COPY assets/ /usr/bin USER nonroot:nonroot From fbd61f67174f0c4151247c7bae1d23d23b9458eb Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 19:47:21 +0200 Subject: [PATCH 11/22] assets and docker file --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index b2d968b..9f67bdc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM alpine +COPY . . +RUN ls -l + COPY assets/ /usr/bin USER nonroot:nonroot From bd4f19c0f803dbda54ec34d4d3c8db48a9d6d7b9 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 19:53:47 +0200 Subject: [PATCH 12/22] assets and docker file --- .goreleaser.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 55cacb5..da71a6e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -33,6 +33,8 @@ dockers: - "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.version={{.Version}}" - "--platform=linux/amd64" + extra_files: + - assets/ - image_templates: - "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64v8" use: buildx @@ -44,6 +46,8 @@ dockers: - "--label=org.opencontainers.image.revision={{.FullCommit}}" - "--label=org.opencontainers.image.version={{.Version}}" - "--platform=linux/arm64/v8" + extra_files: + - assets/ docker_manifests: - name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}" image_templates: From 353c23e7739c1f74cbf1c91a9f4e8e2a3c96b493 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 19:57:13 +0200 Subject: [PATCH 13/22] assets and docker file --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f67bdc..b2d968b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,5 @@ FROM alpine -COPY . . -RUN ls -l - COPY assets/ /usr/bin USER nonroot:nonroot From 4f00f9df9cce57d4c590953cbbc455db8b85425a Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 20:07:58 +0200 Subject: [PATCH 14/22] assets and docker file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b2d968b..fa15b89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine +FROM gcr.io/distroless/static-debian11 COPY assets/ /usr/bin From 928f8c84625dce9799951468621842e405a9aa83 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 20:13:47 +0200 Subject: [PATCH 15/22] assets and docker file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fa15b89..41ec2a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM gcr.io/distroless/static-debian11 -COPY assets/ /usr/bin +COPY assets/ /usr/bin/assets USER nonroot:nonroot From dac115710ef12e67bc52d3aed77974445c3f3508 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 20:25:46 +0200 Subject: [PATCH 16/22] assets and docker file --- pkg/defaults/init.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index 6e9b3ba..1d0063c 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -1,10 +1,13 @@ package defaults import ( + "fmt" "github.com/port-labs/port-k8s-exporter/pkg/port" "github.com/port-labs/port-k8s-exporter/pkg/port/cli" "github.com/port-labs/port-k8s-exporter/pkg/port/integration" "k8s.io/klog/v2" + "log" + "os" ) func getEventListenerConfig(eventListenerType string) *port.EventListenerSettings { @@ -25,6 +28,12 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) CreateMissingRelatedEntities: applicationConfig.CreateMissingRelatedEntities, } + path, err := os.Getwd() + if err != nil { + log.Println(err) + } + fmt.Println(path) + if err != nil { klog.Infof("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) klog.Infof("Creating integration") From 572a4a5dd8159d86ce5f5dd686330f3f6e293619 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 20:25:57 +0200 Subject: [PATCH 17/22] assets and docker file --- pkg/defaults/init.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index 1d0063c..f6c4d64 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -1,7 +1,6 @@ package defaults import ( - "fmt" "github.com/port-labs/port-k8s-exporter/pkg/port" "github.com/port-labs/port-k8s-exporter/pkg/port/cli" "github.com/port-labs/port-k8s-exporter/pkg/port/integration" @@ -32,7 +31,7 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) if err != nil { log.Println(err) } - fmt.Println(path) + klog.Infof(path) if err != nil { klog.Infof("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) From c4c97ae5e0d044968cae370fcc52425f8680bcb9 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 20:32:52 +0200 Subject: [PATCH 18/22] assets and docker file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 41ec2a8..3391bf8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM gcr.io/distroless/static-debian11 -COPY assets/ /usr/bin/assets +COPY assets/ /assets USER nonroot:nonroot From cee8cdb06993f777c7464b255dc4a491cbe78331 Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 20:34:05 +0200 Subject: [PATCH 19/22] assets and docker file --- pkg/defaults/init.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index f6c4d64..6e9b3ba 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -5,8 +5,6 @@ import ( "github.com/port-labs/port-k8s-exporter/pkg/port/cli" "github.com/port-labs/port-k8s-exporter/pkg/port/integration" "k8s.io/klog/v2" - "log" - "os" ) func getEventListenerConfig(eventListenerType string) *port.EventListenerSettings { @@ -27,12 +25,6 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) CreateMissingRelatedEntities: applicationConfig.CreateMissingRelatedEntities, } - path, err := os.Getwd() - if err != nil { - log.Println(err) - } - klog.Infof(path) - if err != nil { klog.Infof("Could not get integration with state key %s, error: %s", applicationConfig.StateKey, err.Error()) klog.Infof("Creating integration") From 17b3bd6c2197b37a8cf2b8d3719126ce48efe49d Mon Sep 17 00:00:00 2001 From: yair Date: Thu, 28 Dec 2023 22:47:43 +0200 Subject: [PATCH 20/22] removed unwanted logs --- .github/workflows/release.yml | 1 - pkg/defaults/init.go | 1 - pkg/port/cli/integration.go | 3 --- 3 files changed, 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 779c423..5b76944 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,7 +49,6 @@ jobs: mkdir ../../musl-cross wget -P ~ https://musl.cc/aarch64-linux-musl-cross.tgz tar -xvf ~/aarch64-linux-musl-cross.tgz -C ../../musl-cross - ls assets - name: Run GoReleaser uses: goreleaser/goreleaser-action@v3 diff --git a/pkg/defaults/init.go b/pkg/defaults/init.go index 6e9b3ba..e0f5521 100644 --- a/pkg/defaults/init.go +++ b/pkg/defaults/init.go @@ -47,7 +47,6 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) // Handle a deprecated case where resources are provided in config file return integration.CreateIntegration(portClient, applicationConfig.StateKey, applicationConfig.EventListenerType, defaultIntegrationConfig) } else { - klog.Infof("integration : %v", existingIntegration) klog.Infof("Integration with state key %s already exists, patching it", applicationConfig.StateKey) integrationPatch := &port.Integration{ EventListener: getEventListenerConfig(applicationConfig.EventListenerType), diff --git a/pkg/port/cli/integration.go b/pkg/port/cli/integration.go index a9fed93..250ec18 100644 --- a/pkg/port/cli/integration.go +++ b/pkg/port/cli/integration.go @@ -3,7 +3,6 @@ package cli import ( "fmt" "github.com/port-labs/port-k8s-exporter/pkg/port" - "k8s.io/klog/v2" ) func parseIntegration(i *port.Integration) *port.Integration { @@ -29,7 +28,6 @@ func (c *PortClient) CreateIntegration(i *port.Integration) (*port.Integration, SetBody(parseIntegration(i)). SetResult(&pb). Post("v1/integration") - klog.Infof("Creating integration: %v", resp) if err != nil { return nil, err } @@ -44,7 +42,6 @@ func (c *PortClient) GetIntegration(stateKey string) (*port.Integration, error) resp, err := c.Client.R(). SetResult(&pb). Get(fmt.Sprintf("v1/integration/%s", stateKey)) - klog.Infof("Integration: %v", resp) if err != nil { return nil, err } From 7fc78933b1010f8ea438b740ffe02f2a8051b5d7 Mon Sep 17 00:00:00 2001 From: yair Date: Sun, 31 Dec 2023 10:42:16 +0200 Subject: [PATCH 21/22] updating app type --- pkg/port/integration/integration.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/port/integration/integration.go b/pkg/port/integration/integration.go index 5af4ba1..e0afc4c 100644 --- a/pkg/port/integration/integration.go +++ b/pkg/port/integration/integration.go @@ -57,6 +57,8 @@ func DeleteIntegration(portClient *cli.PortClient, stateKey string) error { } func PatchIntegration(portClient *cli.PortClient, stateKey string, integration *port.Integration) error { + // Fixing an incorrect app type caused from previous versions (kubernetes -> K8S EXPORTER) + integration.InstallationAppType = "K8S EXPORTER" _, err := portClient.Authenticate(context.Background(), portClient.ClientID, portClient.ClientSecret) if err != nil { return fmt.Errorf("error authenticating with Port: %v", err) From c5949183dca2d0de3b60724e209f3f29c7133c51 Mon Sep 17 00:00:00 2001 From: yair Date: Sun, 31 Dec 2023 11:39:47 +0200 Subject: [PATCH 22/22] remove type override --- pkg/port/integration/integration.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/port/integration/integration.go b/pkg/port/integration/integration.go index e0afc4c..5af4ba1 100644 --- a/pkg/port/integration/integration.go +++ b/pkg/port/integration/integration.go @@ -57,8 +57,6 @@ func DeleteIntegration(portClient *cli.PortClient, stateKey string) error { } func PatchIntegration(portClient *cli.PortClient, stateKey string, integration *port.Integration) error { - // Fixing an incorrect app type caused from previous versions (kubernetes -> K8S EXPORTER) - integration.InstallationAppType = "K8S EXPORTER" _, err := portClient.Authenticate(context.Background(), portClient.ClientID, portClient.ClientSecret) if err != nil { return fmt.Errorf("error authenticating with Port: %v", err)