Skip to content

Commit

Permalink
Merge pull request #28 from port-labs/PORT-5858-default-resources-are…
Browse files Browse the repository at this point in the history
…-not-created

more logs and scorecards fix
  • Loading branch information
yairsimantov20 authored Dec 28, 2023
2 parents fcda795 + b7d805f commit e145cbb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions assets/defaults/scorecards.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"rules": [
{
"identifier": "highAvalabilityB",
"title": "Highly Available",
"title": "\"Wanted Replicas\" >= 1",
"level": "Bronze",
"query": {
"combinator": "and",
Expand All @@ -104,7 +104,7 @@
},
{
"identifier": "highAvalabilityS",
"title": "Highly Available",
"title": "\"Wanted Replicas\" >= 2",
"level": "Silver",
"query": {
"combinator": "and",
Expand All @@ -119,7 +119,7 @@
},
{
"identifier": "highAvalabilityG",
"title": "Highly Available",
"title": "\"Wanted Replicas\" >= 3",
"level": "Gold",
"query": {
"combinator": "and",
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"github.com/joho/godotenv"
"github.com/port-labs/port-k8s-exporter/pkg/port"
"k8s.io/klog/v2"
"strings"
)

Expand Down Expand Up @@ -57,8 +58,10 @@ func NewConfiguration() (*port.Config, error) {
c, err := GetConfigFile(ApplicationConfig.ConfigFilePath)
var fileNotFoundError *FileNotFoundError
if errors.As(err, &fileNotFoundError) {
klog.Infof("Config file not found, using defaults")
return overrides, nil
}
klog.Infof("Config file found")
v, err := json.Marshal(overrides)
if err != nil {
return nil, fmt.Errorf("failed loading configuration: %w", err)
Expand Down
8 changes: 8 additions & 0 deletions pkg/defaults/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func getEventListenerConfig(eventListenerType string) *port.EventListenerSetting
}

func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config) error {
klog.Infof("Initializing Port integration")
existingIntegration, err := integration.GetIntegration(portClient, applicationConfig.StateKey)
defaultIntegrationConfig := &port.IntegrationAppConfig{
Resources: applicationConfig.Resources,
Expand All @@ -25,28 +26,35 @@ func InitIntegration(portClient *cli.PortClient, applicationConfig *port.Config)
}

if err != nil {
klog.Infof("Integration does not exist, creating a new one")
// 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.
if defaultIntegrationConfig.Resources == nil && applicationConfig.CreateDefaultResources {
klog.Infof("Creating default resources")
if err := initializeDefaults(portClient, applicationConfig); err != nil {
klog.Warningf("Error initializing defaults: %s", err.Error())
klog.Warningf("The integration will start without default integration mapping and other default resources. Please create them manually in Port. ")
} else {
klog.Infof("Default resources created successfully")
return nil
}
}

klog.Infof("Could not create default resources, creating integration with no resources")
klog.Infof("Creating integration with config: %v", defaultIntegrationConfig)
// 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")
integrationPatch := &port.Integration{
EventListener: getEventListenerConfig(applicationConfig.EventListenerType),
}

// Handle a deprecated case where resources are provided in config file and integration exists from previous
//versions without a config
if existingIntegration.Config == nil {
klog.Infof("Integration exists without a config, patching it with default config: %v", defaultIntegrationConfig)
integrationPatch.Config = defaultIntegrationConfig
}

Expand Down

0 comments on commit e145cbb

Please sign in to comment.