Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing commits #562

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/broker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"context"

"github.com/go-logr/logr"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down
8 changes: 7 additions & 1 deletion controllers/meshsync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"context"

"github.com/go-logr/logr"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -31,6 +31,7 @@ import (

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

err = meshsync.CheckHealth(ctx, baseResource, r.Clientset)
if err != nil {
return ctrl.Result{Requeue: true}, ErrCheckHealth(err)
}

// Patch the meshsync resource
patch, err := utils.Marshal(baseResource)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ func main() {
LeaderElectionNamespace: namespace,
})
if err != nil {
fmt.Println("RERER")
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

clientset, err := kubernetes.NewForConfig(mgr.GetConfig())
if err != nil {
fmt.Println("RERER-222")
setupLog.Error(err, "unable to initialize clientset")
os.Exit(1)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/broker/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ const (
)

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

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

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

func ErrConditionFalse(reason string) error {
return errors.New(ErrConditionFalseCode + ":" + "The condition is false")
return errors.New(ErrConditionFalseCode + ":" + "The condition is false" + reason)
}
44 changes: 44 additions & 0 deletions pkg/meshsync/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2023 Layer5, Inc.

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

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

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

package meshsync

import (
"errors"
)

const (
ErrGettingResourceCode = "1013"
ErrReplicasNotReadyCode = "1014"
ErrConditionFalseCode = "1015"
ErrGettingEndpointCode = "1016"
)

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

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

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

func ErrConditionFalse(reason string) error {
return errors.New(ErrConditionFalseCode + ":" + "The condition is false" + reason)
}
8 changes: 4 additions & 4 deletions pkg/meshsync/meshsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ func getServerObject(namespace, name string, replicas int32, url string) Object
func CheckHealth(ctx context.Context, m *mesheryv1alpha1.MeshSync, client *kubernetes.Clientset) error {
obj, err := client.AppsV1().Deployments(m.ObjectMeta.Namespace).Get(ctx, m.ObjectMeta.Name, metav1.GetOptions{})
if err != nil {
return err
return ErrGettingResource(err)
}

if obj.Status.Replicas != obj.Status.ReadyReplicas {
if len(obj.Status.Conditions) > 0 {
return err
return ErrReplicasNotReady(obj.Status.Conditions[0].Reason)
}
return err
return ErrReplicasNotReady("Condition Unknown")
}

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

return nil
Expand Down
Loading