Skip to content

Commit e60f1c2

Browse files
fix: missing integrations (#4)
1 parent 3d2c88a commit e60f1c2

File tree

6 files changed

+48
-130
lines changed

6 files changed

+48
-130
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/lucasepe/httplib v0.2.2
99
github.com/pb33f/libopenapi v0.16.8
1010
github.com/rs/zerolog v1.32.0
11-
github.com/stretchr/testify v1.9.0
1211
k8s.io/apimachinery v0.31.1
1312
k8s.io/client-go v0.31.1
1413
sigs.k8s.io/controller-runtime v0.19.1
@@ -42,7 +41,6 @@ require (
4241
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4342
github.com/modern-go/reflect2 v1.0.2 // indirect
4443
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
45-
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
4644
github.com/spf13/pflag v1.0.5 // indirect
4745
github.com/twmb/murmur3 v1.1.8 // indirect
4846
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect

internal/composition/composition.go

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import (
1515
"github.com/krateoplatformops/unstructured-runtime/pkg/controller"
1616
"github.com/krateoplatformops/unstructured-runtime/pkg/logging"
1717
"github.com/krateoplatformops/unstructured-runtime/pkg/meta"
18+
"github.com/krateoplatformops/unstructured-runtime/pkg/pluralizer"
1819
"github.com/krateoplatformops/unstructured-runtime/pkg/tools/unstructured/condition"
1920
"github.com/lucasepe/httplib"
2021

21-
"github.com/krateoplatformops/rest-dynamic-controller/internal/tools"
22+
"github.com/krateoplatformops/unstructured-runtime/pkg/tools"
2223
unstructuredtools "github.com/krateoplatformops/unstructured-runtime/pkg/tools/unstructured"
2324
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2425
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -29,7 +30,7 @@ import (
2930

3031
var _ controller.ExternalClient = (*handler)(nil)
3132

32-
func NewHandler(cfg *rest.Config, log logging.Logger, swg getter.Getter) controller.ExternalClient {
33+
func NewHandler(cfg *rest.Config, log logging.Logger, swg getter.Getter, pluralizer pluralizer.Pluralizer) controller.ExternalClient {
3334
dyn, err := dynamic.NewForConfig(cfg)
3435
if err != nil {
3536
log.Debug("Creating dynamic client", "error", err)
@@ -41,6 +42,7 @@ func NewHandler(cfg *rest.Config, log logging.Logger, swg getter.Getter) control
4142
}
4243

4344
return &handler{
45+
pluralizer: pluralizer,
4446
logger: log,
4547
dynamicClient: dyn,
4648
discoveryClient: dis,
@@ -49,6 +51,7 @@ func NewHandler(cfg *rest.Config, log logging.Logger, swg getter.Getter) control
4951
}
5052

5153
type handler struct {
54+
pluralizer pluralizer.Pluralizer
5255
logger logging.Logger
5356
dynamicClient dynamic.Interface
5457
discoveryClient *discovery.DiscoveryClient
@@ -74,10 +77,14 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
7477
log.Debug("Swagger info is nil")
7578
return controller.ExternalObservation{}, fmt.Errorf("swagger info is nil")
7679
}
77-
tools.Update(ctx, mg, tools.UpdateOptions{
78-
DiscoveryClient: h.discoveryClient,
79-
DynamicClient: h.dynamicClient,
80+
mg, err = tools.Update(ctx, mg, tools.UpdateOptions{
81+
Pluralizer: h.pluralizer,
82+
DynamicClient: h.dynamicClient,
8083
})
84+
if err != nil {
85+
log.Debug("Updating CR", "error", err)
86+
return controller.ExternalObservation{}, err
87+
}
8188

8289
cli, err := restclient.BuildClient(clientInfo.URL)
8390
if err != nil {
@@ -143,13 +150,16 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
143150
log.Debug("Setting condition", "error", err)
144151
return controller.ExternalObservation{}, err
145152
}
153+
154+
_, err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
155+
Pluralizer: h.pluralizer,
156+
DynamicClient: h.dynamicClient,
157+
})
158+
146159
return controller.ExternalObservation{
147-
ResourceExists: true,
148-
ResourceUpToDate: true,
149-
}, tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
150-
DiscoveryClient: h.discoveryClient,
151-
DynamicClient: h.dynamicClient,
152-
})
160+
ResourceExists: true,
161+
ResourceUpToDate: true,
162+
}, err
153163
}
154164
if err != nil {
155165
log.Debug("Building API call", "error", err)
@@ -178,9 +188,9 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
178188
return controller.ExternalObservation{}, err
179189
}
180190

181-
err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
182-
DiscoveryClient: h.discoveryClient,
183-
DynamicClient: h.dynamicClient,
191+
mg, err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
192+
Pluralizer: h.pluralizer,
193+
DynamicClient: h.dynamicClient,
184194
})
185195
if err != nil {
186196
log.Debug("Updating status", "error", err)
@@ -208,9 +218,9 @@ func (h *handler) Observe(ctx context.Context, mg *unstructured.Unstructured) (c
208218
log.Debug("Setting condition", "error", err)
209219
return controller.ExternalObservation{}, err
210220
}
211-
err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
212-
DiscoveryClient: h.discoveryClient,
213-
DynamicClient: h.dynamicClient,
221+
mg, err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
222+
Pluralizer: h.pluralizer,
223+
DynamicClient: h.dynamicClient,
214224
})
215225
if err != nil {
216226
log.Debug("Updating status", "error", err)
@@ -281,9 +291,10 @@ func (h *handler) Create(ctx context.Context, mg *unstructured.Unstructured) err
281291
return err
282292
}
283293

284-
err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
285-
DiscoveryClient: h.discoveryClient,
286-
DynamicClient: h.dynamicClient,
294+
_, err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
295+
296+
Pluralizer: h.pluralizer,
297+
DynamicClient: h.dynamicClient,
287298
})
288299
if err != nil {
289300
log.Debug("Updating status", "error", err)
@@ -356,18 +367,18 @@ func (h *handler) Update(ctx context.Context, mg *unstructured.Unstructured) err
356367
return err
357368
}
358369

359-
err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
360-
DiscoveryClient: h.discoveryClient,
361-
DynamicClient: h.dynamicClient,
370+
mg, err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
371+
Pluralizer: h.pluralizer,
372+
DynamicClient: h.dynamicClient,
362373
})
363374
if err != nil {
364375
log.Debug("Updating status", "error", err)
365376
return err
366377
}
367378

368-
err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
369-
DiscoveryClient: h.discoveryClient,
370-
DynamicClient: h.dynamicClient,
379+
mg, err = tools.UpdateStatus(ctx, mg, tools.UpdateOptions{
380+
Pluralizer: h.pluralizer,
381+
DynamicClient: h.dynamicClient,
371382
})
372383
if err != nil {
373384
log.Debug("Updating status", "error", err)
@@ -419,7 +430,7 @@ func (h *handler) Delete(ctx context.Context, mg *unstructured.Unstructured) err
419430
apiCall, callInfo, err := APICallBuilder(cli, clientInfo, apiaction.Delete)
420431
if apiCall == nil {
421432
log.Debug("API call not found", "action", apiaction.Delete)
422-
return removeFinalizersAndUpdate(ctx, log, h.discoveryClient, h.dynamicClient, mg)
433+
return removeFinalizersAndUpdate(ctx, log, h.pluralizer, h.dynamicClient, mg)
423434
}
424435
if err != nil {
425436
log.Debug("Building API call", "error", err)
@@ -444,5 +455,5 @@ func (h *handler) Delete(ctx context.Context, mg *unstructured.Unstructured) err
444455
return err
445456
}
446457

447-
return removeFinalizersAndUpdate(ctx, log, h.discoveryClient, h.dynamicClient, mg)
458+
return removeFinalizersAndUpdate(ctx, log, h.pluralizer, h.dynamicClient, mg)
448459
}

internal/composition/support.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99

1010
restclient "github.com/krateoplatformops/rest-dynamic-controller/internal/client"
1111
"github.com/krateoplatformops/rest-dynamic-controller/internal/text"
12-
"github.com/krateoplatformops/rest-dynamic-controller/internal/tools"
1312
"github.com/krateoplatformops/rest-dynamic-controller/internal/tools/apiaction"
1413
getter "github.com/krateoplatformops/rest-dynamic-controller/internal/tools/restclient"
1514
"github.com/krateoplatformops/unstructured-runtime/pkg/logging"
15+
"github.com/krateoplatformops/unstructured-runtime/pkg/pluralizer"
16+
"github.com/krateoplatformops/unstructured-runtime/pkg/tools"
1617
unstructuredtools "github.com/krateoplatformops/unstructured-runtime/pkg/tools/unstructured"
1718
"github.com/rs/zerolog/log"
1819
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
19-
"k8s.io/client-go/discovery"
2020
"k8s.io/client-go/dynamic"
2121
)
2222

@@ -257,11 +257,11 @@ func compareAny(a any, b any) bool {
257257
}
258258
}
259259

260-
func removeFinalizersAndUpdate(ctx context.Context, log logging.Logger, discovery *discovery.DiscoveryClient, dynamic dynamic.Interface, mg *unstructured.Unstructured) error {
260+
func removeFinalizersAndUpdate(ctx context.Context, log logging.Logger, pluralizer pluralizer.Pluralizer, dynamic dynamic.Interface, mg *unstructured.Unstructured) error {
261261
mg.SetFinalizers([]string{})
262-
err := tools.Update(ctx, mg, tools.UpdateOptions{
263-
DiscoveryClient: discovery,
264-
DynamicClient: dynamic,
262+
_, err := tools.Update(ctx, mg, tools.UpdateOptions{
263+
Pluralizer: pluralizer,
264+
DynamicClient: dynamic,
265265
})
266266
if err != nil {
267267
log.Debug("Deleting finalizer", "error", err)

internal/tools/tools.go

Lines changed: 0 additions & 60 deletions
This file was deleted.

internal/tools/tools_test.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,19 @@ func main() {
9696
if err != nil {
9797
log.Debug("Creating chart url info getter.", "error", err)
9898
}
99-
handler = restComposition.NewHandler(cfg, log, swg)
10099

101100
log.WithValues("build", Build).
102101
WithValues("debug", *debug).
103102
WithValues("resyncInterval", *resyncInterval).
104103
WithValues("group", *resourceGroup).
105104
WithValues("version", *resourceVersion).
106105
WithValues("resource", *resourceName).
107-
Info("Starting %s.", serviceName)
106+
Info("Starting.", "serviceName", serviceName)
108107

109108
pluralizer := pluralizer.New(urlplurals, http.DefaultClient)
110109

110+
handler = restComposition.NewHandler(cfg, log, swg, *pluralizer)
111+
111112
controller := genctrl.New(genctrl.Options{
112113
Discovery: cachedDisc,
113114
Client: dyn,

0 commit comments

Comments
 (0)