Skip to content

Commit 9c14d19

Browse files
author
Mohd Uzair
authored
Merge pull request #562 from MUzairS15/MUzairS15/add-missing-commit
add health check
2 parents 5a3ddc8 + 7eb9a90 commit 9c14d19

File tree

6 files changed

+60
-12
lines changed

6 files changed

+60
-12
lines changed

controllers/broker_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"context"
2121

2222
"github.com/go-logr/logr"
23-
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423
appsv1 "k8s.io/api/apps/v1"
24+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/runtime"
2626
"k8s.io/client-go/kubernetes"
2727
"k8s.io/client-go/rest"

controllers/meshsync_controller.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"context"
2121

2222
"github.com/go-logr/logr"
23-
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423
appsv1 "k8s.io/api/apps/v1"
24+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/runtime"
2626
"k8s.io/client-go/kubernetes"
2727
"k8s.io/client-go/rest"
@@ -31,6 +31,7 @@ import (
3131

3232
mesheryv1alpha1 "github.com/layer5io/meshery-operator/api/v1alpha1"
3333
brokerpackage "github.com/layer5io/meshery-operator/pkg/broker"
34+
"github.com/layer5io/meshery-operator/pkg/meshsync"
3435
meshsyncpackage "github.com/layer5io/meshery-operator/pkg/meshsync"
3536
"github.com/layer5io/meshery-operator/pkg/utils"
3637
kubeerror "k8s.io/apimachinery/pkg/api/errors"
@@ -81,6 +82,11 @@ func (r *MeshSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
8182
return ctrl.Result{}, ErrReconcileMeshsync(err)
8283
}
8384

85+
err = meshsync.CheckHealth(ctx, baseResource, r.Clientset)
86+
if err != nil {
87+
return ctrl.Result{Requeue: true}, ErrCheckHealth(err)
88+
}
89+
8490
// Patch the meshsync resource
8591
patch, err := utils.Marshal(baseResource)
8692
if err != nil {

main.go

-2
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ func main() {
6868
LeaderElectionNamespace: namespace,
6969
})
7070
if err != nil {
71-
fmt.Println("RERER")
7271
setupLog.Error(err, "unable to start manager")
7372
os.Exit(1)
7473
}
7574

7675
clientset, err := kubernetes.NewForConfig(mgr.GetConfig())
7776
if err != nil {
78-
fmt.Println("RERER-222")
7977
setupLog.Error(err, "unable to initialize clientset")
8078
os.Exit(1)
8179
}

pkg/broker/error.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ const (
2828
)
2929

3030
func ErrGettingResource(err error) error {
31-
return errors.New(ErrGettingResourceCode + ":" + "Unable to get resource")
31+
return errors.New(ErrGettingResourceCode + ":" + "Unable to get resource" + err.Error())
3232
}
3333

3434
func ErrGettingEndpoint(err error) error {
35-
return errors.New(ErrGettingEndpointCode + ":" + "Unable to get endpoint")
35+
return errors.New(ErrGettingEndpointCode + ":" + "Unable to get endpoint" + err.Error())
3636
}
3737

3838
func ErrReplicasNotReady(reason string) error {
39-
return errors.New(ErrReplicasNotReadyCode + ":" + "The replicas are not ready")
39+
return errors.New(ErrReplicasNotReadyCode + ":" + "The replicas are not ready" + reason)
4040
}
4141

4242
func ErrConditionFalse(reason string) error {
43-
return errors.New(ErrConditionFalseCode + ":" + "The condition is false")
43+
return errors.New(ErrConditionFalseCode + ":" + "The condition is false" + reason)
4444
}

pkg/meshsync/error.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2023 Layer5, Inc.
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 meshsync
18+
19+
import (
20+
"errors"
21+
)
22+
23+
const (
24+
ErrGettingResourceCode = "1013"
25+
ErrReplicasNotReadyCode = "1014"
26+
ErrConditionFalseCode = "1015"
27+
ErrGettingEndpointCode = "1016"
28+
)
29+
30+
func ErrGettingResource(err error) error {
31+
return errors.New(ErrGettingResourceCode + ":" + "Unable to get resource" + err.Error())
32+
}
33+
34+
func ErrGettingEndpoint(err error) error {
35+
return errors.New(ErrGettingEndpointCode + ":" + "Unable to get endpoint" + err.Error())
36+
}
37+
38+
func ErrReplicasNotReady(reason string) error {
39+
return errors.New(ErrReplicasNotReadyCode + ":" + "The replicas are not ready" + reason)
40+
}
41+
42+
func ErrConditionFalse(reason string) error {
43+
return errors.New(ErrConditionFalseCode + ":" + "The condition is false" + reason)
44+
}

pkg/meshsync/meshsync.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ func getServerObject(namespace, name string, replicas int32, url string) Object
5656
func CheckHealth(ctx context.Context, m *mesheryv1alpha1.MeshSync, client *kubernetes.Clientset) error {
5757
obj, err := client.AppsV1().Deployments(m.ObjectMeta.Namespace).Get(ctx, m.ObjectMeta.Name, metav1.GetOptions{})
5858
if err != nil {
59-
return err
59+
return ErrGettingResource(err)
6060
}
6161

6262
if obj.Status.Replicas != obj.Status.ReadyReplicas {
6363
if len(obj.Status.Conditions) > 0 {
64-
return err
64+
return ErrReplicasNotReady(obj.Status.Conditions[0].Reason)
6565
}
66-
return err
66+
return ErrReplicasNotReady("Condition Unknown")
6767
}
6868

6969
if len(obj.Status.Conditions) > 0 && (obj.Status.Conditions[0].Status == corev1.ConditionFalse || obj.Status.Conditions[0].Status == corev1.ConditionUnknown) {
70-
return err
70+
return ErrConditionFalse(obj.Status.Conditions[0].Reason)
7171
}
7272

7373
return nil

0 commit comments

Comments
 (0)