mirror of
https://github.com/rancher/types.git
synced 2025-04-28 02:30:07 +00:00
Add Prometheus operrator crds into schema
This commit is contained in:
parent
6adc7c9769
commit
25fb96b983
@ -3,6 +3,7 @@ package schema
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
"github.com/rancher/norman/types"
|
||||
m "github.com/rancher/norman/types/mapper"
|
||||
"github.com/rancher/types/apis/project.cattle.io/v3"
|
||||
@ -42,7 +43,8 @@ var (
|
||||
Init(podTemplateSpecTypes).
|
||||
Init(workloadTypes).
|
||||
Init(appTypes).
|
||||
Init(pipelineTypes)
|
||||
Init(pipelineTypes).
|
||||
Init(monitoringTypes)
|
||||
)
|
||||
|
||||
func configMapTypes(schemas *types.Schemas) *types.Schemas {
|
||||
@ -923,3 +925,88 @@ func pipelineTypes(schema *types.Schemas) *types.Schemas {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func monitoringTypes(schemas *types.Schemas) *types.Schemas {
|
||||
return schemas.
|
||||
AddMapperForType(&Version, monitoringv1.StorageSpec{},
|
||||
&m.Drop{Field: "class"},
|
||||
&m.Drop{Field: "selector"},
|
||||
&m.Drop{Field: "resources"},
|
||||
).
|
||||
AddMapperForType(&Version, monitoringv1.Prometheus{},
|
||||
&m.Drop{Field: "status"},
|
||||
&m.AnnotationField{Field: "description"},
|
||||
).
|
||||
AddMapperForType(&Version, monitoringv1.PrometheusSpec{},
|
||||
&m.Drop{Field: "thanos"},
|
||||
&m.Drop{Field: "apiserverConfig"},
|
||||
&m.Drop{Field: "serviceMonitorNamespaceSelector"},
|
||||
&m.Drop{Field: "ruleNamespaceSelector"},
|
||||
&m.Drop{Field: "paused"},
|
||||
&m.Enum{
|
||||
Field: "logLevel",
|
||||
Options: []string{
|
||||
"all",
|
||||
"debug",
|
||||
"info",
|
||||
"warn",
|
||||
"error",
|
||||
"none",
|
||||
},
|
||||
},
|
||||
).
|
||||
MustImportAndCustomize(&Version, monitoringv1.Prometheus{}, func(schema *types.Schema) {
|
||||
schema.MustCustomizeField("name", func(field types.Field) types.Field {
|
||||
field.Type = "dnsLabelRestricted"
|
||||
field.Nullable = false
|
||||
field.Required = true
|
||||
return field
|
||||
})
|
||||
}, projectOverride{}, struct {
|
||||
Description string `json:"description"`
|
||||
}{}).
|
||||
AddMapperForType(&Version, monitoringv1.RelabelConfig{},
|
||||
&m.Enum{
|
||||
Field: "action",
|
||||
Options: []string{
|
||||
"replace",
|
||||
"keep",
|
||||
"drop",
|
||||
"hashmod",
|
||||
"labelmap",
|
||||
"labeldrop",
|
||||
"labelkeep",
|
||||
},
|
||||
},
|
||||
).
|
||||
AddMapperForType(&Version, monitoringv1.Endpoint{},
|
||||
&m.Drop{Field: "port"},
|
||||
&m.Drop{Field: "tlsConfig"},
|
||||
&m.Drop{Field: "bearerTokenFile"},
|
||||
&m.Drop{Field: "honorLabels"},
|
||||
&m.Drop{Field: "basicAuth"},
|
||||
&m.Drop{Field: "metricRelabelings"},
|
||||
&m.Drop{Field: "proxyUrl"},
|
||||
).
|
||||
AddMapperForType(&Version, monitoringv1.ServiceMonitorSpec{},
|
||||
&m.Embed{Field: "namespaceSelector"},
|
||||
&m.Drop{Field: "any"},
|
||||
&m.Move{From: "matchNames", To: "namespaceSelector"},
|
||||
).
|
||||
AddMapperForType(&Version, monitoringv1.ServiceMonitor{},
|
||||
&m.AnnotationField{Field: "displayName"},
|
||||
&m.DisplayName{},
|
||||
&m.AnnotationField{Field: "targetService"},
|
||||
&m.AnnotationField{Field: "targetWorkload"},
|
||||
).
|
||||
MustImport(&Version, monitoringv1.ServiceMonitor{}, projectOverride{}, struct {
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
TargetService string `json:"targetService,omitempty"`
|
||||
TargetWorkload string `json:"targetWorkload,omitempty"`
|
||||
}{}).
|
||||
MustImport(&Version, monitoringv1.PrometheusRule{}, projectOverride{}).
|
||||
AddMapperForType(&Version, monitoringv1.Alertmanager{},
|
||||
&m.Drop{Field: "status"},
|
||||
).
|
||||
MustImport(&Version, monitoringv1.Alertmanager{}, projectOverride{})
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
extv1beta1 "github.com/rancher/types/apis/extensions/v1beta1"
|
||||
managementv3 "github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
managementSchema "github.com/rancher/types/apis/management.cattle.io/v3/schema"
|
||||
monitoringv1 "github.com/rancher/types/apis/monitoring.coreos.com/v1"
|
||||
knetworkingv1 "github.com/rancher/types/apis/networking.k8s.io/v1"
|
||||
projectv3 "github.com/rancher/types/apis/project.cattle.io/v3"
|
||||
projectSchema "github.com/rancher/types/apis/project.cattle.io/v3/schema"
|
||||
@ -181,6 +182,7 @@ type UserContext struct {
|
||||
BatchV1 batchv1.Interface
|
||||
BatchV1Beta1 batchv1beta1.Interface
|
||||
Networking knetworkingv1.Interface
|
||||
Monitoring monitoringv1.Interface
|
||||
}
|
||||
|
||||
func (w *UserContext) controllers() []controller.Starter {
|
||||
@ -193,6 +195,7 @@ func (w *UserContext) controllers() []controller.Starter {
|
||||
w.BatchV1,
|
||||
w.BatchV1Beta1,
|
||||
w.Networking,
|
||||
w.Monitoring,
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,6 +214,7 @@ func (w *UserContext) UserOnlyContext() *UserOnlyContext {
|
||||
Extensions: w.Extensions,
|
||||
BatchV1: w.BatchV1,
|
||||
BatchV1Beta1: w.BatchV1Beta1,
|
||||
Monitoring: w.Monitoring,
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,6 +232,7 @@ type UserOnlyContext struct {
|
||||
Extensions extv1beta1.Interface
|
||||
BatchV1 batchv1.Interface
|
||||
BatchV1Beta1 batchv1beta1.Interface
|
||||
Monitoring monitoringv1.Interface
|
||||
}
|
||||
|
||||
func (w *UserOnlyContext) controllers() []controller.Starter {
|
||||
@ -239,6 +244,7 @@ func (w *UserOnlyContext) controllers() []controller.Starter {
|
||||
w.Extensions,
|
||||
w.BatchV1,
|
||||
w.BatchV1Beta1,
|
||||
w.Monitoring,
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,6 +381,11 @@ func NewUserContext(scaledContext *ScaledContext, config rest.Config, clusterNam
|
||||
return nil, err
|
||||
}
|
||||
|
||||
context.Monitoring, err = monitoringv1.NewForConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dynamicConfig := config
|
||||
if dynamicConfig.NegotiatedSerializer == nil {
|
||||
dynamicConfig.NegotiatedSerializer = dynamic.NegotiatedSerializer
|
||||
@ -453,6 +464,11 @@ func NewUserOnlyContext(config rest.Config) (*UserOnlyContext, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
context.Monitoring, err = monitoringv1.NewForConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dynamicConfig := config
|
||||
if dynamicConfig.NegotiatedSerializer == nil {
|
||||
dynamicConfig.NegotiatedSerializer = dynamic.NegotiatedSerializer
|
||||
|
12
main.go
12
main.go
@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
clusterSchema "github.com/rancher/types/apis/cluster.cattle.io/v3/schema"
|
||||
managementSchema "github.com/rancher/types/apis/management.cattle.io/v3/schema"
|
||||
publicSchema "github.com/rancher/types/apis/management.cattle.io/v3public/schema"
|
||||
@ -17,6 +18,7 @@ import (
|
||||
extv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
knetworkingv1 "k8s.io/api/networking/v1"
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
k8sschema "k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -73,4 +75,14 @@ func main() {
|
||||
extv1beta1.PodSecurityPolicy{},
|
||||
},
|
||||
)
|
||||
generator.GenerateNativeTypes(
|
||||
k8sschema.GroupVersion{Group: monitoringv1.Group, Version: monitoringv1.Version},
|
||||
[]interface{}{
|
||||
monitoringv1.Prometheus{},
|
||||
monitoringv1.Alertmanager{},
|
||||
monitoringv1.PrometheusRule{},
|
||||
monitoringv1.ServiceMonitor{},
|
||||
},
|
||||
[]interface{}{},
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user