Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Tke
Commits
069da4cb
Commit
069da4cb
authored
5 years ago
by
liangyuzhou
Browse files
Options
Download
Email Patches
Plain Diff
fix: add missed collector validation of monitor
parent
cbf5d4ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/monitor/registry/collector/validation.go
+22
-0
pkg/monitor/registry/collector/validation.go
pkg/platform/registry/cluster/validation.go
+1
-1
pkg/platform/registry/cluster/validation.go
with
23 additions
and
1 deletion
+23
-1
pkg/monitor/registry/collector/validation.go
+
22
-
0
View file @
069da4cb
...
...
@@ -19,7 +19,10 @@
package
collector
import
(
"fmt"
apimachineryvalidation
"k8s.io/apimachinery/pkg/api/validation"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
"tkestack.io/tke/api/monitor"
)
...
...
@@ -28,6 +31,11 @@ import (
// subdomain.
var
ValidateName
=
apimachineryvalidation
.
ValidateNamespaceName
var
types
=
sets
.
NewString
(
string
(
monitor
.
CollectorImportedPrometheus
),
string
(
monitor
.
CollectorManaged
),
)
// ValidateCollector tests if required fields in the cluster are set.
func
ValidateCollector
(
collector
*
monitor
.
Collector
)
field
.
ErrorList
{
allErrs
:=
apimachineryvalidation
.
ValidateObjectMeta
(
&
collector
.
ObjectMeta
,
false
,
ValidateName
,
field
.
NewPath
(
"metadata"
))
...
...
@@ -36,6 +44,20 @@ func ValidateCollector(collector *monitor.Collector) field.ErrorList {
allErrs
=
append
(
allErrs
,
field
.
Required
(
field
.
NewPath
(
"spec"
,
"clusterName"
),
"must specify a cluster name"
))
}
if
collector
.
Spec
.
Type
==
""
{
allErrs
=
append
(
allErrs
,
field
.
Required
(
field
.
NewPath
(
"spec"
,
"type"
),
fmt
.
Sprintf
(
"available type are %v"
,
types
)))
}
else
{
if
!
types
.
Has
(
string
(
collector
.
Spec
.
Type
))
{
allErrs
=
append
(
allErrs
,
field
.
NotSupported
(
field
.
NewPath
(
"spec"
,
"type"
),
collector
.
Spec
.
Type
,
types
.
List
()))
}
if
collector
.
Spec
.
Type
==
monitor
.
CollectorManaged
{
if
collector
.
Spec
.
Version
==
""
{
allErrs
=
append
(
allErrs
,
field
.
Required
(
field
.
NewPath
(
"spec"
,
"version"
),
"must specify collector version"
))
}
}
}
return
allErrs
}
...
...
This diff is collapsed.
Click to expand it.
pkg/platform/registry/cluster/validation.go
+
1
-
1
View file @
069da4cb
...
...
@@ -62,7 +62,7 @@ func ValidateCluster(clusterProviders *sync.Map, obj *platform.Cluster, platform
}
if
obj
.
Spec
.
Type
==
""
{
allErrs
=
append
(
allErrs
,
field
.
Required
(
field
.
NewPath
(
"spec"
,
"type"
),
fmt
.
Sprintf
(
"availble type are %v"
,
types
)))
allErrs
=
append
(
allErrs
,
field
.
Required
(
field
.
NewPath
(
"spec"
,
"type"
),
fmt
.
Sprintf
(
"avail
a
ble type are %v"
,
types
)))
}
else
{
if
!
types
.
Has
(
string
(
obj
.
Spec
.
Type
))
{
allErrs
=
append
(
allErrs
,
field
.
NotSupported
(
field
.
NewPath
(
"spec"
,
"type"
),
obj
.
Spec
.
Type
,
types
.
List
()))
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help