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

Resources health checks #3590

Merged
merged 10 commits into from
Apr 12, 2023
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
17 changes: 17 additions & 0 deletions api/core/core.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,17 @@
},
"title": "GroupVersionKind represents an objects Kubernetes API type data"
},
"v1HealthStatus": {
"type": "object",
"properties": {
"status": {
"type": "string"
},
"message": {
"type": "string"
}
}
},
"v1InventoryEntry": {
"type": "object",
"properties": {
Expand All @@ -910,6 +921,9 @@
"clusterName": {
"type": "string"
},
"health": {
"$ref": "#/definitions/v1HealthStatus"
},
"children": {
"type": "array",
"items": {
Expand Down Expand Up @@ -1105,6 +1119,9 @@
},
"info": {
"type": "string"
},
"health": {
"$ref": "#/definitions/v1HealthStatus"
}
}
},
Expand Down
9 changes: 8 additions & 1 deletion api/core/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ message NamespacedObjectReference {
string namespace = 2;
}

message HealthStatus {
string status = 1;
string message = 2;
}

message InventoryEntry {
string payload = 1;
string tenant = 2;
string clusterName = 3;
repeated InventoryEntry children = 4;
HealthStatus health = 4;
repeated InventoryEntry children = 5;
}

message Object {
Expand All @@ -80,6 +86,7 @@ message Object {
string uid = 4;
repeated GroupVersionKind inventory = 5;
string info = 6;
HealthStatus health = 7;
}

message Deployment {
Expand Down
5 changes: 4 additions & 1 deletion cmd/gitops-server/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/weaveworks/weave-gitops/core/nsaccess"
core "github.com/weaveworks/weave-gitops/core/server"
"github.com/weaveworks/weave-gitops/pkg/featureflags"
"github.com/weaveworks/weave-gitops/pkg/health"
"github.com/weaveworks/weave-gitops/pkg/kube"
"github.com/weaveworks/weave-gitops/pkg/server"
"github.com/weaveworks/weave-gitops/pkg/server/auth"
Expand Down Expand Up @@ -215,7 +216,9 @@ func runCmd(cmd *cobra.Command, args []string) error {
clustersManager := clustersmngr.NewClustersManager([]clustersmngr.ClusterFetcher{fetcher}, nsaccess.NewChecker(nsaccess.DefautltWegoAppRules), log)
clustersManager.Start(ctx)

coreConfig, err := core.NewCoreConfig(log, rest, clusterName, clustersManager)
healthChecker := health.NewHealthChecker()

coreConfig, err := core.NewCoreConfig(log, rest, clusterName, clustersManager, healthChecker)
if err != nil {
return fmt.Errorf("could not create core config: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion core/server/featureflags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/weaveworks/weave-gitops/core/server"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
"github.com/weaveworks/weave-gitops/pkg/featureflags"
"github.com/weaveworks/weave-gitops/pkg/health"
"github.com/weaveworks/weave-gitops/pkg/kube"
"k8s.io/client-go/rest"
)
Expand All @@ -36,7 +37,9 @@ func TestGetFeatureFlags(t *testing.T) {
fetcher.NewSingleClusterFetcher(cluster),
}, &nsChecker, logr.Discard())

cfg, err := server.NewCoreConfig(logr.Discard(), &rest.Config{}, "test", clustersManager)
hc := health.NewHealthChecker()

cfg, err := server.NewCoreConfig(logr.Discard(), &rest.Config{}, "test", clustersManager, hc)
Expect(err).NotTo(HaveOccurred())
coreSrv, err := server.NewCoreServer(cfg)
Expect(err).NotTo(HaveOccurred())
Expand Down
9 changes: 9 additions & 0 deletions core/server/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,20 @@ func (cs *coreServer) unstructuredToInventoryEntry(ctx context.Context, clusterN
clusterUserNss := cs.clustersManager.GetUserNamespaces(auth.Principal(ctx))
tenant := GetTenant(unstructuredObj.GetNamespace(), clusterName, clusterUserNss)

health, err := cs.healthChecker.Check(unstructuredObj)
if err != nil {
return nil, err
}

entry := &pb.InventoryEntry{
Payload: string(bytes),
Tenant: tenant,
ClusterName: clusterName,
Children: children,
Health: &pb.HealthStatus{
Status: string(health.Status),
Message: health.Message,
},
}

return entry, nil
Expand Down
7 changes: 6 additions & 1 deletion core/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/weaveworks/weave-gitops/core/clustersmngr"
"github.com/weaveworks/weave-gitops/core/nsaccess"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
"github.com/weaveworks/weave-gitops/pkg/health"
"github.com/weaveworks/weave-gitops/pkg/services/crd"
"k8s.io/client-go/rest"
)
Expand Down Expand Up @@ -36,6 +37,7 @@ type coreServer struct {
clustersManager clustersmngr.ClustersManager
primaryKinds *PrimaryKinds
crd crd.Fetcher
healthChecker health.HealthChecker
}

type CoreServerConfig struct {
Expand All @@ -46,9 +48,10 @@ type CoreServerConfig struct {
ClustersManager clustersmngr.ClustersManager
PrimaryKinds *PrimaryKinds
CRDService crd.Fetcher
HealthChecker health.HealthChecker
}

func NewCoreConfig(log logr.Logger, cfg *rest.Config, clusterName string, clustersManager clustersmngr.ClustersManager) (CoreServerConfig, error) {
func NewCoreConfig(log logr.Logger, cfg *rest.Config, clusterName string, clustersManager clustersmngr.ClustersManager, healthChecker health.HealthChecker) (CoreServerConfig, error) {
kinds, err := DefaultPrimaryKinds()
if err != nil {
return CoreServerConfig{}, err
Expand All @@ -61,6 +64,7 @@ func NewCoreConfig(log logr.Logger, cfg *rest.Config, clusterName string, cluste
NSAccess: nsaccess.NewChecker(nsaccess.DefautltWegoAppRules),
ClustersManager: clustersManager,
PrimaryKinds: kinds,
HealthChecker: healthChecker,
}, nil
}

Expand All @@ -75,5 +79,6 @@ func NewCoreServer(cfg CoreServerConfig) (pb.CoreServer, error) {
clustersManager: cfg.ClustersManager,
primaryKinds: cfg.PrimaryKinds,
crd: cfg.CRDService,
healthChecker: cfg.HealthChecker,
}, nil
}
9 changes: 7 additions & 2 deletions core/server/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/weaveworks/weave-gitops/core/nsaccess/nsaccessfakes"
"github.com/weaveworks/weave-gitops/core/server"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
"github.com/weaveworks/weave-gitops/pkg/health"
"github.com/weaveworks/weave-gitops/pkg/kube"
"github.com/weaveworks/weave-gitops/pkg/server/auth"
"github.com/weaveworks/weave-gitops/pkg/services/crd"
Expand Down Expand Up @@ -71,8 +72,10 @@ func makeGRPCServer(cfg *rest.Config, t *testing.T) pb.CoreClient {

fetch := fetcher.NewSingleClusterFetcher(cluster)

hc := health.NewHealthChecker()

clustersManager := clustersmngr.NewClustersManager([]clustersmngr.ClusterFetcher{fetch}, &nsChecker, log)
coreCfg, err := server.NewCoreConfig(log, cfg, "foobar", clustersManager)
coreCfg, err := server.NewCoreConfig(log, cfg, "foobar", clustersManager, hc)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -184,7 +187,9 @@ func makeServerConfig(fakeClient client.Client, t *testing.T, clusterName string
// and the default options include the Flowcontrol setup which is not mocked out
clustersManager := clustersmngr.NewClustersManager([]clustersmngr.ClusterFetcher{fetcher}, &nsChecker, log)

coreCfg, err := server.NewCoreConfig(log, &rest.Config{}, "foobar", clustersManager)
hc := health.NewHealthChecker()

coreCfg, err := server.NewCoreConfig(log, &rest.Config{}, "foobar", clustersManager, hc)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading