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

chideat / valkey-operator / 13214360144

08 Feb 2025 09:25AM UTC coverage: 13.534%. First build
13214360144

push

github

web-flow
feat: added features for user, added suit tests (#2)

* chore: updated github actions

* feat: added user recocile, added suit tests

* fix: upgrade x/net for high cve

* fix: update test command

* chore: updated github actions

* chore: updated docker file

108 of 501 new or added lines in 31 files covered. (21.56%)

3048 of 22521 relevant lines covered (13.53%)

0.15 hits per line

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

48.84
/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/config"
35
        "github.com/chideat/valkey-operator/internal/ops"
36
)
37

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

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

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

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

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

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

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

93
        // ================ setup default ===================
94

95
        // _ = instance.Default()
96

97
        // ================ setup default end ===================
98

NEW
99
        return r.Engine.Run(ctx, &instance)
×
100
}
101

102
// SetupWithManager sets up the controller with the Manager.
103
func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
×
104
        return ctrl.NewControllerManagedBy(mgr).
×
NEW
105
                For(&v1alpha1.Cluster{}).
×
NEW
106
                WithOptions(controller.Options{MaxConcurrentReconciles: 8}).
×
NEW
107
                Owns(&appsv1.StatefulSet{}).
×
NEW
108
                Owns(&corev1.Service{}).
×
NEW
109
                Owns(&corev1.ConfigMap{}).
×
NEW
110
                Owns(&corev1.Secret{}).
×
111
                Complete(r)
×
112
}
×
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

© 2025 Coveralls, Inc