Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c20c0637
Commit
c20c0637
authored
Dec 18, 2024
by
Brad Davidson
Committed by
Brad Davidson
Jan 09, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move additional core/v1 mocks into tests package
Convert nodepassword tests to use shared mocks Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
8f8cfb56
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
106 deletions
+160
-106
nodepassword_test.go
pkg/nodepassword/nodepassword_test.go
+31
-84
core.go
tests/mock/core.go
+129
-22
No files found.
pkg/nodepassword/nodepassword_test.go
View file @
c20c0637
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"runtime"
"runtime"
"testing"
"testing"
"github.com/
rancher/wrangler/v3/pkg/generic/fake
"
"github.com/
k3s-io/k3s/tests/mock
"
"go.uber.org/mock/gomock"
"go.uber.org/mock/gomock"
v1
"k8s.io/api/core/v1"
v1
"k8s.io/api/core/v1"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
...
@@ -28,10 +28,11 @@ func Test_UnitAsserts(t *testing.T) {
...
@@ -28,10 +28,11 @@ func Test_UnitAsserts(t *testing.T) {
func
Test_UnitEnsureDelete
(
t
*
testing
.
T
)
{
func
Test_UnitEnsureDelete
(
t
*
testing
.
T
)
{
logMemUsage
(
t
)
logMemUsage
(
t
)
ctrl
:=
gomock
.
NewController
(
t
)
v1Mock
:=
mock
.
NewV1
(
gomock
.
NewController
(
t
))
secretClient
:=
fake
.
NewMockControllerInterface
[
*
v1
.
Secret
,
*
v1
.
SecretList
](
ctrl
)
secretCache
:=
fake
.
NewMockCacheInterface
[
*
v1
.
Secret
](
ctrl
)
secretClient
:=
v1Mock
.
SecretMock
secretStore
:=
&
mockSecretStore
{}
secretCache
:=
v1Mock
.
SecretCache
secretStore
:=
&
mock
.
SecretStore
{}
// Set up expected call counts for tests
// Set up expected call counts for tests
// Expect to see 2 creates, any number of cache gets, and 2 deletes.
// Expect to see 2 creates, any number of cache gets, and 2 deletes.
...
@@ -59,15 +60,15 @@ func Test_UnitMigrateFile(t *testing.T) {
...
@@ -59,15 +60,15 @@ func Test_UnitMigrateFile(t *testing.T) {
nodePasswordFile
:=
generateNodePasswordFile
(
migrateNumNodes
)
nodePasswordFile
:=
generateNodePasswordFile
(
migrateNumNodes
)
defer
os
.
Remove
(
nodePasswordFile
)
defer
os
.
Remove
(
nodePasswordFile
)
ctrl
:=
gomock
.
NewController
(
t
)
v1Mock
:=
mock
.
NewV1
(
gomock
.
NewController
(
t
)
)
secretClient
:=
fake
.
NewMockControllerInterface
[
*
v1
.
Secret
,
*
v1
.
SecretList
](
ctrl
)
secretClient
:=
v1Mock
.
SecretMock
secretCache
:=
fake
.
NewMockCacheInterface
[
*
v1
.
Secret
](
ctrl
)
secretCache
:=
v1Mock
.
SecretCache
secretStore
:=
&
mockSecretStore
{}
secretStore
:=
&
mock
.
SecretStore
{}
nodeClient
:=
fake
.
NewMockNonNamespacedControllerInterface
[
*
v1
.
Node
,
*
v1
.
NodeList
](
ctrl
)
nodeClient
:=
v1Mock
.
NodeMock
nodeCache
:=
fake
.
NewMockNonNamespacedCacheInterface
[
*
v1
.
Node
](
ctrl
)
nodeCache
:=
v1Mock
.
NodeCache
nodeStore
:=
&
mockNodeStore
{}
nodeStore
:=
&
mock
.
NodeStore
{}
// Set up expected call counts for tests
// Set up expected call counts for tests
// Expect to see 1 node list, any number of cache gets, and however many
// Expect to see 1 node list, any number of cache gets, and however many
...
@@ -93,19 +94,20 @@ func Test_UnitMigrateFileNodes(t *testing.T) {
...
@@ -93,19 +94,20 @@ func Test_UnitMigrateFileNodes(t *testing.T) {
nodePasswordFile
:=
generateNodePasswordFile
(
migrateNumNodes
)
nodePasswordFile
:=
generateNodePasswordFile
(
migrateNumNodes
)
defer
os
.
Remove
(
nodePasswordFile
)
defer
os
.
Remove
(
nodePasswordFile
)
ctrl
:=
gomock
.
NewController
(
t
)
v1Mock
:=
mock
.
NewV1
(
gomock
.
NewController
(
t
)
)
secretClient
:=
fake
.
NewMockControllerInterface
[
*
v1
.
Secret
,
*
v1
.
SecretList
](
ctrl
)
secretClient
:=
v1Mock
.
SecretMock
secretCache
:=
fake
.
NewMockCacheInterface
[
*
v1
.
Secret
](
ctrl
)
secretCache
:=
v1Mock
.
SecretCache
secretStore
:=
&
mockSecretStore
{}
secretStore
:=
&
mock
.
SecretStore
{}
nodeClient
:=
fake
.
NewMockNonNamespacedControllerInterface
[
*
v1
.
Node
,
*
v1
.
NodeList
](
ctrl
)
nodeClient
:=
v1Mock
.
NodeMock
nodeCache
:=
fake
.
NewMockNonNamespacedCacheInterface
[
*
v1
.
Node
](
ctrl
)
nodeCache
:=
v1Mock
.
NodeCache
nodeStore
:=
&
mockNodeStore
{}
nodeStore
:=
&
mock
.
NodeStore
{}
nodeStore
.
nodes
=
make
([]
v1
.
Node
,
createNumNodes
,
createNumNodes
)
for
i
:=
0
;
i
<
createNumNodes
;
i
++
{
for
i
:=
range
nodeStore
.
nodes
{
if
_
,
err
:=
nodeStore
.
Create
(
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
fmt
.
Sprintf
(
"node%d"
,
i
+
1
)}});
err
!=
nil
{
nodeStore
.
nodes
[
i
]
.
Name
=
fmt
.
Sprintf
(
"node%d"
,
i
+
1
)
t
.
Fatal
(
err
)
}
}
}
// Set up expected call counts for tests
// Set up expected call counts for tests
...
@@ -124,9 +126,13 @@ func Test_UnitMigrateFileNodes(t *testing.T) {
...
@@ -124,9 +126,13 @@ func Test_UnitMigrateFileNodes(t *testing.T) {
}
}
logMemUsage
(
t
)
logMemUsage
(
t
)
for
_
,
node
:=
range
nodeStore
.
nodes
{
if
nodes
,
err
:=
nodeStore
.
List
(
labels
.
Everything
());
err
!=
nil
{
assertNotEqual
(
t
,
Ensure
(
secretClient
,
node
.
Name
,
"wrong-password"
),
nil
)
t
.
Fatal
(
err
)
assertEqual
(
t
,
Ensure
(
secretClient
,
node
.
Name
,
node
.
Name
),
nil
)
}
else
{
for
_
,
node
:=
range
nodes
{
assertNotEqual
(
t
,
Ensure
(
secretClient
,
node
.
Name
,
"wrong-password"
),
nil
)
assertEqual
(
t
,
Ensure
(
secretClient
,
node
.
Name
,
node
.
Name
),
nil
)
}
}
}
newNode
:=
fmt
.
Sprintf
(
"node%d"
,
migrateNumNodes
+
1
)
newNode
:=
fmt
.
Sprintf
(
"node%d"
,
migrateNumNodes
+
1
)
...
@@ -142,65 +148,6 @@ func Test_PasswordError(t *testing.T) {
...
@@ -142,65 +148,6 @@ func Test_PasswordError(t *testing.T) {
}
}
// --------------------------
// --------------------------
// mock secret store interface
type
mockSecretStore
struct
{
entries
map
[
string
]
map
[
string
]
v1
.
Secret
}
func
(
m
*
mockSecretStore
)
Create
(
secret
*
v1
.
Secret
)
(
*
v1
.
Secret
,
error
)
{
if
m
.
entries
==
nil
{
m
.
entries
=
map
[
string
]
map
[
string
]
v1
.
Secret
{}
}
if
_
,
ok
:=
m
.
entries
[
secret
.
Namespace
];
!
ok
{
m
.
entries
[
secret
.
Namespace
]
=
map
[
string
]
v1
.
Secret
{}
}
if
_
,
ok
:=
m
.
entries
[
secret
.
Namespace
][
secret
.
Name
];
ok
{
return
nil
,
errorAlreadyExists
()
}
m
.
entries
[
secret
.
Namespace
][
secret
.
Name
]
=
*
secret
return
secret
,
nil
}
func
(
m
*
mockSecretStore
)
Delete
(
namespace
,
name
string
,
options
*
metav1
.
DeleteOptions
)
error
{
if
m
.
entries
==
nil
{
return
errorNotFound
()
}
if
_
,
ok
:=
m
.
entries
[
namespace
];
!
ok
{
return
errorNotFound
()
}
if
_
,
ok
:=
m
.
entries
[
namespace
][
name
];
!
ok
{
return
errorNotFound
()
}
delete
(
m
.
entries
[
namespace
],
name
)
return
nil
}
func
(
m
*
mockSecretStore
)
Get
(
namespace
,
name
string
)
(
*
v1
.
Secret
,
error
)
{
if
m
.
entries
==
nil
{
return
nil
,
errorNotFound
()
}
if
_
,
ok
:=
m
.
entries
[
namespace
];
!
ok
{
return
nil
,
errorNotFound
()
}
if
secret
,
ok
:=
m
.
entries
[
namespace
][
name
];
ok
{
return
&
secret
,
nil
}
return
nil
,
errorNotFound
()
}
// --------------------------
// mock node store interface
type
mockNodeStore
struct
{
nodes
[]
v1
.
Node
}
func
(
m
*
mockNodeStore
)
List
(
ls
labels
.
Selector
)
([]
v1
.
Node
,
error
)
{
return
m
.
nodes
,
nil
}
// --------------------------
// utility functions
// utility functions
func
assertEqual
(
t
*
testing
.
T
,
a
interface
{},
b
interface
{})
{
func
assertEqual
(
t
*
testing
.
T
,
a
interface
{},
b
interface
{})
{
...
...
tests/mock/core.go
View file @
c20c0637
...
@@ -7,6 +7,8 @@ import (
...
@@ -7,6 +7,8 @@ import (
"go.uber.org/mock/gomock"
"go.uber.org/mock/gomock"
v1
"k8s.io/api/core/v1"
v1
"k8s.io/api/core/v1"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
)
)
...
@@ -35,32 +37,54 @@ func (m *CoreMock) V1() corev1.Interface {
...
@@ -35,32 +37,54 @@ func (m *CoreMock) V1() corev1.Interface {
var
_
corev1
.
Interface
=
&
V1Mock
{}
var
_
corev1
.
Interface
=
&
V1Mock
{}
type
V1Mock
struct
{
type
V1Mock
struct
{
ConfigMapMock
*
fake
.
MockControllerInterface
[
*
v1
.
ConfigMap
,
*
v1
.
ConfigMapList
]
ConfigMapMock
*
fake
.
MockControllerInterface
[
*
v1
.
ConfigMap
,
*
v1
.
ConfigMapList
]
EndpointsMock
*
fake
.
MockControllerInterface
[
*
v1
.
Endpoints
,
*
v1
.
EndpointsList
]
ConfigMapCache
*
fake
.
MockCacheInterface
[
*
v1
.
ConfigMap
]
EventMock
*
fake
.
MockControllerInterface
[
*
v1
.
Event
,
*
v1
.
EventList
]
EndpointsMock
*
fake
.
MockControllerInterface
[
*
v1
.
Endpoints
,
*
v1
.
EndpointsList
]
NamespaceMock
*
fake
.
MockNonNamespacedControllerInterface
[
*
v1
.
Namespace
,
*
v1
.
NamespaceList
]
EndpointsCache
*
fake
.
MockCacheInterface
[
*
v1
.
Endpoints
]
NodeMock
*
fake
.
MockNonNamespacedControllerInterface
[
*
v1
.
Node
,
*
v1
.
NodeList
]
EventMock
*
fake
.
MockControllerInterface
[
*
v1
.
Event
,
*
v1
.
EventList
]
PersistentVolumeMock
*
fake
.
MockNonNamespacedControllerInterface
[
*
v1
.
PersistentVolume
,
*
v1
.
PersistentVolumeList
]
EventCache
*
fake
.
MockCacheInterface
[
*
v1
.
Event
]
PersistentVolumeClaimMock
*
fake
.
MockControllerInterface
[
*
v1
.
PersistentVolumeClaim
,
*
v1
.
PersistentVolumeClaimList
]
NamespaceMock
*
fake
.
MockNonNamespacedControllerInterface
[
*
v1
.
Namespace
,
*
v1
.
NamespaceList
]
PodMock
*
fake
.
MockControllerInterface
[
*
v1
.
Pod
,
*
v1
.
PodList
]
NamespaceCache
*
fake
.
MockNonNamespacedCacheInterface
[
*
v1
.
Namespace
]
SecretMock
*
fake
.
MockControllerInterface
[
*
v1
.
Secret
,
*
v1
.
SecretList
]
NodeMock
*
fake
.
MockNonNamespacedControllerInterface
[
*
v1
.
Node
,
*
v1
.
NodeList
]
ServiceMock
*
fake
.
MockControllerInterface
[
*
v1
.
Service
,
*
v1
.
ServiceList
]
NodeCache
*
fake
.
MockNonNamespacedCacheInterface
[
*
v1
.
Node
]
ServiceAccountMock
*
fake
.
MockControllerInterface
[
*
v1
.
ServiceAccount
,
*
v1
.
ServiceAccountList
]
PersistentVolumeMock
*
fake
.
MockNonNamespacedControllerInterface
[
*
v1
.
PersistentVolume
,
*
v1
.
PersistentVolumeList
]
PersistentVolumeCache
*
fake
.
MockNonNamespacedCacheInterface
[
*
v1
.
PersistentVolume
]
PersistentVolumeClaimMock
*
fake
.
MockControllerInterface
[
*
v1
.
PersistentVolumeClaim
,
*
v1
.
PersistentVolumeClaimList
]
PersistentVolumeClaimCache
*
fake
.
MockCacheInterface
[
*
v1
.
PersistentVolumeClaim
]
PodMock
*
fake
.
MockControllerInterface
[
*
v1
.
Pod
,
*
v1
.
PodList
]
PodCache
*
fake
.
MockCacheInterface
[
*
v1
.
Pod
]
SecretMock
*
fake
.
MockControllerInterface
[
*
v1
.
Secret
,
*
v1
.
SecretList
]
SecretCache
*
fake
.
MockCacheInterface
[
*
v1
.
Secret
]
ServiceMock
*
fake
.
MockControllerInterface
[
*
v1
.
Service
,
*
v1
.
ServiceList
]
ServiceCache
*
fake
.
MockCacheInterface
[
*
v1
.
Service
]
ServiceAccountMock
*
fake
.
MockControllerInterface
[
*
v1
.
ServiceAccount
,
*
v1
.
ServiceAccountList
]
ServiceAccountCache
*
fake
.
MockCacheInterface
[
*
v1
.
ServiceAccount
]
}
}
func
NewV1
(
c
*
gomock
.
Controller
)
*
V1Mock
{
func
NewV1
(
c
*
gomock
.
Controller
)
*
V1Mock
{
return
&
V1Mock
{
return
&
V1Mock
{
ConfigMapMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
ConfigMap
,
*
v1
.
ConfigMapList
](
c
),
ConfigMapMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
ConfigMap
,
*
v1
.
ConfigMapList
](
c
),
EndpointsMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Endpoints
,
*
v1
.
EndpointsList
](
c
),
ConfigMapCache
:
fake
.
NewMockCacheInterface
[
*
v1
.
ConfigMap
](
c
),
EventMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Event
,
*
v1
.
EventList
](
c
),
EndpointsMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Endpoints
,
*
v1
.
EndpointsList
](
c
),
NamespaceMock
:
fake
.
NewMockNonNamespacedControllerInterface
[
*
v1
.
Namespace
,
*
v1
.
NamespaceList
](
c
),
EndpointsCache
:
fake
.
NewMockCacheInterface
[
*
v1
.
Endpoints
](
c
),
NodeMock
:
fake
.
NewMockNonNamespacedControllerInterface
[
*
v1
.
Node
,
*
v1
.
NodeList
](
c
),
EventMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Event
,
*
v1
.
EventList
](
c
),
PersistentVolumeMock
:
fake
.
NewMockNonNamespacedControllerInterface
[
*
v1
.
PersistentVolume
,
*
v1
.
PersistentVolumeList
](
c
),
EventCache
:
fake
.
NewMockCacheInterface
[
*
v1
.
Event
](
c
),
PersistentVolumeClaimMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
PersistentVolumeClaim
,
*
v1
.
PersistentVolumeClaimList
](
c
),
NamespaceMock
:
fake
.
NewMockNonNamespacedControllerInterface
[
*
v1
.
Namespace
,
*
v1
.
NamespaceList
](
c
),
PodMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Pod
,
*
v1
.
PodList
](
c
),
NamespaceCache
:
fake
.
NewMockNonNamespacedCacheInterface
[
*
v1
.
Namespace
](
c
),
SecretMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Secret
,
*
v1
.
SecretList
](
c
),
NodeMock
:
fake
.
NewMockNonNamespacedControllerInterface
[
*
v1
.
Node
,
*
v1
.
NodeList
](
c
),
ServiceMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Service
,
*
v1
.
ServiceList
](
c
),
NodeCache
:
fake
.
NewMockNonNamespacedCacheInterface
[
*
v1
.
Node
](
c
),
ServiceAccountMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
ServiceAccount
,
*
v1
.
ServiceAccountList
](
c
),
PersistentVolumeMock
:
fake
.
NewMockNonNamespacedControllerInterface
[
*
v1
.
PersistentVolume
,
*
v1
.
PersistentVolumeList
](
c
),
PersistentVolumeCache
:
fake
.
NewMockNonNamespacedCacheInterface
[
*
v1
.
PersistentVolume
](
c
),
PersistentVolumeClaimMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
PersistentVolumeClaim
,
*
v1
.
PersistentVolumeClaimList
](
c
),
PersistentVolumeClaimCache
:
fake
.
NewMockCacheInterface
[
*
v1
.
PersistentVolumeClaim
](
c
),
PodMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Pod
,
*
v1
.
PodList
](
c
),
PodCache
:
fake
.
NewMockCacheInterface
[
*
v1
.
Pod
](
c
),
SecretMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Secret
,
*
v1
.
SecretList
](
c
),
SecretCache
:
fake
.
NewMockCacheInterface
[
*
v1
.
Secret
](
c
),
ServiceMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
Service
,
*
v1
.
ServiceList
](
c
),
ServiceCache
:
fake
.
NewMockCacheInterface
[
*
v1
.
Service
](
c
),
ServiceAccountMock
:
fake
.
NewMockControllerInterface
[
*
v1
.
ServiceAccount
,
*
v1
.
ServiceAccountList
](
c
),
ServiceAccountCache
:
fake
.
NewMockCacheInterface
[
*
v1
.
ServiceAccount
](
c
),
}
}
}
}
...
@@ -108,6 +132,89 @@ func (m *V1Mock) ServiceAccount() corev1.ServiceAccountController {
...
@@ -108,6 +132,89 @@ func (m *V1Mock) ServiceAccount() corev1.ServiceAccountController {
return
m
.
ServiceAccountMock
return
m
.
ServiceAccountMock
}
}
// mock secret store interface
type
SecretStore
struct
{
secrets
map
[
string
]
map
[
string
]
v1
.
Secret
}
func
(
m
*
SecretStore
)
Create
(
secret
*
v1
.
Secret
)
(
*
v1
.
Secret
,
error
)
{
if
m
.
secrets
==
nil
{
m
.
secrets
=
map
[
string
]
map
[
string
]
v1
.
Secret
{}
}
if
_
,
ok
:=
m
.
secrets
[
secret
.
Namespace
];
!
ok
{
m
.
secrets
[
secret
.
Namespace
]
=
map
[
string
]
v1
.
Secret
{}
}
if
_
,
ok
:=
m
.
secrets
[
secret
.
Namespace
][
secret
.
Name
];
ok
{
return
nil
,
ErrorAlreadyExists
(
"secret"
,
secret
.
Name
)
}
m
.
secrets
[
secret
.
Namespace
][
secret
.
Name
]
=
*
secret
return
secret
,
nil
}
func
(
m
*
SecretStore
)
Delete
(
namespace
,
name
string
,
options
*
metav1
.
DeleteOptions
)
error
{
if
m
.
secrets
==
nil
{
return
ErrorNotFound
(
"secret"
,
name
)
}
if
_
,
ok
:=
m
.
secrets
[
namespace
];
!
ok
{
return
ErrorNotFound
(
"secret"
,
name
)
}
if
_
,
ok
:=
m
.
secrets
[
namespace
][
name
];
!
ok
{
return
ErrorNotFound
(
"secret"
,
name
)
}
delete
(
m
.
secrets
[
namespace
],
name
)
return
nil
}
func
(
m
*
SecretStore
)
Get
(
namespace
,
name
string
)
(
*
v1
.
Secret
,
error
)
{
if
m
.
secrets
==
nil
{
return
nil
,
ErrorNotFound
(
"secret"
,
name
)
}
if
_
,
ok
:=
m
.
secrets
[
namespace
];
!
ok
{
return
nil
,
ErrorNotFound
(
"secret"
,
name
)
}
if
secret
,
ok
:=
m
.
secrets
[
namespace
][
name
];
ok
{
return
&
secret
,
nil
}
return
nil
,
ErrorNotFound
(
"secret"
,
name
)
}
// mock node store interface
type
NodeStore
struct
{
nodes
map
[
string
]
v1
.
Node
}
func
(
m
*
NodeStore
)
Create
(
node
*
v1
.
Node
)
(
*
v1
.
Node
,
error
)
{
if
m
.
nodes
==
nil
{
m
.
nodes
=
map
[
string
]
v1
.
Node
{}
}
if
_
,
ok
:=
m
.
nodes
[
node
.
Name
];
ok
{
return
nil
,
ErrorAlreadyExists
(
"node"
,
node
.
Name
)
}
m
.
nodes
[
node
.
Name
]
=
*
node
return
node
,
nil
}
func
(
m
*
NodeStore
)
List
(
ls
labels
.
Selector
)
([]
v1
.
Node
,
error
)
{
nodes
:=
[]
v1
.
Node
{}
if
ls
==
nil
{
ls
=
labels
.
Everything
()
}
for
_
,
node
:=
range
m
.
nodes
{
if
ls
.
Matches
(
labels
.
Set
(
node
.
Labels
))
{
nodes
=
append
(
nodes
,
node
)
}
}
return
nodes
,
nil
}
// utility functions
func
ErrorNotFound
(
gv
,
name
string
)
error
{
func
ErrorNotFound
(
gv
,
name
string
)
error
{
return
apierrors
.
NewNotFound
(
schema
.
ParseGroupResource
(
gv
),
name
)
return
apierrors
.
NewNotFound
(
schema
.
ParseGroupResource
(
gv
),
name
)
}
}
func
ErrorAlreadyExists
(
gv
,
name
string
)
error
{
return
apierrors
.
NewAlreadyExists
(
schema
.
ParseGroupResource
(
gv
),
name
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment