-
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… (
#15)
- Loading branch information
Showing
8 changed files
with
106 additions
and
26 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"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" | ||
) | ||
|
||
func NewIntegration(portClient *cli.PortClient, k8sConfig clientcmd.ClientConfig, stateKey string) error { | ||
|
||
k8sRawConfig, err := k8sConfig.RawConfig() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
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 { | ||
return fmt.Errorf("error authenticating with Port: %v", err) | ||
} | ||
|
||
_, err = portClient.CreateIntegration(integration) | ||
if err != nil { | ||
return fmt.Errorf("error creating Port integration: %v", err) | ||
} | ||
return 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