1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-06 17:14:13 +00:00

*: Fix CRD generation

This commit is contained in:
Frederic Branczyk 2018-07-02 16:17:39 +02:00
parent d40211d952
commit edcf458e9c
No known key found for this signature in database
GPG key ID: 7741A52782A90069
16 changed files with 224 additions and 128 deletions

2
Gopkg.lock generated
View file

@ -32,7 +32,7 @@
branch = "master"
name = "github.com/ant31/crd-validation"
packages = ["pkg"]
revision = "eabcf70a1bd73e9296fa0c5f57de604689200a1b"
revision = "30f8a35d0ac2d8a2825c78ff47885979e3ee1121"
[[projects]]
branch = "master"

View file

@ -72,6 +72,10 @@ func main() {
SpecName: cfg.SpecDefinitionName},
cfg.Group, cfg.Labels.LabelsMap, cfg.EnableValidation)
crdutils.MarshallCrd(crd, cfg.OutputFormat)
err := crdutils.MarshallCrd(crd, cfg.OutputFormat)
if err != nil {
fmt.Println("Error: ", err)
os.Exit(1)
}
os.Exit(0)
}

View file

@ -11,7 +11,6 @@ spec:
scope: Namespaced
validation:
openAPIV3Schema:
description: Alertmanager describes an Alertmanager cluster.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
@ -815,7 +814,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -830,7 +832,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
preStop:
@ -882,7 +887,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -897,7 +905,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
livenessProbe:
@ -955,7 +966,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -986,7 +1000,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
timeoutSeconds:
@ -1095,7 +1112,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -1126,7 +1146,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
timeoutSeconds:
@ -2379,12 +2402,4 @@ spec:
- updatedReplicas
- availableReplicas
- unavailableReplicas
required:
- spec
version: v1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null

View file

@ -11,7 +11,6 @@ spec:
scope: Namespaced
validation:
openAPIV3Schema:
description: Prometheus defines a Prometheus deployment.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
@ -640,7 +639,10 @@ spec:
pathPrefix:
description: Prefix for the HTTP path alerts are pushed to.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use when firing alerts.
type: string
@ -898,7 +900,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -913,7 +918,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
preStop:
@ -965,7 +973,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -980,7 +991,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
livenessProbe:
@ -1038,7 +1052,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -1069,7 +1086,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
timeoutSeconds:
@ -1178,7 +1198,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -1209,7 +1232,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
timeoutSeconds:
@ -2961,12 +2987,4 @@ spec:
- updatedReplicas
- availableReplicas
- unavailableReplicas
required:
- spec
version: v1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null

View file

@ -11,7 +11,6 @@ spec:
scope: Namespaced
validation:
openAPIV3Schema:
description: PrometheusRule defines alerting rules for a Prometheus instance
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
@ -337,12 +336,4 @@ spec:
- name
- rules
type: array
required:
- spec
version: v1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null

View file

@ -11,7 +11,6 @@ spec:
scope: Namespaced
validation:
openAPIV3Schema:
description: ServiceMonitor defines monitoring for a set of services.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
@ -143,7 +142,10 @@ spec:
scrapeTimeout:
description: Timeout after which the scrape is ended
type: string
targetPort: {}
targetPort:
anyOf:
- type: string
- type: integer
tlsConfig:
description: TLSConfig specifies TLS configuration parameters.
properties:
@ -230,12 +232,4 @@ spec:
required:
- endpoints
- selector
required:
- spec
version: v1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null

View file

@ -12,7 +12,6 @@ spec:
scope: Namespaced
validation:
openAPIV3Schema:
description: Alertmanager describes an Alertmanager cluster.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
@ -816,7 +815,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -831,7 +833,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
preStop:
@ -883,7 +888,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -898,7 +906,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
livenessProbe:
@ -956,7 +967,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -987,7 +1001,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
timeoutSeconds:
@ -1096,7 +1113,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -1127,7 +1147,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
timeoutSeconds:
@ -2380,12 +2403,4 @@ spec:
- updatedReplicas
- availableReplicas
- unavailableReplicas
required:
- spec
version: v1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null

View file

@ -12,7 +12,6 @@ spec:
scope: Namespaced
validation:
openAPIV3Schema:
description: Prometheus defines a Prometheus deployment.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
@ -641,7 +640,10 @@ spec:
pathPrefix:
description: Prefix for the HTTP path alerts are pushed to.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use when firing alerts.
type: string
@ -899,7 +901,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -914,7 +919,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
preStop:
@ -966,7 +974,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -981,7 +992,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
livenessProbe:
@ -1039,7 +1053,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -1070,7 +1087,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
timeoutSeconds:
@ -1179,7 +1199,10 @@ spec:
path:
description: Path to access on the HTTP server.
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
scheme:
description: Scheme to use for connecting to the host.
Defaults to HTTP.
@ -1210,7 +1233,10 @@ spec:
description: 'Optional: Host name to connect to, defaults
to the pod IP.'
type: string
port: {}
port:
anyOf:
- type: string
- type: integer
required:
- port
timeoutSeconds:
@ -2962,12 +2988,4 @@ spec:
- updatedReplicas
- availableReplicas
- unavailableReplicas
required:
- spec
version: v1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null

View file

@ -12,7 +12,6 @@ spec:
scope: Namespaced
validation:
openAPIV3Schema:
description: PrometheusRule defines alerting rules for a Prometheus instance
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
@ -338,12 +337,4 @@ spec:
- name
- rules
type: array
required:
- spec
version: v1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null

View file

@ -12,7 +12,6 @@ spec:
scope: Namespaced
validation:
openAPIV3Schema:
description: ServiceMonitor defines monitoring for a set of services.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
@ -144,7 +143,10 @@ spec:
scrapeTimeout:
description: Timeout after which the scrape is ended
type: string
targetPort: {}
targetPort:
anyOf:
- type: string
- type: integer
tlsConfig:
description: TLSConfig specifies TLS configuration parameters.
properties:
@ -231,12 +233,4 @@ spec:
required:
- endpoints
- selector
required:
- spec
version: v1
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -17,12 +17,13 @@ package crdvalidation
import (
"encoding/json"
"flag"
"fmt"
"os"
"strings"
"github.com/ghodss/yaml"
extensionsobj "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"strings"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
// Config stores the user configuration input
@ -37,6 +38,8 @@ type Config struct {
Kind string
Version string
Plural string
Categories []string
ShortNames []string
GetOpenAPIDefinitions GetAPIDefinitions
}
@ -92,8 +95,10 @@ func NewCustomResourceDefinition(config Config) *extensionsobj.CustomResourceDef
Version: config.Version,
Scope: extensionsobj.ResourceScope(config.ResourceScope),
Names: extensionsobj.CustomResourceDefinitionNames{
Plural: config.Plural,
Kind: config.Kind,
Plural: config.Plural,
Kind: config.Kind,
Categories: config.Categories,
ShortNames: config.ShortNames,
},
},
}
@ -105,22 +110,47 @@ func NewCustomResourceDefinition(config Config) *extensionsobj.CustomResourceDef
return crd
}
func MarshallCrd(crd *extensionsobj.CustomResourceDefinition, outputFormat string) {
jsonBytes, err := json.MarshalIndent(crd, "", " ")
func MarshallCrd(crd *extensionsobj.CustomResourceDefinition, outputFormat string) error {
jsonBytes, err := json.Marshal(crd)
if err != nil {
fmt.Println("error:", err)
return err
}
var r unstructured.Unstructured
if err := json.Unmarshal(jsonBytes, &r.Object); err != nil {
return err
}
unstructured.RemoveNestedField(r.Object, "status")
jsonBytes, err = json.MarshalIndent(r.Object, "", " ")
if err != nil {
return err
}
if outputFormat == "json" {
os.Stdout.Write(jsonBytes)
_, err = os.Stdout.Write(jsonBytes)
if err != nil {
return err
}
} else {
yamlBytes, err := yaml.JSONToYAML(jsonBytes)
if err != nil {
fmt.Println("error:", err)
return err
}
_, err = os.Stdout.Write([]byte("---\n"))
if err != nil {
return err
}
_, err = os.Stdout.Write(yamlBytes)
if err != nil {
return err
}
os.Stdout.Write([]byte("---\n"))
os.Stdout.Write(yamlBytes)
}
return nil
}
// InitFlags prepares command line flags parser

View file

@ -38,9 +38,35 @@ func GetCustomResourceValidations(fn GetAPIDefinitions) map[string]*extensionsob
// GetCustomResourceValidation returns the validation definition for a CRD name
func GetCustomResourceValidation(name string, fn func(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition) *extensionsobj.CustomResourceValidation {
openapiSpec := fn(OpenAPIRefCallBack)
fixKnownTypes(openapiSpec)
schema := openapiSpec[name].Schema
return &extensionsobj.CustomResourceValidation{
crv := &extensionsobj.CustomResourceValidation{
OpenAPIV3Schema: SchemaPropsToJSONProps(&schema, openapiSpec, true),
}
crv.OpenAPIV3Schema.Description = ""
crv.OpenAPIV3Schema.Required = nil
return crv
}
// ref: https://github.com/kubernetes/kubernetes/issues/62329
func fixKnownTypes(openapiSpec map[string]common.OpenAPIDefinition) {
openapiSpec["k8s.io/apimachinery/pkg/util/intstr.IntOrString"] = common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
AnyOf: []spec.Schema{
{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
{
SchemaProps: spec.SchemaProps{
Type: []string{"integer"},
},
},
},
},
},
}
}