-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When k8s exporter is up, start upsert request to port to update the i…
…ngeration
- Loading branch information
Showing
7 changed files
with
103 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -16,6 +16,10 @@ | |
|
||
.idea | ||
|
||
.vscode | ||
|
||
__debug_bin | ||
|
||
config.yaml | ||
|
||
deployments/k8s |
This file contains 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 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 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,9 @@ | ||
package k8s | ||
|
||
import "k8s.io/client-go/tools/clientcmd" | ||
|
||
func NewKubeConfig() clientcmd.ClientConfig { | ||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() | ||
configOverrides := &clientcmd.ConfigOverrides{} | ||
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides) | ||
} |
This file contains 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,35 @@ | ||
package k8s | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/port-labs/port-k8s-exporter/pkg/port" | ||
"github.com/port-labs/port-k8s-exporter/pkg/port/cli" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func NewIntegration(portClient *cli.PortClient, k8sConfig clientcmd.ClientConfig, stateKey string) { | ||
|
||
k8sRawConfig, err := k8sConfig.RawConfig() | ||
if err != nil { | ||
klog.Fatalf("Error getting K8s raw config: %s", err.Error()) | ||
} | ||
|
||
clusterName := k8sRawConfig.Contexts[k8sRawConfig.CurrentContext].Cluster | ||
|
||
integration := &port.Integration{ | ||
Title: clusterName, | ||
InstallationAppType: "kubernetes", | ||
InstallationId: stateKey, | ||
} | ||
_, err = portClient.Authenticate(context.Background(), portClient.ClientID, portClient.ClientSecret) | ||
if err != nil { | ||
klog.Errorf("error authenticating with Port: %v", err) | ||
} | ||
|
||
_, err = portClient.CreateIntegration(integration) | ||
if err != nil { | ||
klog.Fatalf("Error creating Port integration: %s", err.Error()) | ||
} | ||
} |
This file contains 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,23 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/port-labs/port-k8s-exporter/pkg/port" | ||
) | ||
|
||
func (c *PortClient) CreateIntegration(i *port.Integration) (*port.Integration, error) { | ||
pb := &port.ResponseBody{} | ||
resp, err := c.Client.R(). | ||
SetBody(i). | ||
SetResult(&pb). | ||
SetQueryParam("upsert", "true"). | ||
Post("v1/integration") | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !pb.OK { | ||
return nil, fmt.Errorf("failed to create integration, got: %s", resp.Body()) | ||
} | ||
return &pb.Integration, nil | ||
} |
This file contains 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