mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 11:48:53 +00:00
pkg,test: fix gofmt and much golint
This commit fixes the gofmt warning and many of the golint warnings. We still need to add comments for many exported types.
This commit is contained in:
parent
e82f7bbd51
commit
d065eea6a4
24 changed files with 100 additions and 110 deletions
pkg
client/monitoring
prometheus
test
|
@ -26,7 +26,7 @@ import (
|
|||
|
||||
// TestAlertmanagerUnstructuredTimestamps ensures that an Alertmanager with many
|
||||
// default values can be converted into an Unstructured which would be valid to
|
||||
// POST (this is primarily to ensure that creationTimestamp is ommitted).
|
||||
// POST (this is primarily to ensure that creationTimestamp is ommited).
|
||||
func TestAlertmanagerUnstructuredTimestamps(t *testing.T) {
|
||||
p := &Alertmanager{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
@ -47,7 +47,7 @@ type CrdKinds struct {
|
|||
PrometheusRule CrdKind
|
||||
}
|
||||
|
||||
var DefaultCrdKinds CrdKinds = CrdKinds{
|
||||
var DefaultCrdKinds = CrdKinds{
|
||||
KindsString: "",
|
||||
Prometheus: CrdKind{Plural: PrometheusName, Kind: PrometheusesKind, SpecName: "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.Prometheus"},
|
||||
ServiceMonitor: CrdKind{Plural: ServiceMonitorName, Kind: ServiceMonitorsKind, SpecName: "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1.ServiceMonitor"},
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
|
||||
// TestPrometheusUnstructuredTimestamps ensures that a Prometheus with many
|
||||
// default values can be converted into an Unstructured which would be valid to
|
||||
// POST (this is primarily to ensure that creationTimestamp is ommitted).
|
||||
// POST (this is primarily to ensure that creationTimestamp is ommited).
|
||||
func TestPrometheusUnstructuredTimestamps(t *testing.T) {
|
||||
p := &Prometheus{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
@ -50,7 +50,7 @@ type PrometheusList struct {
|
|||
Items []*Prometheus `json:"items"`
|
||||
}
|
||||
|
||||
// Specification of the desired behavior of the Prometheus cluster. More info:
|
||||
// PrometheusSpec is a specification of the desired behavior of the Prometheus cluster. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
|
||||
// +k8s:openapi-gen=true
|
||||
type PrometheusSpec struct {
|
||||
|
@ -176,7 +176,7 @@ type PrometheusSpec struct {
|
|||
Thanos *ThanosSpec `json:"thanos,omitempty"`
|
||||
}
|
||||
|
||||
// Most recent observed status of the Prometheus cluster. Read-only. Not
|
||||
// PrometheusStatus is the most recent observed status of the Prometheus cluster. Read-only. Not
|
||||
// included when requesting from the apiserver, only from the Prometheus
|
||||
// Operator API itself. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
|
||||
|
@ -252,7 +252,7 @@ type ThanosGCSSpec struct {
|
|||
Bucket *string `json:"bucket,omitempty"`
|
||||
}
|
||||
|
||||
// ThanosSpec defines parameters for of AWS Simple Storage Service (S3) with
|
||||
// ThanosS3Spec defines parameters for of AWS Simple Storage Service (S3) with
|
||||
// Thanos. (S3 compatible services apply as well)
|
||||
// +k8s:openapi-gen=true
|
||||
type ThanosS3Spec struct {
|
||||
|
@ -469,7 +469,7 @@ type TLSConfig struct {
|
|||
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
|
||||
}
|
||||
|
||||
// A list of ServiceMonitors.
|
||||
// ServiceMonitorList is a list of ServiceMonitors.
|
||||
// +k8s:openapi-gen=true
|
||||
type ServiceMonitorList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
@ -480,7 +480,7 @@ type ServiceMonitorList struct {
|
|||
Items []*ServiceMonitor `json:"items"`
|
||||
}
|
||||
|
||||
// A list of PrometheusRules.
|
||||
// PrometheusRuleList is a list of PrometheusRules.
|
||||
// +k8s:openapi-gen=true
|
||||
type PrometheusRuleList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
@ -549,7 +549,7 @@ type Alertmanager struct {
|
|||
Status *AlertmanagerStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// Specification of the desired behavior of the Alertmanager cluster. More info:
|
||||
// AlertmanagerSpec is a specification of the desired behavior of the Alertmanager cluster. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
|
||||
// +k8s:openapi-gen=true
|
||||
type AlertmanagerSpec struct {
|
||||
|
@ -615,7 +615,7 @@ type AlertmanagerSpec struct {
|
|||
Containers []v1.Container `json:"containers,omitempty"`
|
||||
}
|
||||
|
||||
// A list of Alertmanagers.
|
||||
// AlertmanagerList is a list of Alertmanagers.
|
||||
// +k8s:openapi-gen=true
|
||||
type AlertmanagerList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
@ -626,7 +626,7 @@ type AlertmanagerList struct {
|
|||
Items []Alertmanager `json:"items"`
|
||||
}
|
||||
|
||||
// Most recent observed status of the Alertmanager cluster. Read-only. Not
|
||||
// AlertmanagerStatus is the most recent observed status of the Alertmanager cluster. Read-only. Not
|
||||
// included when requesting from the apiserver, only from the Prometheus
|
||||
// Operator API itself. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
|
||||
|
@ -648,7 +648,7 @@ type AlertmanagerStatus struct {
|
|||
UnavailableReplicas int32 `json:"unavailableReplicas"`
|
||||
}
|
||||
|
||||
// A selector for selecting namespaces either selecting all namespaces or a
|
||||
// NamespaceSelector is a selector for selecting either all namespaces or a
|
||||
// list of namespaces.
|
||||
// +k8s:openapi-gen=true
|
||||
type NamespaceSelector struct {
|
||||
|
@ -663,34 +663,42 @@ type NamespaceSelector struct {
|
|||
// implementation to support label selections.
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *Alertmanager) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *AlertmanagerList) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *Prometheus) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *PrometheusList) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *ServiceMonitor) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *ServiceMonitorList) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (f *PrometheusRule) DeepCopyObject() runtime.Object {
|
||||
return f.DeepCopy()
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *PrometheusRuleList) DeepCopyObject() runtime.Object {
|
||||
return l.DeepCopy()
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ type PrometheusList struct {
|
|||
Items []*Prometheus `json:"items"`
|
||||
}
|
||||
|
||||
// Specification of the desired behavior of the Prometheus cluster. More info:
|
||||
// PrometheusSpec is the specification of the desired behavior of the Prometheus cluster. More info:
|
||||
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
|
||||
type PrometheusSpec struct {
|
||||
// Standard object’s metadata. More info:
|
||||
|
@ -111,7 +111,7 @@ type PrometheusSpec struct {
|
|||
// Sharding...
|
||||
}
|
||||
|
||||
// Most recent observed status of the Prometheus cluster. Read-only. Not
|
||||
// PrometheusStatus is the most recent observed status of the Prometheus cluster. Read-only. Not
|
||||
// included when requesting from the apiserver, only from the Prometheus
|
||||
// Operator API itself. More info:
|
||||
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
|
||||
|
@ -243,7 +243,7 @@ type TLSConfig struct {
|
|||
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
|
||||
}
|
||||
|
||||
// A list of ServiceMonitors.
|
||||
// ServiceMonitorList is a list of ServiceMonitors.
|
||||
type ServiceMonitorList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
// Standard list metadata
|
||||
|
@ -253,7 +253,7 @@ type ServiceMonitorList struct {
|
|||
Items []*ServiceMonitor `json:"items"`
|
||||
}
|
||||
|
||||
// Describes an Alertmanager cluster.
|
||||
// Alertmanager describes an Alertmanager cluster.
|
||||
type Alertmanager struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
// Standard object’s metadata. More info:
|
||||
|
@ -269,7 +269,7 @@ type Alertmanager struct {
|
|||
Status *AlertmanagerStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// Specification of the desired behavior of the Alertmanager cluster. More info:
|
||||
// AlertmanagerSpec is the specification of the desired behavior of the Alertmanager cluster. More info:
|
||||
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
|
||||
type AlertmanagerSpec struct {
|
||||
// Standard object’s metadata. More info:
|
||||
|
@ -309,7 +309,7 @@ type AlertmanagerSpec struct {
|
|||
Resources v1.ResourceRequirements `json:"resources,omitempty"`
|
||||
}
|
||||
|
||||
// A list of Alertmanagers.
|
||||
// AlertmanagerList is a list of Alertmanagers.
|
||||
type AlertmanagerList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
// Standard list metadata
|
||||
|
@ -319,7 +319,7 @@ type AlertmanagerList struct {
|
|||
Items []Alertmanager `json:"items"`
|
||||
}
|
||||
|
||||
// Most recent observed status of the Alertmanager cluster. Read-only. Not
|
||||
// AlertmanagerStatus is the most recent observed status of the Alertmanager cluster. Read-only. Not
|
||||
// included when requesting from the apiserver, only from the Prometheus
|
||||
// Operator API itself. More info:
|
||||
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
|
||||
|
@ -340,7 +340,7 @@ type AlertmanagerStatus struct {
|
|||
UnavailableReplicas int32 `json:"unavailableReplicas"`
|
||||
}
|
||||
|
||||
// A selector for selecting namespaces either selecting all namespaces or a
|
||||
// NamespaceSelector is a selector for selecting either all namespaces or a
|
||||
// list of namespaces.
|
||||
type NamespaceSelector struct {
|
||||
// Boolean describing whether all namespaces are selected in contrast to a
|
||||
|
@ -354,26 +354,32 @@ type NamespaceSelector struct {
|
|||
// implementation to support label selections.
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *Alertmanager) DeepCopyObject() runtime.Object {
|
||||
panic("DeepCopyObject not implemented for Alertmanager")
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *AlertmanagerList) DeepCopyObject() runtime.Object {
|
||||
panic("DeepCopyObject not implemented for AlertmanagerList")
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *Prometheus) DeepCopyObject() runtime.Object {
|
||||
panic("DeepCopyObject not implemented for Prometheus")
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *PrometheusList) DeepCopyObject() runtime.Object {
|
||||
panic("DeepCopyObject not implemented for PrometheusList")
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *ServiceMonitor) DeepCopyObject() runtime.Object {
|
||||
panic("DeepCopyObject not implemented for ServiceMonitor")
|
||||
}
|
||||
|
||||
// DeepCopyObject implements the runtime.Object interface.
|
||||
func (l *ServiceMonitorList) DeepCopyObject() runtime.Object {
|
||||
panic("DeepCopyObject not implemented for ServiceMonitorList")
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ func (labels *Labels) Merge(otherLabels map[string]string) map[string]string {
|
|||
return mergedLabels
|
||||
}
|
||||
|
||||
// Implement the flag.Set interface
|
||||
// Set implements the flag.Set interface.
|
||||
func (labels *Labels) Set(value string) error {
|
||||
m := map[string]string{}
|
||||
if value != "" {
|
||||
|
@ -909,10 +909,10 @@ func loadAdditionalScrapeConfigsSecret(additionalScrapeConfigs *v1.SecretKeySele
|
|||
return c, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("key %v could not be found in Secret %v.", additionalScrapeConfigs.Key, additionalScrapeConfigs.Name)
|
||||
return nil, fmt.Errorf("key %v could not be found in Secret %v", additionalScrapeConfigs.Key, additionalScrapeConfigs.Name)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("secret %v could not be found.", additionalScrapeConfigs.Name)
|
||||
return nil, fmt.Errorf("secret %v could not be found", additionalScrapeConfigs.Name)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -928,7 +928,7 @@ func loadBasicAuthSecret(basicAuth *monitoringv1.BasicAuth, s *v1.SecretList) (B
|
|||
if u, ok := secret.Data[basicAuth.Username.Key]; ok {
|
||||
username = string(u)
|
||||
} else {
|
||||
return BasicAuthCredentials{}, fmt.Errorf("Secret username key %q in secret %q not found.", basicAuth.Username.Key, secret.Name)
|
||||
return BasicAuthCredentials{}, fmt.Errorf("secret username key %q in secret %q not found", basicAuth.Username.Key, secret.Name)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -938,7 +938,7 @@ func loadBasicAuthSecret(basicAuth *monitoringv1.BasicAuth, s *v1.SecretList) (B
|
|||
if p, ok := secret.Data[basicAuth.Password.Key]; ok {
|
||||
password = string(p)
|
||||
} else {
|
||||
return BasicAuthCredentials{}, fmt.Errorf("Secret password key %q in secret %q not found.", basicAuth.Password.Key, secret.Name)
|
||||
return BasicAuthCredentials{}, fmt.Errorf("secret password key %q in secret %q not found", basicAuth.Password.Key, secret.Name)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -948,7 +948,7 @@ func loadBasicAuthSecret(basicAuth *monitoringv1.BasicAuth, s *v1.SecretList) (B
|
|||
}
|
||||
|
||||
if username == "" && password == "" {
|
||||
return BasicAuthCredentials{}, fmt.Errorf("BasicAuth username and password secret not found.")
|
||||
return BasicAuthCredentials{}, fmt.Errorf("basic auth username and password secret not found")
|
||||
}
|
||||
|
||||
return BasicAuthCredentials{username: username, password: password}, nil
|
||||
|
@ -956,42 +956,36 @@ func loadBasicAuthSecret(basicAuth *monitoringv1.BasicAuth, s *v1.SecretList) (B
|
|||
}
|
||||
|
||||
func (c *Operator) loadBasicAuthSecrets(mons map[string]*monitoringv1.ServiceMonitor, remoteReads []monitoringv1.RemoteReadSpec, remoteWrites []monitoringv1.RemoteWriteSpec, s *v1.SecretList) (map[string]BasicAuthCredentials, error) {
|
||||
|
||||
secrets := map[string]BasicAuthCredentials{}
|
||||
|
||||
for _, mon := range mons {
|
||||
|
||||
for i, ep := range mon.Spec.Endpoints {
|
||||
|
||||
if ep.BasicAuth != nil {
|
||||
|
||||
if credentials, err := loadBasicAuthSecret(ep.BasicAuth, s); err != nil {
|
||||
return nil, fmt.Errorf("Could not generate basicAuth for servicemonitor %s. %s", mon.Name, err)
|
||||
} else {
|
||||
secrets[fmt.Sprintf("serviceMonitor/%s/%s/%d", mon.Namespace, mon.Name, i)] = credentials
|
||||
credentials, err := loadBasicAuthSecret(ep.BasicAuth, s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not generate basicAuth for servicemonitor %s. %s", mon.Name, err)
|
||||
}
|
||||
|
||||
secrets[fmt.Sprintf("serviceMonitor/%s/%s/%d", mon.Namespace, mon.Name, i)] = credentials
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i, remote := range remoteReads {
|
||||
if remote.BasicAuth != nil {
|
||||
if credentials, err := loadBasicAuthSecret(remote.BasicAuth, s); err != nil {
|
||||
return nil, fmt.Errorf("Could not generate basicAuth for remote_read config %d. %s", i, err)
|
||||
} else {
|
||||
secrets[fmt.Sprintf("remoteRead/%d", i)] = credentials
|
||||
credentials, err := loadBasicAuthSecret(remote.BasicAuth, s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not generate basicAuth for remote_read config %d. %s", i, err)
|
||||
}
|
||||
secrets[fmt.Sprintf("remoteRead/%d", i)] = credentials
|
||||
}
|
||||
}
|
||||
|
||||
for i, remote := range remoteWrites {
|
||||
if remote.BasicAuth != nil {
|
||||
if credentials, err := loadBasicAuthSecret(remote.BasicAuth, s); err != nil {
|
||||
return nil, fmt.Errorf("Could not generate basicAuth for remote_write config %d. %s", i, err)
|
||||
} else {
|
||||
secrets[fmt.Sprintf("remoteWrite/%d", i)] = credentials
|
||||
credentials, err := loadBasicAuthSecret(remote.BasicAuth, s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not generate basicAuth for remote_write config %d. %s", i, err)
|
||||
}
|
||||
secrets[fmt.Sprintf("remoteWrite/%d", i)] = credentials
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1062,9 +1056,8 @@ func (c *Operator) createOrUpdateConfigurationSecret(p *monitoringv1.Prometheus,
|
|||
if bytes.Equal(curConfig, generatedConf) {
|
||||
level.Debug(c.logger).Log("msg", "updating Prometheus configuration secret skipped, no configuration change")
|
||||
return nil
|
||||
} else {
|
||||
level.Debug(c.logger).Log("msg", "current Prometheus configuration has changed")
|
||||
}
|
||||
level.Debug(c.logger).Log("msg", "current Prometheus configuration has changed")
|
||||
} else {
|
||||
level.Debug(c.logger).Log("msg", "no current Prometheus configuration secret found", "currentConfigFound", curConfigFound)
|
||||
}
|
||||
|
@ -1110,7 +1103,7 @@ func (c *Operator) selectServiceMonitors(p *monitoringv1.Prometheus) (map[string
|
|||
}
|
||||
|
||||
serviceMonitors := []string{}
|
||||
for k, _ := range res {
|
||||
for k := range res {
|
||||
serviceMonitors = append(serviceMonitors, k)
|
||||
}
|
||||
level.Debug(c.logger).Log("msg", "selected ServiceMonitors", "servicemonitors", strings.Join(serviceMonitors, ","), "namespace", p.Namespace, "prometheus", p.Name)
|
||||
|
|
|
@ -40,7 +40,7 @@ func stringMapToMapSlice(m map[string]string) yaml.MapSlice {
|
|||
res := yaml.MapSlice{}
|
||||
ks := make([]string, 0)
|
||||
|
||||
for k, _ := range m {
|
||||
for k := range m {
|
||||
ks = append(ks, k)
|
||||
}
|
||||
sort.Strings(ks)
|
||||
|
@ -373,15 +373,15 @@ func generateServiceMonitorConfig(version semver.Version, m *v1.ServiceMonitor,
|
|||
|
||||
// Relabel namespace and pod and service labels into proper labels.
|
||||
relabelings = append(relabelings, []yaml.MapSlice{
|
||||
yaml.MapSlice{
|
||||
{
|
||||
{Key: "source_labels", Value: []string{"__meta_kubernetes_namespace"}},
|
||||
{Key: "target_label", Value: "namespace"},
|
||||
},
|
||||
yaml.MapSlice{
|
||||
{
|
||||
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_name"}},
|
||||
{Key: "target_label", Value: "pod"},
|
||||
},
|
||||
yaml.MapSlice{
|
||||
{
|
||||
{Key: "source_labels", Value: []string{"__meta_kubernetes_service_name"}},
|
||||
{Key: "target_label", Value: "service"},
|
||||
},
|
||||
|
@ -491,7 +491,7 @@ func k8sSDWithNamespaces(namespaces []string) yaml.MapItem {
|
|||
return yaml.MapItem{
|
||||
Key: "kubernetes_sd_configs",
|
||||
Value: []yaml.MapSlice{
|
||||
yaml.MapSlice{
|
||||
{
|
||||
{
|
||||
Key: "role",
|
||||
Value: "endpoints",
|
||||
|
@ -514,7 +514,7 @@ func k8sSDAllNamespaces() yaml.MapItem {
|
|||
return yaml.MapItem{
|
||||
Key: "kubernetes_sd_configs",
|
||||
Value: []yaml.MapSlice{
|
||||
yaml.MapSlice{
|
||||
{
|
||||
{
|
||||
Key: "role",
|
||||
Value: "endpoints",
|
||||
|
|
|
@ -232,7 +232,7 @@ func makeServiceMonitors() map[string]*monitoringv1.ServiceMonitor {
|
|||
},
|
||||
},
|
||||
Endpoints: []monitoringv1.Endpoint{
|
||||
monitoringv1.Endpoint{
|
||||
{
|
||||
Port: "web",
|
||||
Interval: "30s",
|
||||
},
|
||||
|
@ -256,7 +256,7 @@ func makeServiceMonitors() map[string]*monitoringv1.ServiceMonitor {
|
|||
},
|
||||
},
|
||||
Endpoints: []monitoringv1.Endpoint{
|
||||
monitoringv1.Endpoint{
|
||||
{
|
||||
Port: "web",
|
||||
Interval: "30s",
|
||||
},
|
||||
|
@ -280,11 +280,11 @@ func makeServiceMonitors() map[string]*monitoringv1.ServiceMonitor {
|
|||
},
|
||||
},
|
||||
Endpoints: []monitoringv1.Endpoint{
|
||||
monitoringv1.Endpoint{
|
||||
{
|
||||
Port: "web",
|
||||
Interval: "30s",
|
||||
Path: "/federate",
|
||||
Params: map[string][]string{"metrics[]": []string{"{__name__=~\"job:.*\"}"}},
|
||||
Params: map[string][]string{"metrics[]": {"{__name__=~\"job:.*\"}"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -306,16 +306,16 @@ func makeServiceMonitors() map[string]*monitoringv1.ServiceMonitor {
|
|||
},
|
||||
},
|
||||
Endpoints: []monitoringv1.Endpoint{
|
||||
monitoringv1.Endpoint{
|
||||
{
|
||||
Port: "web",
|
||||
Interval: "30s",
|
||||
MetricRelabelConfigs: []*monitoringv1.RelabelConfig{
|
||||
&monitoringv1.RelabelConfig{
|
||||
{
|
||||
Action: "drop",
|
||||
Regex: "my-job-pod-.+",
|
||||
SourceLabels: []string{"pod_name"},
|
||||
},
|
||||
&monitoringv1.RelabelConfig{
|
||||
{
|
||||
Action: "drop",
|
||||
Regex: "test",
|
||||
SourceLabels: []string{"namespace"},
|
||||
|
|
|
@ -97,10 +97,12 @@ func (c *Operator) getRuleCMs(ns string, cmLabelSelector *metav1.LabelSelector)
|
|||
}
|
||||
|
||||
configMaps := []*v1.ConfigMap{}
|
||||
|
||||
err = cache.ListAllByNamespace(c.cmapInf.GetIndexer(), ns, cmSelector, func(obj interface{}) {
|
||||
configMaps = append(configMaps, obj.(*v1.ConfigMap))
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "list ConfigMaps for namespace %q", ns)
|
||||
}
|
||||
|
||||
return configMaps, nil
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ func makeRulesConfigMaps(p *monitoringv1.Prometheus, ruleFiles map[string]string
|
|||
}
|
||||
|
||||
buckets := []map[string]string{
|
||||
map[string]string{},
|
||||
{},
|
||||
}
|
||||
currBucketIndex := 0
|
||||
sortedNames := sortKeyesOfStringMap(ruleFiles)
|
||||
|
|
|
@ -84,13 +84,13 @@ func shouldSplitUpLargeSmallIntoTwo(t *testing.T) {
|
|||
|
||||
func TestChecksumConfigMaps(t *testing.T) {
|
||||
configMapsAsc := []v1.ConfigMap{
|
||||
v1.ConfigMap{
|
||||
{
|
||||
Data: map[string]string{
|
||||
"key1a": "value1a",
|
||||
"key1b": "value1b",
|
||||
},
|
||||
},
|
||||
v1.ConfigMap{
|
||||
{
|
||||
Data: map[string]string{
|
||||
"key2a": "value2a",
|
||||
"key2b": "value2b",
|
||||
|
@ -98,13 +98,13 @@ func TestChecksumConfigMaps(t *testing.T) {
|
|||
},
|
||||
}
|
||||
configMapsDesc := []v1.ConfigMap{
|
||||
v1.ConfigMap{
|
||||
{
|
||||
Data: map[string]string{
|
||||
"key2b": "value2b",
|
||||
"key2a": "value2a",
|
||||
},
|
||||
},
|
||||
v1.ConfigMap{
|
||||
{
|
||||
Data: map[string]string{
|
||||
"key1b": "value1b",
|
||||
"key1a": "value1a",
|
||||
|
|
|
@ -252,7 +252,7 @@ func makeConfigSecret(p *monitoringv1.Prometheus, config Config) *v1.Secret {
|
|||
},
|
||||
},
|
||||
Data: map[string][]byte{
|
||||
configFilename: []byte{},
|
||||
configFilename: {},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -350,7 +350,7 @@ func TestAlertmanagerZeroDowntimeRollingDeployment(t *testing.T) {
|
|||
Spec: v1.ServiceSpec{
|
||||
Type: v1.ServiceTypeClusterIP,
|
||||
Ports: []v1.ServicePort{
|
||||
v1.ServicePort{
|
||||
{
|
||||
Name: "web",
|
||||
Port: 5001,
|
||||
TargetPort: intstr.FromString("web"),
|
||||
|
|
|
@ -450,10 +450,10 @@ func TestPrometheusReloadRules(t *testing.T) {
|
|||
}
|
||||
|
||||
ruleFile.Spec.Groups = []monitoringv1.RuleGroup{
|
||||
monitoringv1.RuleGroup{
|
||||
{
|
||||
Name: "my-alerting-group",
|
||||
Rules: []monitoringv1.Rule{
|
||||
monitoringv1.Rule{
|
||||
{
|
||||
Alert: secondAlertName,
|
||||
Expr: "vector(1)",
|
||||
},
|
||||
|
@ -706,7 +706,7 @@ func TestPrometheusRulesExceedingConfigMapLimit(t *testing.T) {
|
|||
func generateHugePrometheusRule(ns, identifier string) monitoringv1.PrometheusRule {
|
||||
alertName := "my-alert"
|
||||
groups := []monitoringv1.RuleGroup{
|
||||
monitoringv1.RuleGroup{
|
||||
{
|
||||
Name: alertName,
|
||||
Rules: []monitoringv1.Rule{},
|
||||
},
|
||||
|
@ -1064,7 +1064,7 @@ func TestPrometheusDiscoverTargetPort(t *testing.T) {
|
|||
},
|
||||
},
|
||||
Endpoints: []monitoringv1.Endpoint{
|
||||
monitoringv1.Endpoint{
|
||||
{
|
||||
TargetPort: intstr.FromInt(9090),
|
||||
Interval: "30s",
|
||||
},
|
||||
|
|
|
@ -80,7 +80,7 @@ func (f *Framework) MakeAlertmanagerService(name, group string, serviceType v1.S
|
|||
Spec: v1.ServiceSpec{
|
||||
Type: serviceType,
|
||||
Ports: []v1.ServicePort{
|
||||
v1.ServicePort{
|
||||
{
|
||||
Name: "web",
|
||||
Port: 9093,
|
||||
TargetPort: intstr.FromString("web"),
|
||||
|
@ -336,9 +336,8 @@ type amAPIStatusData struct {
|
|||
func (s *amAPIStatusData) getAmountPeers() int {
|
||||
if s.MeshStatus != nil {
|
||||
return len(s.MeshStatus.Peers)
|
||||
} else {
|
||||
return len(s.ClusterStatus.Peers)
|
||||
}
|
||||
return len(s.ClusterStatus.Peers)
|
||||
}
|
||||
|
||||
type clusterStatus struct {
|
||||
|
|
|
@ -53,11 +53,7 @@ func DeleteClusterRole(kubeClient kubernetes.Interface, relativePath string) err
|
|||
return err
|
||||
}
|
||||
|
||||
if err := kubeClient.RbacV1().ClusterRoles().Delete(clusterRole.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return kubeClient.RbacV1().ClusterRoles().Delete(clusterRole.Name, &metav1.DeleteOptions{})
|
||||
}
|
||||
|
||||
func parseClusterRoleYaml(relativePath string) (*rbacv1.ClusterRole, error) {
|
||||
|
|
|
@ -55,11 +55,7 @@ func DeleteClusterRoleBinding(kubeClient kubernetes.Interface, relativePath stri
|
|||
return err
|
||||
}
|
||||
|
||||
if err := kubeClient.RbacV1().ClusterRoleBindings().Delete(clusterRoleBinding.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return kubeClient.RbacV1().ClusterRoleBindings().Delete(clusterRoleBinding.Name, &metav1.DeleteOptions{})
|
||||
}
|
||||
|
||||
func parseClusterRoleBindingYaml(relativePath string) (*rbacv1.ClusterRoleBinding, error) {
|
||||
|
|
|
@ -45,7 +45,7 @@ type Framework struct {
|
|||
DefaultTimeout time.Duration
|
||||
}
|
||||
|
||||
// Setup setups a test framework and returns it.
|
||||
// New setups a test framework and returns it.
|
||||
func New(ns, kubeconfig, opImage string) (*Framework, error) {
|
||||
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
|
||||
if err != nil {
|
||||
|
@ -215,9 +215,6 @@ func (f *Framework) Teardown() error {
|
|||
if err := f.KubeClient.Extensions().Deployments(f.Namespace.Name).Delete("prometheus-operator", nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := DeleteNamespace(f.KubeClient, f.Namespace.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return DeleteNamespace(f.KubeClient, f.Namespace.Name)
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ func WaitForHTTPSuccessStatusCode(timeout time.Duration, url string) error {
|
|||
})
|
||||
|
||||
return errors.Wrap(err, fmt.Sprintf(
|
||||
"waiting for %v to return a successfull status code timed out. Last response from server was: %v",
|
||||
"waiting for %v to return a successful status code timed out. Last response from server was: %v",
|
||||
url,
|
||||
resp,
|
||||
))
|
||||
|
|
|
@ -36,11 +36,11 @@ func MakeBasicIngress(serviceName string, servicePort int) *v1beta1.Ingress {
|
|||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Rules: []v1beta1.IngressRule{
|
||||
v1beta1.IngressRule{
|
||||
{
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
v1beta1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: serviceName,
|
||||
ServicePort: intstr.FromInt(servicePort),
|
||||
|
|
|
@ -43,10 +43,7 @@ func (ctx *TestCtx) CreateNamespace(t *testing.T, kubeClient kubernetes.Interfac
|
|||
}
|
||||
|
||||
namespaceFinalizerFn := func() error {
|
||||
if err := DeleteNamespace(kubeClient, name); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return DeleteNamespace(kubeClient, name)
|
||||
}
|
||||
|
||||
ctx.AddFinalizerFn(namespaceFinalizerFn)
|
||||
|
|
|
@ -64,7 +64,7 @@ func (f *Framework) MakeBasicPrometheus(ns, name, group string, replicas int32)
|
|||
func (f *Framework) AddAlertingToPrometheus(p *monitoringv1.Prometheus, ns, name string) {
|
||||
p.Spec.Alerting = &monitoringv1.AlertingSpec{
|
||||
Alertmanagers: []monitoringv1.AlertmanagerEndpoints{
|
||||
monitoringv1.AlertmanagerEndpoints{
|
||||
{
|
||||
Namespace: ns,
|
||||
Name: fmt.Sprintf("alertmanager-%s", name),
|
||||
Port: intstr.FromString("web"),
|
||||
|
@ -88,7 +88,7 @@ func (f *Framework) MakeBasicServiceMonitor(name string) *monitoringv1.ServiceMo
|
|||
},
|
||||
},
|
||||
Endpoints: []monitoringv1.Endpoint{
|
||||
monitoringv1.Endpoint{
|
||||
{
|
||||
Port: "web",
|
||||
Interval: "30s",
|
||||
},
|
||||
|
@ -112,7 +112,7 @@ func (f *Framework) MakeBasicServiceMonitorV1alpha1(name string) *v1alpha1.Servi
|
|||
},
|
||||
},
|
||||
Endpoints: []v1alpha1.Endpoint{
|
||||
v1alpha1.Endpoint{
|
||||
{
|
||||
Port: "web",
|
||||
Interval: "30s",
|
||||
},
|
||||
|
@ -132,7 +132,7 @@ func (f *Framework) MakePrometheusService(name, group string, serviceType v1.Ser
|
|||
Spec: v1.ServiceSpec{
|
||||
Type: serviceType,
|
||||
Ports: []v1.ServicePort{
|
||||
v1.ServicePort{
|
||||
{
|
||||
Name: "web",
|
||||
Port: 9090,
|
||||
TargetPort: intstr.FromString("web"),
|
||||
|
@ -153,7 +153,7 @@ func (f *Framework) MakeThanosQuerierService(name string) *v1.Service {
|
|||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
v1.ServicePort{
|
||||
{
|
||||
Name: "http-query",
|
||||
Port: 10902,
|
||||
TargetPort: intstr.FromString("http"),
|
||||
|
@ -174,7 +174,7 @@ func (f *Framework) MakeThanosService(name string) *v1.Service {
|
|||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
v1.ServicePort{
|
||||
{
|
||||
Name: "cluster",
|
||||
Port: 10900,
|
||||
TargetPort: intstr.FromString("cluster"),
|
||||
|
|
|
@ -50,10 +50,10 @@ func (f *Framework) CreateRule(ns string, ar monitoringv1.PrometheusRule) error
|
|||
|
||||
func (f *Framework) MakeAndCreateFiringRule(ns, name, alertName string) (monitoringv1.PrometheusRule, error) {
|
||||
groups := []monitoringv1.RuleGroup{
|
||||
monitoringv1.RuleGroup{
|
||||
{
|
||||
Name: alertName,
|
||||
Rules: []monitoringv1.Rule{
|
||||
monitoringv1.Rule{
|
||||
{
|
||||
Alert: alertName,
|
||||
Expr: "vector(1)",
|
||||
},
|
||||
|
|
|
@ -38,11 +38,7 @@ func DeleteRoleBinding(kubeClient kubernetes.Interface, ns string, relativePath
|
|||
return err
|
||||
}
|
||||
|
||||
if err := kubeClient.RbacV1().RoleBindings(ns).Delete(roleBinding.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return kubeClient.RbacV1().RoleBindings(ns).Delete(roleBinding.Name, &metav1.DeleteOptions{})
|
||||
}
|
||||
|
||||
func parseRoleBindingYaml(relativePath string) (*rbacv1.RoleBinding, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue