1 // Copyright 2018 The prometheus-operator Authors
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
28 type CrdKinds struct {
32 ServiceMonitor CrdKind
33 PrometheusRule CrdKind
36 var DefaultCrdKinds = CrdKinds{
38 Prometheus: CrdKind{Plural: PrometheusName, Kind: PrometheusesKind, SpecName: "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1.Prometheus"},
39 ServiceMonitor: CrdKind{Plural: ServiceMonitorName, Kind: ServiceMonitorsKind, SpecName: "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1.ServiceMonitor"},
40 Alertmanager: CrdKind{Plural: AlertmanagerName, Kind: AlertmanagersKind, SpecName: "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1.Alertmanager"},
41 PrometheusRule: CrdKind{Plural: PrometheusRuleName, Kind: PrometheusRuleKind, SpecName: "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1.PrometheusRule"},
44 // Implement the flag.Value interface
45 func (crdkinds *CrdKinds) String() string {
46 return crdkinds.KindsString
49 // Set Implement the flag.Set interface
50 func (crdkinds *CrdKinds) Set(value string) error {
51 *crdkinds = DefaultCrdKinds
53 value = fmt.Sprintf("%s=%s:%s,%s=%s:%s,%s=%s:%s,%s=%s:%s",
54 PrometheusKindKey, PrometheusesKind, PrometheusName,
55 AlertManagerKindKey, AlertmanagersKind, AlertmanagerName,
56 ServiceMonitorKindKey, ServiceMonitorsKind, ServiceMonitorName,
57 PrometheusRuleKindKey, PrometheusRuleKind, PrometheusRuleName,
60 splited := strings.Split(value, ",")
61 for _, pair := range splited {
62 sp := strings.Split(pair, "=")
63 kind := strings.Split(sp[1], ":")
64 crdKind := CrdKind{Plural: kind[1], Kind: kind[0]}
65 switch kindKey := sp[0]; kindKey {
66 case PrometheusKindKey:
67 (*crdkinds).Prometheus = crdKind
68 case ServiceMonitorKindKey:
69 (*crdkinds).ServiceMonitor = crdKind
70 case AlertManagerKindKey:
71 (*crdkinds).Alertmanager = crdKind
72 case PrometheusRuleKindKey:
73 (*crdkinds).PrometheusRule = crdKind
75 fmt.Printf("Warning: unknown kind: %s... ignoring", kindKey)
79 (*crdkinds).KindsString = value