Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / github.com / coreos / prometheus-operator / pkg / apis / monitoring / v1 / crd_kinds.go
1 // Copyright 2018 The prometheus-operator Authors
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 package v1
16
17 import (
18         "fmt"
19         "strings"
20 )
21
22 type CrdKind struct {
23         Kind     string
24         Plural   string
25         SpecName string
26 }
27
28 type CrdKinds struct {
29         KindsString    string
30         Prometheus     CrdKind
31         Alertmanager   CrdKind
32         ServiceMonitor CrdKind
33         PrometheusRule CrdKind
34 }
35
36 var DefaultCrdKinds = CrdKinds{
37         KindsString:    "",
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"},
42 }
43
44 // Implement the flag.Value interface
45 func (crdkinds *CrdKinds) String() string {
46         return crdkinds.KindsString
47 }
48
49 // Set Implement the flag.Set interface
50 func (crdkinds *CrdKinds) Set(value string) error {
51         *crdkinds = DefaultCrdKinds
52         if value == "" {
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,
58                 )
59         }
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
74                 default:
75                         fmt.Printf("Warning: unknown kind: %s... ignoring", kindKey)
76                 }
77
78         }
79         (*crdkinds).KindsString = value
80         return nil
81 }