Skip to content

Commit

Permalink
Refector cluster status code
Browse files Browse the repository at this point in the history
Signed-off-by: Imtiaz Uddin <[email protected]>
  • Loading branch information
Imtiaz246 authored and tamalsaha committed Oct 8, 2023
1 parent bb7530d commit 34884d4
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 210 deletions.
3 changes: 1 addition & 2 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
identityv1alpha1 "kubeops.dev/ui-server/apis/identity/v1alpha1"
policyinstall "kubeops.dev/ui-server/apis/policy/install"
policyapi "kubeops.dev/ui-server/apis/policy/v1alpha1"
"kubeops.dev/ui-server/pkg/clusterstatus"
projectquotacontroller "kubeops.dev/ui-server/pkg/controllers/projectquota"
"kubeops.dev/ui-server/pkg/graph"
"kubeops.dev/ui-server/pkg/metricshandler"
Expand Down Expand Up @@ -255,7 +254,7 @@ func (c completedConfig) New(ctx context.Context) (*UIServer, error) {
os.Exit(1)
}

if err := mgr.Add(manager.RunnableFunc(clusterstatus.StartClusterStatusPuller(mgr))); err != nil {
if err := mgr.Add(manager.RunnableFunc(clusterstatusstorage.StartClusterStatusPuller(mgr))); err != nil {
setupLog.Error(err, "unable to set up cluster status puller")
os.Exit(1)
}
Expand Down
93 changes: 0 additions & 93 deletions pkg/clusterstatus/helpers.go

This file was deleted.

99 changes: 0 additions & 99 deletions pkg/clusterstatus/status.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package clusterstatus
import (
goctx "context"

core "k8s.io/api/core/v1"
appsv1 "k8s.io/api/apps/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

const (
Expand All @@ -39,9 +39,9 @@ type FluxCDStatus struct {
Message string `json:"message,omitempty"`
}

func getFluxCDStatus(config *rest.Config) (FluxCDStatus, error) {
func getFluxCDStatus(mgr manager.Manager) (FluxCDStatus, error) {
status := FluxCDStatus{}
if err := checkFluxCRDRegistered(config); err != nil {
if err := checkFluxCRDRegistered(mgr.GetConfig()); err != nil {
if kerr.IsNotFound(err) || meta.IsNoMatchError(err) {
status.Installed = false
status.Message = "FluxCD CRDs HelmReleases and HelmRepositories are not registered"
Expand All @@ -50,13 +50,11 @@ func getFluxCDStatus(config *rest.Config) (FluxCDStatus, error) {
return status, err
}

kc, err := kubernetes.NewForConfig(config)
if err != nil {
return status, err
}
kc := mgr.GetClient()

srcCtrl, err := kc.AppsV1().Deployments(core.NamespaceAll).List(goctx.Background(), metav1.ListOptions{
FieldSelector: "metadata.name=source-controller",
srcCtrl := appsv1.DeploymentList{}
err := kc.List(goctx.Background(), &srcCtrl, client.MatchingFields{
"metadata.name": "source-controller",
})
if err != nil {
return status, err
Expand All @@ -75,8 +73,9 @@ func getFluxCDStatus(config *rest.Config) (FluxCDStatus, error) {
return status, nil
}

helmCtrl, err := kc.AppsV1().Deployments(core.NamespaceAll).List(goctx.Background(), metav1.ListOptions{
FieldSelector: "metadata.name=helm-controller",
helmCtrl := appsv1.DeploymentList{}
err = kc.List(goctx.Background(), &helmCtrl, client.MatchingFields{
"metadata.name": "helm-controller",
})
if err != nil {
return status, err
Expand Down
Loading

0 comments on commit 34884d4

Please sign in to comment.