Skip to content

Commit b7fef19

Browse files
author
Dmitriy Matrenichev
committed
chore: migrate from AlekSi/pointer to siderolabs/go-pointer
Now that we have generics and require Go 1.18 - redo pointer.* functions as two generic functions. Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
1 parent 639b4a2 commit b7fef19

9 files changed

Lines changed: 40 additions & 40 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ go 1.18
77
replace gopkg.in/yaml.v3 => github.com/unix4ever/yaml v0.0.0-20210315173758-8fb30b8e5a5b
88

99
require (
10-
github.com/AlekSi/pointer v1.1.0
1110
github.com/cenkalti/backoff/v4 v4.1.1
1211
github.com/gertd/go-pluralize v0.1.7
1312
github.com/golang/protobuf v1.5.2
1413
github.com/hashicorp/go-memdb v1.3.2
14+
github.com/siderolabs/go-pointer v1.0.0
1515
github.com/stretchr/testify v1.7.0
1616
github.com/talos-systems/go-retry v0.3.1
1717
go.uber.org/goleak v1.1.10

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
3-
github.com/AlekSi/pointer v1.1.0 h1:SSDMPcXD9jSl8FPy9cRzoRaMJtm9g9ggGTxecRUbQoI=
4-
github.com/AlekSi/pointer v1.1.0/go.mod h1:y7BvfRI3wXPWKXEBhU71nbnIEEZX0QTSB2Bj48UJIZE=
53
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
64
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
75
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
@@ -71,6 +69,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
7169
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7270
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
7371
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
72+
github.com/siderolabs/go-pointer v1.0.0 h1:6TshPKep2doDQJAAtHUuHWXbca8ZfyRySjSBT/4GsMU=
73+
github.com/siderolabs/go-pointer v1.0.0/go.mod h1:HTRFUNYa3R+k0FFKNv11zgkaCLzEkWVzoYZ433P3kHc=
7474
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7575
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7676
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

pkg/controller/runtime/adapter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"sync"
1414
"time"
1515

16-
"github.com/AlekSi/pointer"
1716
"github.com/cenkalti/backoff/v4"
17+
"github.com/siderolabs/go-pointer"
1818
"go.uber.org/zap"
1919

2020
"github.com/cosi-project/runtime/pkg/controller"
@@ -188,7 +188,7 @@ func (adapter *adapter) checkFinalizerAccess(resourceNamespace resource.Namespac
188188

189189
// Get implements controller.Runtime interface.
190190
func (adapter *adapter) Get(ctx context.Context, resourcePointer resource.Pointer) (resource.Resource, error) { //nolint:ireturn
191-
if err := adapter.checkReadAccess(resourcePointer.Namespace(), resourcePointer.Type(), pointer.ToString(resourcePointer.ID())); err != nil {
191+
if err := adapter.checkReadAccess(resourcePointer.Namespace(), resourcePointer.Type(), pointer.To(resourcePointer.ID())); err != nil {
192192
return nil, err
193193
}
194194

pkg/controller/runtime/dependency/database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ package dependency
77
import (
88
"fmt"
99

10-
"github.com/AlekSi/pointer"
1110
"github.com/hashicorp/go-memdb"
11+
"github.com/siderolabs/go-pointer"
1212

1313
"github.com/cosi-project/runtime/pkg/controller"
1414
"github.com/cosi-project/runtime/pkg/resource"
@@ -327,7 +327,7 @@ func (db *Database) GetControllerInputs(controllerName string) ([]controller.Inp
327327
}
328328

329329
if model.ID != StarID {
330-
dep.ID = pointer.ToString(model.ID)
330+
dep.ID = pointer.To(model.ID)
331331
}
332332

333333
result = append(result, dep)

pkg/controller/runtime/dependency/database_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package dependency_test
77
import (
88
"testing"
99

10-
"github.com/AlekSi/pointer"
10+
"github.com/siderolabs/go-pointer"
1111
"github.com/stretchr/testify/suite"
1212

1313
"github.com/cosi-project/runtime/pkg/controller"
@@ -118,7 +118,7 @@ func (suite *DatabaseSuite) TestControllerDependency() {
118118
suite.Require().NoError(suite.db.AddControllerInput("ConfigController", controller.Input{
119119
Namespace: "state",
120120
Type: "Machine",
121-
ID: pointer.ToString("system"),
121+
ID: pointer.To("system"),
122122
Kind: controller.InputStrong,
123123
}))
124124

@@ -139,7 +139,7 @@ func (suite *DatabaseSuite) TestControllerDependency() {
139139
ctrls, err := suite.db.GetDependentControllers(controller.Input{
140140
Namespace: "user",
141141
Type: "Config",
142-
ID: pointer.ToString("config"),
142+
ID: pointer.To("config"),
143143
})
144144
suite.Require().NoError(err)
145145
suite.Assert().Equal([]string{"ConfigController"}, ctrls)
@@ -161,15 +161,15 @@ func (suite *DatabaseSuite) TestControllerDependency() {
161161
ctrls, err = suite.db.GetDependentControllers(controller.Input{
162162
Namespace: "state",
163163
Type: "Machine",
164-
ID: pointer.ToString("node"),
164+
ID: pointer.To("node"),
165165
})
166166
suite.Require().NoError(err)
167167
suite.Assert().Empty(ctrls)
168168

169169
ctrls, err = suite.db.GetDependentControllers(controller.Input{
170170
Namespace: "state",
171171
Type: "Machine",
172-
ID: pointer.ToString("system"),
172+
ID: pointer.To("system"),
173173
})
174174
suite.Require().NoError(err)
175175
suite.Assert().Equal([]string{"ConfigController"}, ctrls)
@@ -184,7 +184,7 @@ func (suite *DatabaseSuite) TestControllerDependency() {
184184
suite.Require().NoError(suite.db.DeleteControllerInput("ConfigController", controller.Input{
185185
Namespace: "state",
186186
Type: "Machine",
187-
ID: pointer.ToString("system"),
187+
ID: pointer.To("system"),
188188
}))
189189

190190
ctrls, err = suite.db.GetDependentControllers(controller.Input{
@@ -221,7 +221,7 @@ func (suite *DatabaseSuite) TestExport() {
221221
Namespace: "user",
222222
Type: "Config",
223223
Kind: controller.InputWeak,
224-
ID: pointer.ToString("config"),
224+
ID: pointer.To("config"),
225225
}))
226226

227227
suite.Require().NoError(suite.db.AddControllerInput("ControllerTable", controller.Input{

pkg/controller/runtime/dependency/dependency_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package dependency_test
77
import (
88
"testing"
99

10-
"github.com/AlekSi/pointer"
10+
"github.com/siderolabs/go-pointer"
1111
"github.com/stretchr/testify/assert"
1212

1313
"github.com/cosi-project/runtime/pkg/controller"
@@ -27,13 +27,13 @@ func TestLess(t *testing.T) {
2727
A: controller.Input{
2828
Namespace: "default",
2929
Type: "Config",
30-
ID: pointer.ToString("id"),
30+
ID: pointer.To("id"),
3131
Kind: controller.InputStrong,
3232
},
3333
B: controller.Input{
3434
Namespace: "default",
3535
Type: "Config",
36-
ID: pointer.ToString("id"),
36+
ID: pointer.To("id"),
3737
Kind: controller.InputStrong,
3838
},
3939
Expected: false,
@@ -43,13 +43,13 @@ func TestLess(t *testing.T) {
4343
A: controller.Input{
4444
Namespace: "default",
4545
Type: "Config",
46-
ID: pointer.ToString("id"),
46+
ID: pointer.To("id"),
4747
Kind: controller.InputStrong,
4848
},
4949
B: controller.Input{
5050
Namespace: "default",
5151
Type: "Config",
52-
ID: pointer.ToString("jd"),
52+
ID: pointer.To("jd"),
5353
Kind: controller.InputStrong,
5454
},
5555
Expected: true,
@@ -94,13 +94,13 @@ func TestEqual(t *testing.T) {
9494
A: controller.Input{
9595
Namespace: "default",
9696
Type: "Config",
97-
ID: pointer.ToString("id"),
97+
ID: pointer.To("id"),
9898
Kind: controller.InputStrong,
9999
},
100100
B: controller.Input{
101101
Namespace: "default",
102102
Type: "Config",
103-
ID: pointer.ToString("id"),
103+
ID: pointer.To("id"),
104104
Kind: controller.InputStrong,
105105
},
106106
Expected: true,
@@ -110,13 +110,13 @@ func TestEqual(t *testing.T) {
110110
A: controller.Input{
111111
Namespace: "default",
112112
Type: "Config",
113-
ID: pointer.ToString("id"),
113+
ID: pointer.To("id"),
114114
Kind: controller.InputStrong,
115115
},
116116
B: controller.Input{
117117
Namespace: "default",
118118
Type: "Config",
119-
ID: pointer.ToString("jd"),
119+
ID: pointer.To("jd"),
120120
Kind: controller.InputStrong,
121121
},
122122
Expected: false,
@@ -126,7 +126,7 @@ func TestEqual(t *testing.T) {
126126
A: controller.Input{
127127
Namespace: "default",
128128
Type: "Config",
129-
ID: pointer.ToString("id"),
129+
ID: pointer.To("id"),
130130
Kind: controller.InputStrong,
131131
},
132132
B: controller.Input{
@@ -174,13 +174,13 @@ func TestEqual(t *testing.T) {
174174
A: controller.Input{
175175
Namespace: "user",
176176
Type: "Config",
177-
ID: pointer.ToString("id"),
177+
ID: pointer.To("id"),
178178
Kind: controller.InputStrong,
179179
},
180180
B: controller.Input{
181181
Namespace: "default",
182182
Type: "Config",
183-
ID: pointer.ToString("id"),
183+
ID: pointer.To("id"),
184184
Kind: controller.InputStrong,
185185
},
186186
Expected: false,
@@ -209,13 +209,13 @@ func TestEqualKeys(t *testing.T) {
209209
A: controller.Input{
210210
Namespace: "default",
211211
Type: "Config",
212-
ID: pointer.ToString("id"),
212+
ID: pointer.To("id"),
213213
Kind: controller.InputStrong,
214214
},
215215
B: controller.Input{
216216
Namespace: "default",
217217
Type: "Config",
218-
ID: pointer.ToString("id"),
218+
ID: pointer.To("id"),
219219
Kind: controller.InputStrong,
220220
},
221221
Expected: true,
@@ -225,13 +225,13 @@ func TestEqualKeys(t *testing.T) {
225225
A: controller.Input{
226226
Namespace: "default",
227227
Type: "Config",
228-
ID: pointer.ToString("id"),
228+
ID: pointer.To("id"),
229229
Kind: controller.InputWeak,
230230
},
231231
B: controller.Input{
232232
Namespace: "default",
233233
Type: "Config",
234-
ID: pointer.ToString("id"),
234+
ID: pointer.To("id"),
235235
Kind: controller.InputStrong,
236236
},
237237
Expected: true,
@@ -241,13 +241,13 @@ func TestEqualKeys(t *testing.T) {
241241
A: controller.Input{
242242
Namespace: "default",
243243
Type: "Config",
244-
ID: pointer.ToString("id"),
244+
ID: pointer.To("id"),
245245
Kind: controller.InputStrong,
246246
},
247247
B: controller.Input{
248248
Namespace: "default",
249249
Type: "Config",
250-
ID: pointer.ToString("jd"),
250+
ID: pointer.To("jd"),
251251
Kind: controller.InputStrong,
252252
},
253253
Expected: false,
@@ -257,7 +257,7 @@ func TestEqualKeys(t *testing.T) {
257257
A: controller.Input{
258258
Namespace: "default",
259259
Type: "Config",
260-
ID: pointer.ToString("id"),
260+
ID: pointer.To("id"),
261261
Kind: controller.InputStrong,
262262
},
263263
B: controller.Input{

pkg/controller/runtime/runtime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"fmt"
1111
"sync"
1212

13-
"github.com/AlekSi/pointer"
1413
"github.com/cenkalti/backoff/v4"
14+
"github.com/siderolabs/go-pointer"
1515
"go.uber.org/zap"
1616

1717
"github.com/cosi-project/runtime/pkg/controller"
@@ -234,7 +234,7 @@ func (runtime *Runtime) processWatched() {
234234
controllers, err := runtime.depDB.GetDependentControllers(controller.Input{
235235
Namespace: md.Namespace(),
236236
Type: md.Type(),
237-
ID: pointer.ToString(md.ID()),
237+
ID: pointer.To(md.ID()),
238238
})
239239
if err != nil {
240240
// TODO: no way to handle it here

pkg/resource/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"strconv"
1010

11-
"github.com/AlekSi/pointer"
11+
"github.com/siderolabs/go-pointer"
1212
)
1313

1414
// Version of a resource.
@@ -55,6 +55,6 @@ func ParseVersion(ver string) (Version, error) {
5555
}
5656

5757
return Version{
58-
uint64: pointer.ToUint64(uint64(intVersion)),
58+
uint64: pointer.To(uint64(intVersion)),
5959
}, nil
6060
}

pkg/state/protobuf/client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"errors"
1111
"io"
1212

13-
"github.com/AlekSi/pointer"
13+
"github.com/siderolabs/go-pointer"
1414
"google.golang.org/grpc/codes"
1515
"google.golang.org/grpc/status"
1616

@@ -182,7 +182,7 @@ func (adapter *Adapter) Update(ctx context.Context, curVersion resource.Version,
182182
var expectedPhase *string
183183

184184
if opts.ExpectedPhase != nil {
185-
expectedPhase = pointer.ToString(opts.ExpectedPhase.String())
185+
expectedPhase = pointer.To(opts.ExpectedPhase.String())
186186
}
187187

188188
_, err = adapter.client.Update(ctx, &v1alpha1.UpdateRequest{
@@ -264,7 +264,7 @@ func (adapter *Adapter) Watch(ctx context.Context, resourcePointer resource.Poin
264264
cli, err := adapter.client.Watch(ctx, &v1alpha1.WatchRequest{
265265
Namespace: resourcePointer.Namespace(),
266266
Type: resourcePointer.Type(),
267-
Id: pointer.ToString(resourcePointer.ID()),
267+
Id: pointer.To(resourcePointer.ID()),
268268
Options: &v1alpha1.WatchOptions{
269269
TailEvents: int32(opts.TailEvents),
270270
},

0 commit comments

Comments
 (0)