Skip to content

Commit

Permalink
fix #4167 : Default integrationPlatform created at operator startup d…
Browse files Browse the repository at this point in the history
…ose not honor OPERATOR_ID config
  • Loading branch information
valdar committed Mar 28, 2023
1 parent 3280f32 commit 937af80
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/cmd/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"time"

"github.com/pkg/errors"
"k8s.io/klog/v2"

"go.uber.org/automaxprocs/maxprocs"
"go.uber.org/zap"
Expand All @@ -46,8 +47,6 @@ import (
"k8s.io/apimachinery/pkg/selection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"

"sigs.k8s.io/controller-runtime/pkg/cache"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand Down Expand Up @@ -243,20 +242,26 @@ func Run(healthPort, monitoringPort int32, leaderElection bool, leaderElectionID

// findOrCreateIntegrationPlatform create default integration platform in operator namespace if not already exists.
func findOrCreateIntegrationPlatform(ctx context.Context, c client.Client, operatorNamespace string) error {
operatorID := defaults.OperatorID()
var platformName string
if defaults.OperatorID() != "" {
platformName = defaults.OperatorID()
if operatorID != "" {
platformName = operatorID
} else {
platformName = platform.DefaultPlatformName
}

if pl, err := kubernetes.GetIntegrationPlatform(ctx, c, platformName, operatorNamespace); pl == nil || k8serrors.IsNotFound(err) {
defaultPlatform := v1.NewIntegrationPlatform(operatorNamespace, platformName)

if defaultPlatform.Labels == nil {
defaultPlatform.Labels = make(map[string]string)
}
defaultPlatform.Labels["camel.apache.org/platform.generated"] = "true"

if operatorID != "" {
defaultPlatform.SetOperatorID(operatorID)
}

if _, err := c.CamelV1().IntegrationPlatforms(operatorNamespace).Create(ctx, &defaultPlatform, metav1.CreateOptions{}); err != nil {
return err
}
Expand Down

0 comments on commit 937af80

Please sign in to comment.