@@ -2,7 +2,6 @@ package cli
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"fmt"
7
6
"log"
8
7
"strconv"
@@ -20,16 +19,13 @@ import (
20
19
"sigs.k8s.io/controller-runtime/pkg/client/config"
21
20
22
21
lhv1b1 "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta1"
23
- promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
24
22
"github.com/spf13/cobra"
25
23
)
26
24
27
25
var scaleDownReplicasWaitTime = 5 * time .Minute
28
26
29
27
const (
30
28
prometheusNamespace = "monitoring"
31
- prometheusName = "k8s"
32
- prometheusStatefulSetName = "prometheus-k8s"
33
29
ekcoNamespace = "kurl"
34
30
ekcoDeploymentName = "ekc-operator"
35
31
pvmigrateScaleDownAnnotation = "kurl.sh/pvcmigrate-scale"
@@ -64,7 +60,6 @@ func NewLonghornRollbackMigrationReplicas(cli CLI) *cobra.Command {
64
60
return fmt .Errorf ("error creating client: %s" , err )
65
61
}
66
62
lhv1b1 .AddToScheme (cli .Scheme ())
67
- promv1 .AddToScheme (cli .Scheme ())
68
63
69
64
var l1b1Volumes lhv1b1.VolumeList
70
65
if err := cli .List (cmd .Context (), & l1b1Volumes , client .InNamespace (longhornNamespace )); err != nil {
@@ -136,7 +131,6 @@ func NewLonghornPrepareForMigration(cli CLI) *cobra.Command {
136
131
return fmt .Errorf ("error creating client: %s" , err )
137
132
}
138
133
lhv1b1 .AddToScheme (cli .Scheme ())
139
- promv1 .AddToScheme (cli .Scheme ())
140
134
141
135
var scaledDown bool
142
136
var nodes corev1.NodeList
@@ -256,46 +250,22 @@ func isPrometheusInstalled(ctx context.Context, cli client.Client) (bool, error)
256
250
return true , nil
257
251
}
258
252
259
- // scaleUpPrometheus scales up prometheus.
253
+ // scaleUpPrometheus scales up the prometheus operator .
260
254
func scaleUpPrometheus (ctx context.Context , cli client.Client ) error {
261
255
if installed , err := isPrometheusInstalled (ctx , cli ); err != nil {
262
- return fmt .Errorf ("error scaling down prometheus: %w" , err )
256
+ return fmt .Errorf ("error scaling up prometheus: %w" , err )
263
257
} else if ! installed {
264
258
return nil
265
259
}
266
260
267
- nsn := types.NamespacedName {Namespace : prometheusNamespace , Name : prometheusName }
268
- var prometheus promv1.Prometheus
269
- if err := cli .Get (ctx , nsn , & prometheus ); err != nil {
270
- if errors .IsNotFound (err ) {
271
- return nil
272
- }
273
- return fmt .Errorf ("error getting prometheus: %w" , err )
274
- }
275
- replicasStr , ok := prometheus .Annotations [pvmigrateScaleDownAnnotation ]
276
- if ! ok {
277
- return fmt .Errorf ("error reading original replicas from the prometheus annotation: not found" )
278
- }
279
- origReplicas , err := strconv .Atoi (replicasStr )
280
- if err != nil {
281
- return fmt .Errorf ("error converting replicas annotation to integer: %w" , err )
282
- }
283
- patch := map [string ]interface {}{
284
- "metadata" : map [string ]interface {}{
285
- "annotations" : map [string ]interface {}{
286
- pvmigrateScaleDownAnnotation : nil ,
287
- },
288
- },
289
- "spec" : map [string ]interface {}{
290
- "replicas" : origReplicas ,
291
- },
292
- }
293
- rawPatch , err := json .Marshal (patch )
294
- if err != nil {
295
- return fmt .Errorf ("error creating prometheus patch: %w" , err )
261
+ var dep appsv1.Deployment
262
+ if err := cli .Get (ctx , types.NamespacedName {Namespace : prometheusNamespace , Name : "prometheus-operator" }, & dep ); err != nil {
263
+ return fmt .Errorf ("error getting prometheus operator deployment: %w" , err )
296
264
}
297
- if err := cli .Patch (ctx , & prometheus , client .RawPatch (types .MergePatchType , rawPatch )); err != nil {
298
- return fmt .Errorf ("error scaling prometheus: %w" , err )
265
+
266
+ dep .Spec .Replicas = ptr .To (int32 (1 ))
267
+ if err := cli .Update (ctx , & dep ); err != nil {
268
+ return fmt .Errorf ("error scaling up prometheus operator: %w" , err )
299
269
}
300
270
return nil
301
271
}
0 commit comments