Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yairsimantov20 committed Dec 13, 2023
1 parent 25254fb commit 1eef152
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ func main() {

_, err = integration.GetIntegrationConfig(portClient, stateKey)
if err != nil {
err = integration.NewIntegration(portClient, stateKey, exporterConfig)
if exporterConfig == nil {
klog.Fatalf("The integration does not exist and no config file was provided")
}
err = integration.NewIntegration(portClient, exporterConfig, exporterConfig.Resources)
if err != nil {
klog.Fatalf("Error creating K8s integration: %s", err.Error())
}
}
cli.WithHeader("User-Agent", fmt.Sprintf("port-k8s-exporter/0.1 (statekey/%s)", exporterConfig.StateKey))(portClient)

klog.Info("Starting controllers handler")
handler, _ := InitiateHandler(exporterConfig, k8sClient, portClient)
Expand Down
16 changes: 9 additions & 7 deletions pkg/event_listener/polling/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import (
)

type PollingHandler struct {
ticker *time.Ticker
stateKey string
portClient *cli.PortClient
ticker *time.Ticker
stateKey string
portClient *cli.PortClient
pollingRate int
}

func NewPollingHandler(pollingRate int, stateKey string, portClient *cli.PortClient) *PollingHandler {
rv := &PollingHandler{
ticker: time.NewTicker(time.Second * time.Duration(pollingRate)),
stateKey: stateKey,
portClient: portClient,
ticker: time.NewTicker(time.Second * time.Duration(pollingRate)),
stateKey: stateKey,
portClient: portClient,
pollingRate: pollingRate,
}
return rv
}
Expand All @@ -44,7 +46,7 @@ func (h *PollingHandler) Run(resync func()) {
klog.Infof("Received signal %v: terminating\n", sig)
run = false
case <-h.ticker.C:
klog.Infof("Polling event listener iteration after %d seconds. Checking for changes...", h.ticker.C)
klog.Infof("Polling event listener iteration after %d seconds. Checking for changes...", h.pollingRate)
configuration, err := integration.GetIntegrationConfig(h.portClient, h.stateKey)
if err != nil {
klog.Errorf("error resyncing: %s", err.Error())
Expand Down
15 changes: 14 additions & 1 deletion pkg/jq/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package jq
import (
"fmt"
"github.com/itchyny/gojq"
"k8s.io/klog/v2"
"os"
"strings"
"sync"
)
Expand All @@ -12,11 +14,22 @@ var mutex = &sync.Mutex{}
func runJQQuery(jqQuery string, obj interface{}) (interface{}, error) {
query, err := gojq.Parse(jqQuery)
if err != nil {
klog.Warningf("failed to parse jq query: %s", jqQuery)
return nil, err
}
code, err := gojq.Compile(
query,
gojq.WithEnvironLoader(func() []string {
return os.Environ()
}),
)
if err != nil {
klog.Warningf("failed to compile jq query: %s", jqQuery)
return nil, err
}

mutex.Lock()
queryRes, ok := query.Run(obj).Next()
queryRes, ok := code.Run(obj).Next()
mutex.Unlock()

if !ok {
Expand Down
11 changes: 5 additions & 6 deletions pkg/port/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import (
"github.com/port-labs/port-k8s-exporter/pkg/port/cli"
)

func NewIntegration(portClient *cli.PortClient, stateKey string, exporterConfig *port.Config) error {

func NewIntegration(portClient *cli.PortClient, exporterConfig *port.Config, resources []port.Resource) error {
integration := &port.Integration{
Title: stateKey,
InstallationAppType: "kubernetes",
InstallationId: stateKey,
Title: exporterConfig.StateKey,
InstallationAppType: "K8S EXPORTER",
InstallationId: exporterConfig.StateKey,
EventListener: port.EventListenerSettings{
Type: exporterConfig.EventListenerType,
},
Config: &port.AppConfig{
Resources: exporterConfig.Resources,
Resources: resources,
},
}
_, err := portClient.Authenticate(context.Background(), portClient.ClientID, portClient.ClientSecret)
Expand Down
8 changes: 4 additions & 4 deletions pkg/port/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type (
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Identifier string `json:"identifier,omitempty"`
Default string `json:"default,omitempty"`
Default any `json:"default,omitempty"`
Icon string `json:"icon,omitempty"`
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
Expand Down Expand Up @@ -87,9 +87,9 @@ type (
Description string `json:"description"`
Schema BlueprintSchema `json:"schema"`
FormulaProperties map[string]BlueprintFormulaProperty `json:"formulaProperties"`
MirrorProperties map[string]BlueprintMirrorProperty `json:"mirrorProperties"`
MirrorProperties map[string]BlueprintMirrorProperty `json:"mirrorProperties,omitempty"`
ChangelogDestination *ChangelogDestination `json:"changelogDestination,omitempty"`
Relations map[string]Relation `json:"relations"`
Relations map[string]Relation `json:"relations,omitempty"`
}

Action struct {
Expand Down Expand Up @@ -147,7 +147,7 @@ type EntityMapping struct {
Identifier string `json:"identifier"`
Title string `json:"title"`
Blueprint string `json:"blueprint"`
Team string `json:"team"`
Team string `json:"team,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
Relations map[string]string `json:"relations,omitempty"`
}
Expand Down

0 comments on commit 1eef152

Please sign in to comment.