-
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.
Merge pull request #19 from port-labs/PORT-5363-ui-for-the-kubernetes…
…-exporter-moving-the-config-into-port Port 5363 UI for the kubernetes exporter moving the config into port
- Loading branch information
Showing
28 changed files
with
1,278 additions
and
179 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
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 |
---|---|---|
@@ -1,60 +1,25 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/port-labs/port-k8s-exporter/pkg/port" | ||
"os" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type Entity struct { | ||
Mappings []port.EntityMapping | ||
} | ||
|
||
type Port struct { | ||
Entity Entity | ||
} | ||
|
||
type Selector struct { | ||
Query string | ||
} | ||
|
||
type Resource struct { | ||
Kind string | ||
Selector Selector | ||
Port Port | ||
} | ||
|
||
type Config struct { | ||
Resources []Resource | ||
ResyncInterval uint | ||
StateKey string | ||
} | ||
|
||
type KindConfig struct { | ||
Selector Selector | ||
Port Port | ||
} | ||
|
||
type AggregatedResource struct { | ||
Kind string | ||
KindConfigs []KindConfig | ||
} | ||
|
||
func New(filepath string, resyncInterval uint, stateKey string) (*Config, error) { | ||
c := &Config{ | ||
ResyncInterval: resyncInterval, | ||
StateKey: stateKey, | ||
} | ||
config, err := os.ReadFile(filepath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = yaml.Unmarshal(config, c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return c, nil | ||
var KafkaConfig = &KafkaConfiguration{} | ||
var PollingListenerRate uint | ||
|
||
var ApplicationConfig = &ApplicationConfiguration{} | ||
|
||
func Init() { | ||
// Kafka listener Configuration | ||
NewString(&KafkaConfig.Brokers, "event-listener-brokers", "localhost:9092", "Kafka event listener brokers") | ||
NewString(&KafkaConfig.SecurityProtocol, "event-listener-security-protocol", "plaintext", "Kafka event listener security protocol") | ||
NewString(&KafkaConfig.AuthenticationMechanism, "event-listener-authentication-mechanism", "none", "Kafka event listener authentication mechanism") | ||
|
||
// Polling listener Configuration | ||
NewUInt(&PollingListenerRate, "event-listener-polling-rate", 60, "Polling event listener polling rate") | ||
|
||
// Application Configuration | ||
NewString(&ApplicationConfig.ConfigFilePath, "config", "config.yaml", "Path to Port K8s Exporter config file. Required.") | ||
NewString(&ApplicationConfig.StateKey, "state-key", "my-k8s-exporter", "Port K8s Exporter state key id. Required.") | ||
NewUInt(&ApplicationConfig.ResyncInterval, "resync-interval", 0, "The re-sync interval in minutes. Optional.") | ||
NewString(&ApplicationConfig.PortBaseURL, "port-base-url", "https://api.getport.io", "Port base URL. Optional.") | ||
NewString(&ApplicationConfig.PortClientId, "port-client-id", "", "Port client id. Required.") | ||
NewString(&ApplicationConfig.PortClientSecret, "port-client-secret", "", "Port client secret. Required.") | ||
NewString(&ApplicationConfig.EventListenerType, "event-listener-type", "POLLING", "Event listener type, can be either POLLING or KAFKA. Optional.") | ||
} |
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,21 @@ | ||
package config | ||
|
||
type KafkaConfiguration struct { | ||
Brokers string | ||
SecurityProtocol string | ||
GroupID string | ||
AuthenticationMechanism string | ||
Username string | ||
Password string | ||
KafkaSecurityEnabled bool | ||
} | ||
|
||
type ApplicationConfiguration struct { | ||
ConfigFilePath string | ||
StateKey string | ||
ResyncInterval uint | ||
PortBaseURL string | ||
PortClientId string | ||
PortClientSecret string | ||
EventListenerType string | ||
} |
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,62 @@ | ||
package config | ||
|
||
import ( | ||
"flag" | ||
"github.com/port-labs/port-k8s-exporter/pkg/goutils" | ||
"github.com/port-labs/port-k8s-exporter/pkg/port" | ||
"gopkg.in/yaml.v2" | ||
"k8s.io/klog/v2" | ||
"k8s.io/utils/strings/slices" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var keys []string | ||
|
||
func prepareEnvKey(key string) string { | ||
newKey := strings.ToUpper(strings.ReplaceAll(key, "-", "_")) | ||
|
||
if slices.Contains(keys, newKey) { | ||
klog.Fatalf("Application Error : Found duplicate config key: %s", newKey) | ||
} | ||
|
||
keys = append(keys, newKey) | ||
return newKey | ||
} | ||
|
||
func NewString(v *string, key string, defaultValue string, description string) { | ||
value := goutils.GetStringEnvOrDefault(prepareEnvKey(key), defaultValue) | ||
flag.StringVar(v, key, value, description) | ||
} | ||
|
||
func NewUInt(v *uint, key string, defaultValue uint, description string) { | ||
value := uint(goutils.GetUintEnvOrDefault(prepareEnvKey(key), uint64(defaultValue))) | ||
flag.UintVar(v, key, value, description) | ||
} | ||
|
||
type FileNotFoundError struct { | ||
s string | ||
} | ||
|
||
func (e *FileNotFoundError) Error() string { | ||
return e.s | ||
} | ||
|
||
func GetConfigFile(filepath string, resyncInterval uint, stateKey string, eventListenerType string) (*port.Config, error) { | ||
c := &port.Config{ | ||
ResyncInterval: resyncInterval, | ||
StateKey: stateKey, | ||
EventListenerType: eventListenerType, | ||
} | ||
config, err := os.ReadFile(filepath) | ||
if err != nil { | ||
return c, &FileNotFoundError{err.Error()} | ||
} | ||
|
||
err = yaml.Unmarshal(config, c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return c, nil | ||
} |
Oops, something went wrong.