• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

chideat / valkey-operator / 14173979426

31 Mar 2025 02:26PM UTC coverage: 10.247% (-3.3%) from 13.534%
14173979426

push

github

web-flow
feat: added webhooks

168 of 2201 new or added lines in 67 files covered. (7.63%)

1254 existing lines in 61 files now uncovered.

2074 of 20241 relevant lines covered (10.25%)

0.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

34.88
/internal/controller/cluster_controller.go
1
/*
2
Copyright 2024 chideat.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package controller
18

19
import (
20
        "context"
21
        "time"
22

23
        appsv1 "k8s.io/api/apps/v1"
24
        corev1 "k8s.io/api/core/v1"
25
        "k8s.io/apimachinery/pkg/api/errors"
26
        "k8s.io/apimachinery/pkg/runtime"
27
        "k8s.io/client-go/tools/record"
28
        ctrl "sigs.k8s.io/controller-runtime"
29
        "sigs.k8s.io/controller-runtime/pkg/client"
30
        "sigs.k8s.io/controller-runtime/pkg/controller"
31
        "sigs.k8s.io/controller-runtime/pkg/log"
32

33
        "github.com/chideat/valkey-operator/api/v1alpha1"
34
        "github.com/chideat/valkey-operator/internal/builder"
35
        "github.com/chideat/valkey-operator/internal/config"
36
        "github.com/chideat/valkey-operator/internal/ops"
37
)
38

39
// ClusterReconciler reconciles a Cluster object
40
type ClusterReconciler struct {
41
        client.Client
42
        Scheme        *runtime.Scheme
43
        EventRecorder record.EventRecorder
44
        Engine        *ops.OpEngine
45
}
46

47
// +kubebuilder:rbac:groups=valkey.buf.red,resources=clusters,verbs=get;list;watch;create;update;patch;delete
48
// +kubebuilder:rbac:groups=valkey.buf.red,resources=clusters/status,verbs=get;update;patch
49
// +kubebuilder:rbac:groups=valkey.buf.red,resources=clusters/finalizers,verbs=update
50

51
// Reconcile is part of the main kubernetes reconciliation loop which aims to
52
// move the current state of the cluster closer to the desired state.
53
func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
1✔
54
        logger := log.FromContext(ctx).WithValues("target", req.String())
1✔
55

1✔
56
        var instance v1alpha1.Cluster
1✔
57
        if err := r.Get(ctx, req.NamespacedName, &instance); errors.IsNotFound(err) {
1✔
58
                return ctrl.Result{}, nil
×
59
        } else if err != nil {
1✔
60
                logger.Error(err, "get resource failed")
×
61
                return ctrl.Result{}, err
×
62
        }
×
63

64
        // update default status
65
        if instance.Status.Phase == "" {
2✔
66
                // update status to creating
1✔
67
                r.EventRecorder.Eventf(&instance, corev1.EventTypeNormal, "Creating", "new instance request")
1✔
68

1✔
69
                instance.Status.Phase = v1alpha1.ClusterPhaseCreating
1✔
70
                if err := r.Status().Update(ctx, &instance); err != nil {
1✔
71
                        logger.Error(err, "update instance status failed")
×
72
                        if errors.IsNotFound(err) {
×
73
                                return ctrl.Result{}, nil
×
74
                        }
×
75
                        return ctrl.Result{}, err
×
76
                }
77
        }
78

79
        crVersion := instance.Annotations[builder.CRVersionKey]
1✔
80
        if crVersion == "" {
1✔
UNCOV
81
                if config.GetOperatorVersion() != "" {
×
UNCOV
82
                        if instance.Annotations == nil {
×
UNCOV
83
                                instance.Annotations = make(map[string]string)
×
UNCOV
84
                        }
×
85
                        // update crVersion to instance
NEW
86
                        instance.Annotations[builder.CRVersionKey] = config.GetOperatorVersion()
×
UNCOV
87
                        if err := r.Update(ctx, &instance); err != nil {
×
88
                                logger.Error(err, "update instance actor version failed")
×
89
                        }
×
UNCOV
90
                        return ctrl.Result{RequeueAfter: time.Second}, nil
×
91
                }
92
        }
93

94
        // ================ setup default ===================
95

96
        // _ = instance.Default()
97

98
        // ================ setup default end ===================
99

100
        return r.Engine.Run(ctx, &instance)
1✔
101
}
102

103
// SetupWithManager sets up the controller with the Manager.
104
func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
×
105
        return ctrl.NewControllerManagedBy(mgr).
×
106
                For(&v1alpha1.Cluster{}).
×
107
                WithOptions(controller.Options{MaxConcurrentReconciles: 8}).
×
108
                Owns(&appsv1.StatefulSet{}).
×
109
                Owns(&corev1.Service{}).
×
110
                Owns(&corev1.ConfigMap{}).
×
111
                Owns(&corev1.Secret{}).
×
112
                Complete(r)
×
113
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc