Skip to content

Commit

Permalink
fix: add detection/error for inability to connect to cluster (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtkeller authored Jan 13, 2024
1 parent e21e296 commit b2484eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var validateCmd = &cobra.Command{
// Primary expected path for validation of OSCAL documents
findings, observations, err := ValidateOnPath(opts.InputFile)
if err != nil {
message.Fatalf(err, "Validation error")
message.Fatalf(err, "Validation error: %s", err)
}

report, err := oscal.GenerateAssessmentResults(findings, observations)
Expand Down
10 changes: 8 additions & 2 deletions src/pkg/common/kubernetes/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func GetResourcesDynamically(ctx context.Context,
group string, version string, resource string, namespace string) (
[]unstructured.Unstructured, error) {

config := ctrl.GetConfigOrDie()
config, err := ctrl.GetConfig()
if err != nil {
return nil, fmt.Errorf("Error with connection to the Cluster")
}
dynamic := dynamic.NewForConfigOrDie(config)

resourceId := schema.GroupVersionResource{
Expand All @@ -85,7 +88,10 @@ func GetResourcesDynamically(ctx context.Context,
}

func getGroupVersionResource(kind string) (gvr *schema.GroupVersionResource, err error) {
config := ctrl.GetConfigOrDie()
config, err := ctrl.GetConfig()
if err != nil {
return nil, fmt.Errorf("Error with connection to the Cluster")
}
name := strings.Split(kind, "/")[0]

discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
Expand Down

0 comments on commit b2484eb

Please sign in to comment.