This commit is contained in:
37
pkg/health/health.go
Normal file
37
pkg/health/health.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
zitadelv1alpha1 "gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/api/v1alpha1"
|
||||
|
||||
"gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/pkg/deployment"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
type EndpointPolicy string
|
||||
|
||||
func IsClusterHealthy(ctx context.Context, client ctrlclient.Client, zitadel *zitadelv1alpha1.Cluster) (bool, error) {
|
||||
key := ctrlclient.ObjectKeyFromObject(zitadel)
|
||||
var dep appsv1.Deployment
|
||||
if err := client.Get(ctx, key, &dep); err != nil {
|
||||
return false, ctrlclient.IgnoreNotFound(err)
|
||||
}
|
||||
if dep.Status.ReadyReplicas != zitadel.Spec.Replicas {
|
||||
return false, nil
|
||||
}
|
||||
var endpoints corev1.Endpoints
|
||||
if err := client.Get(ctx, key, &endpoints); err != nil {
|
||||
return false, ctrlclient.IgnoreNotFound(err)
|
||||
}
|
||||
for _, subset := range endpoints.Subsets {
|
||||
for _, port := range subset.Ports {
|
||||
if port.Port == deployment.ZitadelPort {
|
||||
return len(subset.Addresses) > 0, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
Reference in New Issue
Block a user