Skip to content

Commit

Permalink
feat: dynamic rest mapper (#129)
Browse files Browse the repository at this point in the history
## Description

Not having a dynamic rest mapper is problematic for Zarf health checks
with CRDs. See [#3010](zarf-dev/zarf#3010)

---------

Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
  • Loading branch information
AustinAbro321 authored Sep 20, 2024
1 parent 764e08c commit 2861521
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion kubernetes/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
k8s.io/apimachinery v0.29.1
k8s.io/client-go v0.29.1
sigs.k8s.io/cli-utils v0.36.0
sigs.k8s.io/controller-runtime v0.16.3
)

require (
Expand Down Expand Up @@ -56,7 +57,6 @@ require (
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/controller-runtime v0.16.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.15.0 // indirect
sigs.k8s.io/kustomize/kyaml v0.15.0 // indirect
Expand Down
10 changes: 4 additions & 6 deletions kubernetes/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import (
"context"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/client-go/restmapper"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/collector"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
"sigs.k8s.io/cli-utils/pkg/kstatus/watcher"
"sigs.k8s.io/cli-utils/pkg/object"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)

// WatcherForConfig returns a status watcher for the give Kubernetes configuration.
Expand All @@ -25,16 +24,15 @@ func WatcherForConfig(cfg *rest.Config) (watcher.StatusWatcher, error) {
if err != nil {
return nil, err
}
discoveryClient, err := discovery.NewDiscoveryClientForConfig(cfg)
httpClient, err := rest.HTTPClientFor(cfg)
if err != nil {
return nil, err
}
groupResources, err := restmapper.GetAPIGroupResources(discoveryClient)
restMapper, err := apiutil.NewDynamicRESTMapper(cfg, httpClient)
if err != nil {
return nil, err
}
rm := restmapper.NewDiscoveryRESTMapper(groupResources)
sw := watcher.NewDefaultStatusWatcher(dynamicClient, rm)
sw := watcher.NewDefaultStatusWatcher(dynamicClient, restMapper)
return sw, nil
}

Expand Down

0 comments on commit 2861521

Please sign in to comment.