@@ -8,11 +8,22 @@ import (
88
99 console "github.com/pluralsh/console-client-go"
1010 clienterrors "github.com/pluralsh/deployment-operator/internal/errors"
11+ "github.com/pluralsh/deployment-operator/internal/utils"
12+ "github.com/pluralsh/deployment-operator/pkg/applier"
13+ "github.com/pluralsh/deployment-operator/pkg/client"
1114 "github.com/pluralsh/deployment-operator/pkg/controller"
15+ plrlerrors "github.com/pluralsh/deployment-operator/pkg/errors"
16+ "github.com/pluralsh/deployment-operator/pkg/manifests"
17+ manis "github.com/pluralsh/deployment-operator/pkg/manifests"
18+ "github.com/pluralsh/deployment-operator/pkg/manifests/template"
19+ "github.com/pluralsh/deployment-operator/pkg/ping"
20+ "github.com/pluralsh/deployment-operator/pkg/websocket"
1221 "github.com/pluralsh/polly/algorithms"
1322 "github.com/samber/lo"
1423 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1524 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
25+ "k8s.io/apimachinery/pkg/runtime/schema"
26+ "k8s.io/apimachinery/pkg/util/wait"
1627 "k8s.io/client-go/discovery"
1728 "k8s.io/client-go/kubernetes"
1829 "k8s.io/client-go/rest"
@@ -23,15 +34,6 @@ import (
2334 "sigs.k8s.io/cli-utils/pkg/inventory"
2435 "sigs.k8s.io/controller-runtime/pkg/log"
2536 "sigs.k8s.io/controller-runtime/pkg/reconcile"
26-
27- "github.com/pluralsh/deployment-operator/internal/utils"
28- "github.com/pluralsh/deployment-operator/pkg/applier"
29- "github.com/pluralsh/deployment-operator/pkg/client"
30- plrlerrors "github.com/pluralsh/deployment-operator/pkg/errors"
31- "github.com/pluralsh/deployment-operator/pkg/manifests"
32- manis "github.com/pluralsh/deployment-operator/pkg/manifests"
33- "github.com/pluralsh/deployment-operator/pkg/ping"
34- "github.com/pluralsh/deployment-operator/pkg/websocket"
3537)
3638
3739func init () {
@@ -67,7 +69,8 @@ type ServiceReconciler struct {
6769 pinger * ping.Pinger
6870}
6971
70- func NewServiceReconciler (consoleClient client.Client , config * rest.Config , refresh time.Duration , restoreNamespace string ) (* ServiceReconciler , error ) {
72+ func NewServiceReconciler (ctx context.Context , consoleClient client.Client , config * rest.Config , refresh time.Duration , restoreNamespace string ) (* ServiceReconciler , error ) {
73+ logger := log .FromContext (ctx )
7174 utils .DisableClientLimits (config )
7275
7376 _ , deployToken := consoleClient .GetCredentials ()
@@ -103,6 +106,19 @@ func NewServiceReconciler(consoleClient client.Client, config *rest.Config, refr
103106 if err != nil {
104107 return nil , err
105108 }
109+ if err := CapabilitiesAPIVersions (discoveryClient ); err != nil {
110+ return nil , err
111+ }
112+
113+ go func () {
114+ //nolint:all
115+ _ = wait .PollImmediateInfinite (time .Minute * 5 , func () (done bool , err error ) {
116+ if err := CapabilitiesAPIVersions (discoveryClient ); err != nil {
117+ logger .Error (err , "can't fetch API versions" )
118+ }
119+ return false , nil
120+ })
121+ }()
106122
107123 return & ServiceReconciler {
108124 ConsoleClient : consoleClient ,
@@ -120,6 +136,29 @@ func NewServiceReconciler(consoleClient client.Client, config *rest.Config, refr
120136 }, nil
121137}
122138
139+ func CapabilitiesAPIVersions (discoveryClient * discovery.DiscoveryClient ) error {
140+ lists , err := discoveryClient .ServerPreferredResources ()
141+ if err != nil {
142+ return err
143+ }
144+ for _ , list := range lists {
145+ if len (list .APIResources ) == 0 {
146+ continue
147+ }
148+ gv , err := schema .ParseGroupVersion (list .GroupVersion )
149+ if err != nil {
150+ continue
151+ }
152+ for _ , resource := range list .APIResources {
153+ if len (resource .Verbs ) == 0 {
154+ continue
155+ }
156+ template .APIVersions .Set (fmt .Sprintf ("%s/%s" , gv .String (), resource .Kind ), true )
157+ }
158+ }
159+ return nil
160+ }
161+
123162func (s * ServiceReconciler ) GetPublisher () (string , websocket.Publisher ) {
124163 return "service.event" , & socketPublisher {
125164 svcQueue : s .SvcQueue ,
0 commit comments