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
ad4c2ee6
Commit
ad4c2ee6
authored
Feb 04, 2015
by
Jerzy Szczepkowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve "constraint violation" error message.
parent
63c07ad5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
10 deletions
+16
-10
constraint.go
pkg/constraint/constraint.go
+7
-2
constraint_test.go
pkg/constraint/constraint_test.go
+7
-6
etcd.go
pkg/registry/etcd/etcd.go
+2
-2
No files found.
pkg/constraint/constraint.go
View file @
ad4c2ee6
...
@@ -17,11 +17,16 @@ limitations under the License.
...
@@ -17,11 +17,16 @@ limitations under the License.
package
constraint
package
constraint
import
(
import
(
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
)
// Allowed returns true if pods is a collection of bound pods
// Allowed returns true if pods is a collection of bound pods
// which can run without conflict on a single minion.
// which can run without conflict on a single minion.
func
Allowed
(
pods
[]
api
.
BoundPod
)
bool
{
func
Allowed
(
pods
[]
api
.
BoundPod
)
error
{
return
!
PortsConflict
(
pods
)
if
(
PortsConflict
(
pods
))
{
return
fmt
.
Errorf
(
"conflicting ports"
);
}
return
nil
;
}
}
pkg/constraint/constraint_test.go
View file @
ad4c2ee6
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
constraint
package
constraint
import
(
import
(
"fmt"
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
@@ -40,11 +41,11 @@ func podWithContainers(containers ...api.Container) api.BoundPod {
...
@@ -40,11 +41,11 @@ func podWithContainers(containers ...api.Container) api.BoundPod {
func
TestAllowed
(
t
*
testing
.
T
)
{
func
TestAllowed
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
table
:=
[]
struct
{
allowed
bool
err
error
pods
[]
api
.
BoundPod
pods
[]
api
.
BoundPod
}{
}{
{
{
allowed
:
true
,
err
:
nil
,
pods
:
[]
api
.
BoundPod
{
pods
:
[]
api
.
BoundPod
{
podWithContainers
(
podWithContainers
(
containerWithHostPorts
(
1
,
2
,
3
),
containerWithHostPorts
(
1
,
2
,
3
),
...
@@ -57,7 +58,7 @@ func TestAllowed(t *testing.T) {
...
@@ -57,7 +58,7 @@ func TestAllowed(t *testing.T) {
},
},
},
},
{
{
allowed
:
true
,
err
:
nil
,
pods
:
[]
api
.
BoundPod
{
pods
:
[]
api
.
BoundPod
{
podWithContainers
(
podWithContainers
(
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
...
@@ -70,7 +71,7 @@ func TestAllowed(t *testing.T) {
...
@@ -70,7 +71,7 @@ func TestAllowed(t *testing.T) {
},
},
},
},
{
{
allowed
:
false
,
err
:
fmt
.
Errorf
(
"conflicting ports"
)
,
pods
:
[]
api
.
BoundPod
{
pods
:
[]
api
.
BoundPod
{
podWithContainers
(
podWithContainers
(
containerWithHostPorts
(
3
,
3
),
containerWithHostPorts
(
3
,
3
),
...
@@ -78,7 +79,7 @@ func TestAllowed(t *testing.T) {
...
@@ -78,7 +79,7 @@ func TestAllowed(t *testing.T) {
},
},
},
},
{
{
allowed
:
false
,
err
:
fmt
.
Errorf
(
"conflicting ports"
)
,
pods
:
[]
api
.
BoundPod
{
pods
:
[]
api
.
BoundPod
{
podWithContainers
(
podWithContainers
(
containerWithHostPorts
(
6
),
containerWithHostPorts
(
6
),
...
@@ -91,7 +92,7 @@ func TestAllowed(t *testing.T) {
...
@@ -91,7 +92,7 @@ func TestAllowed(t *testing.T) {
}
}
for
_
,
item
:=
range
table
{
for
_
,
item
:=
range
table
{
if
e
,
a
:=
item
.
allowed
,
Allowed
(
item
.
pods
);
e
!=
a
{
if
e
,
a
:=
item
.
err
,
Allowed
(
item
.
pods
);
e
!=
a
&&
e
.
Error
()
!=
a
.
Error
()
{
t
.
Errorf
(
"Expected %v, got %v:
\n
%v
\v
"
,
e
,
a
,
item
.
pods
)
t
.
Errorf
(
"Expected %v, got %v:
\n
%v
\v
"
,
e
,
a
,
item
.
pods
)
}
}
}
}
...
...
pkg/registry/etcd/etcd.go
View file @
ad4c2ee6
...
@@ -214,8 +214,8 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro
...
@@ -214,8 +214,8 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro
err
=
r
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
err
=
r
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
boundPodList
:=
in
.
(
*
api
.
BoundPods
)
boundPodList
:=
in
.
(
*
api
.
BoundPods
)
boundPodList
.
Items
=
append
(
boundPodList
.
Items
,
*
boundPod
)
boundPodList
.
Items
=
append
(
boundPodList
.
Items
,
*
boundPod
)
if
!
constraint
.
Allowed
(
boundPodList
.
Items
)
{
if
e
:=
constraint
.
Allowed
(
boundPodList
.
Items
);
e
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"the assignment would cause
a constraint violation"
)
return
nil
,
fmt
.
Errorf
(
"the assignment would cause
the following constraint violation: %v"
,
e
)
}
}
return
boundPodList
,
nil
return
boundPodList
,
nil
})
})
...
...
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