@@ -26,7 +26,6 @@ import (
26
26
"io/fs"
27
27
"log"
28
28
"net/http"
29
- "os"
30
29
"strings"
31
30
"time"
32
31
@@ -87,7 +86,6 @@ const (
87
86
databaseClusterAPIVersion = "everest.percona.com/v1alpha1"
88
87
restartAnnotationKey = "everest.percona.com/restart"
89
88
managedByKey = "everest.percona.com/managed-by"
90
- disableTelemetryEnvVar = "DISABLE_TELEMETRY"
91
89
// ContainerStateWaiting represents a state when container requires some
92
90
// operations being done in order to complete start up.
93
91
ContainerStateWaiting ContainerState = "waiting"
@@ -629,47 +627,96 @@ type InstallOperatorRequest struct {
629
627
SubscriptionConfig * olmv1alpha1.SubscriptionConfig
630
628
}
631
629
630
+ func mergeSubscriptionConfig (sub * olmv1alpha1.SubscriptionConfig , cfg * olmv1alpha1.SubscriptionConfig ) * olmv1alpha1.SubscriptionConfig {
631
+ if sub == nil {
632
+ sub = & olmv1alpha1.SubscriptionConfig {Env : []corev1.EnvVar {}}
633
+ }
634
+
635
+ if cfg == nil {
636
+ return sub
637
+ }
638
+
639
+ for _ , e := range cfg .Env {
640
+ found := false
641
+ for i , se := range sub .Env {
642
+ if e .Name == se .Name {
643
+ found = true
644
+ // If the environment variable is not the namespaces, just override it
645
+ if e .Name != EverestDBNamespacesEnvVar {
646
+ sub .Env [i ].Value = e .Value
647
+ break
648
+ }
649
+
650
+ // Merge the namespaces
651
+ subNamespaces := strings .Split (se .Value , "," )
652
+ cfgNamespaces := strings .Split (e .Value , "," )
653
+ namespacesMap := map [string ]struct {}{}
654
+ for _ , ns := range subNamespaces {
655
+ namespacesMap [ns ] = struct {}{}
656
+ }
657
+ for _ , ns := range cfgNamespaces {
658
+ namespacesMap [ns ] = struct {}{}
659
+ }
660
+ namespaces := []string {}
661
+ for ns := range namespacesMap {
662
+ namespaces = append (namespaces , ns )
663
+ }
664
+ sub .Env [i ].Value = strings .Join (namespaces , "," )
665
+
666
+ break
667
+ }
668
+ }
669
+ if ! found {
670
+ sub .Env = append (sub .Env , e )
671
+ }
672
+ }
673
+
674
+ return sub
675
+ }
676
+
632
677
// InstallOperator installs an operator via OLM.
633
678
func (k * Kubernetes ) InstallOperator (ctx context.Context , req InstallOperatorRequest ) error { //nolint:funlen
634
- disableTelemetry , ok := os .LookupEnv (disableTelemetryEnvVar )
635
- if ! ok || disableTelemetry != "true" {
636
- disableTelemetry = "false"
637
- }
638
- config := & olmv1alpha1.SubscriptionConfig {Env : []corev1.EnvVar {}}
639
- if req .SubscriptionConfig != nil {
640
- config = req .SubscriptionConfig
679
+ subscription , err := k .client .GetSubscription (ctx , req .Namespace , req .Name )
680
+ if err != nil && ! apierrors .IsNotFound (err ) {
681
+ return errors .Join (err , errors .New ("cannot get subscription" ))
641
682
}
642
- config .Env = append (config .Env , corev1.EnvVar {
643
- Name : disableTelemetryEnvVar ,
644
- Value : disableTelemetry ,
645
- })
646
- subscription := & olmv1alpha1.Subscription {
647
- TypeMeta : metav1.TypeMeta {
648
- Kind : olmv1alpha1 .SubscriptionKind ,
649
- APIVersion : olmv1alpha1 .SubscriptionCRDAPIVersion ,
650
- },
651
- ObjectMeta : metav1.ObjectMeta {
652
- Namespace : req .Namespace ,
653
- Name : req .Name ,
654
- },
655
- Spec : & olmv1alpha1.SubscriptionSpec {
656
- CatalogSource : req .CatalogSource ,
657
- CatalogSourceNamespace : req .CatalogSourceNamespace ,
658
- Package : req .Name ,
659
- Channel : req .Channel ,
660
- StartingCSV : req .StartingCSV ,
661
- InstallPlanApproval : req .InstallPlanApproval ,
662
- Config : config ,
663
- },
683
+ if apierrors .IsNotFound (err ) {
684
+ subscription = & olmv1alpha1.Subscription {
685
+ TypeMeta : metav1.TypeMeta {
686
+ Kind : olmv1alpha1 .SubscriptionKind ,
687
+ APIVersion : olmv1alpha1 .SubscriptionCRDAPIVersion ,
688
+ },
689
+ ObjectMeta : metav1.ObjectMeta {
690
+ Namespace : req .Namespace ,
691
+ Name : req .Name ,
692
+ },
693
+ Spec : & olmv1alpha1.SubscriptionSpec {
694
+ CatalogSource : req .CatalogSource ,
695
+ CatalogSourceNamespace : req .CatalogSourceNamespace ,
696
+ Package : req .Name ,
697
+ Channel : req .Channel ,
698
+ StartingCSV : req .StartingCSV ,
699
+ InstallPlanApproval : req .InstallPlanApproval ,
700
+ },
701
+ }
664
702
}
665
- subs , err := k .client .CreateSubscription (ctx , req .Namespace , subscription )
666
- if err != nil {
667
- return errors .Join (err , errors .New ("cannot create a subscription to install the operator" ))
703
+
704
+ subscription .Spec .Config = mergeSubscriptionConfig (subscription .Spec .Config , req .SubscriptionConfig )
705
+ if apierrors .IsNotFound (err ) {
706
+ _ , err := k .client .CreateSubscription (ctx , req .Namespace , subscription )
707
+ if err != nil {
708
+ return errors .Join (err , errors .New ("cannot create a subscription to install the operator" ))
709
+ }
710
+ } else {
711
+ _ , err := k .client .UpdateSubscription (ctx , req .Namespace , subscription )
712
+ if err != nil {
713
+ return errors .Join (err , errors .New ("cannot update a subscription to install the operator" ))
714
+ }
668
715
}
669
716
670
717
err = wait .PollUntilContextTimeout (ctx , pollInterval , pollDuration , false , func (ctx context.Context ) (bool , error ) {
671
718
k .l .Debugf ("Polling subscription %s/%s" , req .Namespace , req .Name )
672
- subs , err = k .client .GetSubscription (ctx , req .Namespace , req .Name )
719
+ subs , err : = k .client .GetSubscription (ctx , req .Namespace , req .Name )
673
720
if err != nil {
674
721
return false , errors .Join (err , fmt .Errorf ("cannot get an install plan for the operator subscription: %q" , req .Name ))
675
722
}
0 commit comments