go version removal v1
Change-Id: I5b2e90549c8ca4f6b1c91b0879470a2cee59bf59
This commit is contained in:
parent
f6ca81190c
commit
add918bd3c
@ -1,33 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +kubebuilder:object:generate=true
|
|
||||||
// +groupName=monitoring.coreos.com
|
|
||||||
package v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/scheme"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// GroupVersion is group version used to register these objects
|
|
||||||
GroupVersion = schema.GroupVersion{Group: "monitoring.coreos.com", Version: "v1"}
|
|
||||||
|
|
||||||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
|
|
||||||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
|
||||||
|
|
||||||
// AddToScheme adds the types in this group-version to the given scheme.
|
|
||||||
AddToScheme = SchemeBuilder.AddToScheme
|
|
||||||
)
|
|
@ -1,207 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
Version = "v1"
|
|
||||||
|
|
||||||
PodMonitorsKind = "PodMonitor"
|
|
||||||
PodMonitorName = "podmonitors"
|
|
||||||
PodMonitorKindKey = "podmonitor"
|
|
||||||
|
|
||||||
PrometheusRuleKind = "PrometheusRule"
|
|
||||||
PrometheusRuleName = "prometheusrules"
|
|
||||||
PrometheusRuleKindKey = "prometheusrule"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PodMonitor defines monitoring for a set of pods.
|
|
||||||
// +genclient
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
// +kubebuilder:object:root=true
|
|
||||||
type PodMonitor struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
|
||||||
// Specification of desired Pod selection for target discovery by Prometheus.
|
|
||||||
Spec PodMonitorSpec `json:"spec"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodMonitorSpec contains specification parameters for a PodMonitor.
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
type PodMonitorSpec struct {
|
|
||||||
// The label to use to retrieve the job name from.
|
|
||||||
JobLabel string `json:"jobLabel,omitempty"`
|
|
||||||
// PodTargetLabels transfers labels on the Kubernetes Pod onto the target.
|
|
||||||
PodTargetLabels []string `json:"podTargetLabels,omitempty"`
|
|
||||||
// A list of endpoints allowed as part of this PodMonitor.
|
|
||||||
PodMetricsEndpoints []PodMetricsEndpoint `json:"podMetricsEndpoints"`
|
|
||||||
// Selector to select Pod objects.
|
|
||||||
Selector metav1.LabelSelector `json:"selector"`
|
|
||||||
// Selector to select which namespaces the Endpoints objects are discovered from.
|
|
||||||
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty"`
|
|
||||||
// SampleLimit defines per-scrape limit on number of scraped samples that will be accepted.
|
|
||||||
SampleLimit uint64 `json:"sampleLimit,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodMonitorList is a list of PodMonitors.
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
// +kubebuilder:object:root=true
|
|
||||||
type PodMonitorList struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
// Standard list metadata
|
|
||||||
// More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
|
||||||
metav1.ListMeta `json:"metadata,omitempty"`
|
|
||||||
// List of PodMonitors
|
|
||||||
Items []*PodMonitor `json:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// RelabelConfig allows dynamic rewriting of the label set, being applied to samples before ingestion.
|
|
||||||
// It defines `<metric_relabel_configs>`-section of Prometheus configuration.
|
|
||||||
// More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
type RelabelConfig struct {
|
|
||||||
//The source labels select values from existing labels. Their content is concatenated
|
|
||||||
//using the configured separator and matched against the configured regular expression
|
|
||||||
//for the replace, keep, and drop actions.
|
|
||||||
SourceLabels []string `json:"sourceLabels,omitempty"`
|
|
||||||
//Separator placed between concatenated source label values. default is ';'.
|
|
||||||
Separator string `json:"separator,omitempty"`
|
|
||||||
//Label to which the resulting value is written in a replace action.
|
|
||||||
//It is mandatory for replace actions. Regex capture groups are available.
|
|
||||||
TargetLabel string `json:"targetLabel,omitempty"`
|
|
||||||
//Regular expression against which the extracted value is matched. Default is '(.*)'
|
|
||||||
Regex string `json:"regex,omitempty"`
|
|
||||||
// Modulus to take of the hash of the source label values.
|
|
||||||
Modulus uint64 `json:"modulus,omitempty"`
|
|
||||||
//Replacement value against which a regex replace is performed if the
|
|
||||||
//regular expression matches. Regex capture groups are available. Default is '$1'
|
|
||||||
Replacement string `json:"replacement,omitempty"`
|
|
||||||
// Action to perform based on regex matching. Default is 'replace'
|
|
||||||
Action string `json:"action,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodMetricsEndpoint defines a scrapeable endpoint of a Kubernetes Pod serving Prometheus metrics.
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
type PodMetricsEndpoint struct {
|
|
||||||
// Name of the pod port this endpoint refers to. Mutually exclusive with targetPort.
|
|
||||||
Port string `json:"port,omitempty"`
|
|
||||||
// Deprecated: Use 'port' instead.
|
|
||||||
TargetPort *intstr.IntOrString `json:"targetPort,omitempty"`
|
|
||||||
// HTTP path to scrape for metrics.
|
|
||||||
Path string `json:"path,omitempty"`
|
|
||||||
// HTTP scheme to use for scraping.
|
|
||||||
Scheme string `json:"scheme,omitempty"`
|
|
||||||
// Optional HTTP URL parameters
|
|
||||||
Params map[string][]string `json:"params,omitempty"`
|
|
||||||
// Interval at which metrics should be scraped
|
|
||||||
Interval string `json:"interval,omitempty"`
|
|
||||||
// Timeout after which the scrape is ended
|
|
||||||
ScrapeTimeout string `json:"scrapeTimeout,omitempty"`
|
|
||||||
// HonorLabels chooses the metric's labels on collisions with target labels.
|
|
||||||
HonorLabels bool `json:"honorLabels,omitempty"`
|
|
||||||
// HonorTimestamps controls whether Prometheus respects the timestamps present in scraped data.
|
|
||||||
HonorTimestamps *bool `json:"honorTimestamps,omitempty"`
|
|
||||||
// MetricRelabelConfigs to apply to samples before ingestion.
|
|
||||||
MetricRelabelConfigs []*RelabelConfig `json:"metricRelabelings,omitempty"`
|
|
||||||
// RelabelConfigs to apply to samples before ingestion.
|
|
||||||
// More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
|
|
||||||
RelabelConfigs []*RelabelConfig `json:"relabelings,omitempty"`
|
|
||||||
// ProxyURL eg http://proxyserver:2195 Directs scrapes to proxy through this endpoint.
|
|
||||||
ProxyURL *string `json:"proxyUrl,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NamespaceSelector is a selector for selecting either all namespaces or a
|
|
||||||
// list of namespaces.
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
type NamespaceSelector struct {
|
|
||||||
// Boolean describing whether all namespaces are selected in contrast to a
|
|
||||||
// list restricting them.
|
|
||||||
Any bool `json:"any,omitempty"`
|
|
||||||
// List of namespace names.
|
|
||||||
MatchNames []string `json:"matchNames,omitempty"`
|
|
||||||
|
|
||||||
// TODO(fabxc): this should embed metav1.LabelSelector eventually.
|
|
||||||
// Currently the selector is only used for namespaces which require more complex
|
|
||||||
// implementation to support label selections.
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrometheusRuleList is a list of PrometheusRules.
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
// +kubebuilder:object:root=true
|
|
||||||
type PrometheusRuleList struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
// Standard list metadata
|
|
||||||
// More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
|
||||||
metav1.ListMeta `json:"metadata,omitempty"`
|
|
||||||
// List of Rules
|
|
||||||
Items []*PrometheusRule `json:"items"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrometheusRule defines alerting rules for a Prometheus instance
|
|
||||||
// +genclient
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
// +kubebuilder:object:root=true
|
|
||||||
type PrometheusRule struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
|
||||||
// Specification of desired alerting rule definitions for Prometheus.
|
|
||||||
Spec PrometheusRuleSpec `json:"spec"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrometheusRuleSpec contains specification parameters for a Rule.
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
type PrometheusRuleSpec struct {
|
|
||||||
// Content of Prometheus rule file
|
|
||||||
Groups []RuleGroup `json:"groups,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// RuleGroup and Rule are copied instead of vendored because the
|
|
||||||
// upstream Prometheus struct definitions don't have json struct tags.
|
|
||||||
|
|
||||||
// RuleGroup is a list of sequentially evaluated recording and alerting rules.
|
|
||||||
// Note: PartialResponseStrategy is only used by ThanosRuler and will
|
|
||||||
// be ignored by Prometheus instances. Valid values for this field are 'warn'
|
|
||||||
// or 'abort'. More info: https://github.com/thanos-io/thanos/blob/master/docs/components/rule.md#partial-response
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
type RuleGroup struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Interval string `json:"interval,omitempty"`
|
|
||||||
Rules []Rule `json:"rules"`
|
|
||||||
PartialResponseStrategy string `json:"partial_response_strategy,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rule describes an alerting or recording rule.
|
|
||||||
// +k8s:openapi-gen=true
|
|
||||||
type Rule struct {
|
|
||||||
Record string `json:"record,omitempty"`
|
|
||||||
Alert string `json:"alert,omitempty"`
|
|
||||||
Expr intstr.IntOrString `json:"expr"`
|
|
||||||
For string `json:"for,omitempty"`
|
|
||||||
Labels map[string]string `json:"labels,omitempty"`
|
|
||||||
Annotations map[string]string `json:"annotations,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=podmonitors,verbs=get;list;watch;create;update;patch;delete
|
|
||||||
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=podmonitors/status,verbs=get;update;patch
|
|
||||||
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=prometheusrules,verbs=get;list;watch;create;update;patch;delete
|
|
||||||
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=prometheusrules/status,verbs=get;update;patch
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
SchemeBuilder.Register(&PodMonitor{}, &PodMonitorList{}, &PrometheusRule{}, &PrometheusRuleList{})
|
|
||||||
}
|
|
@ -1,358 +0,0 @@
|
|||||||
// +build !ignore_autogenerated
|
|
||||||
|
|
||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Code generated by controller-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *NamespaceSelector) DeepCopyInto(out *NamespaceSelector) {
|
|
||||||
*out = *in
|
|
||||||
if in.MatchNames != nil {
|
|
||||||
in, out := &in.MatchNames, &out.MatchNames
|
|
||||||
*out = make([]string, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamespaceSelector.
|
|
||||||
func (in *NamespaceSelector) DeepCopy() *NamespaceSelector {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(NamespaceSelector)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *PodMetricsEndpoint) DeepCopyInto(out *PodMetricsEndpoint) {
|
|
||||||
*out = *in
|
|
||||||
if in.TargetPort != nil {
|
|
||||||
in, out := &in.TargetPort, &out.TargetPort
|
|
||||||
*out = new(intstr.IntOrString)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
if in.Params != nil {
|
|
||||||
in, out := &in.Params, &out.Params
|
|
||||||
*out = make(map[string][]string, len(*in))
|
|
||||||
for key, val := range *in {
|
|
||||||
var outVal []string
|
|
||||||
if val == nil {
|
|
||||||
(*out)[key] = nil
|
|
||||||
} else {
|
|
||||||
in, out := &val, &outVal
|
|
||||||
*out = make([]string, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
}
|
|
||||||
(*out)[key] = outVal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if in.HonorTimestamps != nil {
|
|
||||||
in, out := &in.HonorTimestamps, &out.HonorTimestamps
|
|
||||||
*out = new(bool)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
if in.MetricRelabelConfigs != nil {
|
|
||||||
in, out := &in.MetricRelabelConfigs, &out.MetricRelabelConfigs
|
|
||||||
*out = make([]*RelabelConfig, len(*in))
|
|
||||||
for i := range *in {
|
|
||||||
if (*in)[i] != nil {
|
|
||||||
in, out := &(*in)[i], &(*out)[i]
|
|
||||||
*out = new(RelabelConfig)
|
|
||||||
(*in).DeepCopyInto(*out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if in.RelabelConfigs != nil {
|
|
||||||
in, out := &in.RelabelConfigs, &out.RelabelConfigs
|
|
||||||
*out = make([]*RelabelConfig, len(*in))
|
|
||||||
for i := range *in {
|
|
||||||
if (*in)[i] != nil {
|
|
||||||
in, out := &(*in)[i], &(*out)[i]
|
|
||||||
*out = new(RelabelConfig)
|
|
||||||
(*in).DeepCopyInto(*out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if in.ProxyURL != nil {
|
|
||||||
in, out := &in.ProxyURL, &out.ProxyURL
|
|
||||||
*out = new(string)
|
|
||||||
**out = **in
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetricsEndpoint.
|
|
||||||
func (in *PodMetricsEndpoint) DeepCopy() *PodMetricsEndpoint {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(PodMetricsEndpoint)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *PodMonitor) DeepCopyInto(out *PodMonitor) {
|
|
||||||
*out = *in
|
|
||||||
out.TypeMeta = in.TypeMeta
|
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
|
||||||
in.Spec.DeepCopyInto(&out.Spec)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMonitor.
|
|
||||||
func (in *PodMonitor) DeepCopy() *PodMonitor {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(PodMonitor)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *PodMonitor) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *PodMonitorList) DeepCopyInto(out *PodMonitorList) {
|
|
||||||
*out = *in
|
|
||||||
out.TypeMeta = in.TypeMeta
|
|
||||||
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
|
||||||
if in.Items != nil {
|
|
||||||
in, out := &in.Items, &out.Items
|
|
||||||
*out = make([]*PodMonitor, len(*in))
|
|
||||||
for i := range *in {
|
|
||||||
if (*in)[i] != nil {
|
|
||||||
in, out := &(*in)[i], &(*out)[i]
|
|
||||||
*out = new(PodMonitor)
|
|
||||||
(*in).DeepCopyInto(*out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMonitorList.
|
|
||||||
func (in *PodMonitorList) DeepCopy() *PodMonitorList {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(PodMonitorList)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *PodMonitorList) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *PodMonitorSpec) DeepCopyInto(out *PodMonitorSpec) {
|
|
||||||
*out = *in
|
|
||||||
if in.PodTargetLabels != nil {
|
|
||||||
in, out := &in.PodTargetLabels, &out.PodTargetLabels
|
|
||||||
*out = make([]string, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
}
|
|
||||||
if in.PodMetricsEndpoints != nil {
|
|
||||||
in, out := &in.PodMetricsEndpoints, &out.PodMetricsEndpoints
|
|
||||||
*out = make([]PodMetricsEndpoint, len(*in))
|
|
||||||
for i := range *in {
|
|
||||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
in.Selector.DeepCopyInto(&out.Selector)
|
|
||||||
in.NamespaceSelector.DeepCopyInto(&out.NamespaceSelector)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMonitorSpec.
|
|
||||||
func (in *PodMonitorSpec) DeepCopy() *PodMonitorSpec {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(PodMonitorSpec)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *PrometheusRule) DeepCopyInto(out *PrometheusRule) {
|
|
||||||
*out = *in
|
|
||||||
out.TypeMeta = in.TypeMeta
|
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
|
||||||
in.Spec.DeepCopyInto(&out.Spec)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusRule.
|
|
||||||
func (in *PrometheusRule) DeepCopy() *PrometheusRule {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(PrometheusRule)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *PrometheusRule) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *PrometheusRuleList) DeepCopyInto(out *PrometheusRuleList) {
|
|
||||||
*out = *in
|
|
||||||
out.TypeMeta = in.TypeMeta
|
|
||||||
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
|
||||||
if in.Items != nil {
|
|
||||||
in, out := &in.Items, &out.Items
|
|
||||||
*out = make([]*PrometheusRule, len(*in))
|
|
||||||
for i := range *in {
|
|
||||||
if (*in)[i] != nil {
|
|
||||||
in, out := &(*in)[i], &(*out)[i]
|
|
||||||
*out = new(PrometheusRule)
|
|
||||||
(*in).DeepCopyInto(*out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusRuleList.
|
|
||||||
func (in *PrometheusRuleList) DeepCopy() *PrometheusRuleList {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(PrometheusRuleList)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *PrometheusRuleList) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *PrometheusRuleSpec) DeepCopyInto(out *PrometheusRuleSpec) {
|
|
||||||
*out = *in
|
|
||||||
if in.Groups != nil {
|
|
||||||
in, out := &in.Groups, &out.Groups
|
|
||||||
*out = make([]RuleGroup, len(*in))
|
|
||||||
for i := range *in {
|
|
||||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusRuleSpec.
|
|
||||||
func (in *PrometheusRuleSpec) DeepCopy() *PrometheusRuleSpec {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(PrometheusRuleSpec)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *RelabelConfig) DeepCopyInto(out *RelabelConfig) {
|
|
||||||
*out = *in
|
|
||||||
if in.SourceLabels != nil {
|
|
||||||
in, out := &in.SourceLabels, &out.SourceLabels
|
|
||||||
*out = make([]string, len(*in))
|
|
||||||
copy(*out, *in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RelabelConfig.
|
|
||||||
func (in *RelabelConfig) DeepCopy() *RelabelConfig {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(RelabelConfig)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *Rule) DeepCopyInto(out *Rule) {
|
|
||||||
*out = *in
|
|
||||||
out.Expr = in.Expr
|
|
||||||
if in.Labels != nil {
|
|
||||||
in, out := &in.Labels, &out.Labels
|
|
||||||
*out = make(map[string]string, len(*in))
|
|
||||||
for key, val := range *in {
|
|
||||||
(*out)[key] = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if in.Annotations != nil {
|
|
||||||
in, out := &in.Annotations, &out.Annotations
|
|
||||||
*out = make(map[string]string, len(*in))
|
|
||||||
for key, val := range *in {
|
|
||||||
(*out)[key] = val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rule.
|
|
||||||
func (in *Rule) DeepCopy() *Rule {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(Rule)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *RuleGroup) DeepCopyInto(out *RuleGroup) {
|
|
||||||
*out = *in
|
|
||||||
if in.Rules != nil {
|
|
||||||
in, out := &in.Rules, &out.Rules
|
|
||||||
*out = make([]Rule, len(*in))
|
|
||||||
for i := range *in {
|
|
||||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuleGroup.
|
|
||||||
func (in *RuleGroup) DeepCopy() *RuleGroup {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(RuleGroup)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ConfigMapBuilder defines the interface to build a ConfigMap
|
|
||||||
type ConfigMapBuilder struct {
|
|
||||||
obj *corev1.ConfigMap
|
|
||||||
owner metav1.Object
|
|
||||||
scheme *runtime.Scheme
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigMap returns a new service builder
|
|
||||||
func ConfigMap(existing *corev1.ConfigMap, owner metav1.Object, scheme *runtime.Scheme) *ConfigMapBuilder {
|
|
||||||
existing.Data = map[string]string{}
|
|
||||||
|
|
||||||
return &ConfigMapBuilder{
|
|
||||||
obj: existing,
|
|
||||||
owner: owner,
|
|
||||||
scheme: scheme,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Data sets a key inside this ConfigMap
|
|
||||||
func (cm *ConfigMapBuilder) Data(key, value string) *ConfigMapBuilder {
|
|
||||||
cm.obj.Data[key] = value
|
|
||||||
return cm
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns a complete ConfigMap object
|
|
||||||
func (cm *ConfigMapBuilder) Build() error {
|
|
||||||
return controllerutil.SetControllerReference(cm.owner, cm.obj, cm.scheme)
|
|
||||||
}
|
|
@ -1,203 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/alecthomas/units"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
v1 "k8s.io/api/core/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ContainerBuilder provides an interface to build containers
|
|
||||||
type ContainerBuilder struct {
|
|
||||||
obj *corev1.Container
|
|
||||||
securityContext *SecurityContextBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
// Container returns a new container builder
|
|
||||||
func Container(name string, image string) *ContainerBuilder {
|
|
||||||
container := &corev1.Container{
|
|
||||||
Name: name,
|
|
||||||
Image: image,
|
|
||||||
ImagePullPolicy: corev1.PullAlways,
|
|
||||||
TerminationMessagePath: "/dev/termination-log",
|
|
||||||
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ContainerBuilder{
|
|
||||||
obj: container,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Args sets the arguments for that container
|
|
||||||
func (c *ContainerBuilder) Args(args ...string) *ContainerBuilder {
|
|
||||||
c.obj.Args = args
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// SecurityContext sets the SecurityContext for that container
|
|
||||||
func (c *ContainerBuilder) SecurityContext(SecurityContext *SecurityContextBuilder) *ContainerBuilder {
|
|
||||||
c.securityContext = SecurityContext
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// Port appends a port to the container
|
|
||||||
func (c *ContainerBuilder) Port(name string, port int32) *ContainerBuilder {
|
|
||||||
c.obj.Ports = append(c.obj.Ports, v1.ContainerPort{
|
|
||||||
Name: name,
|
|
||||||
ContainerPort: port,
|
|
||||||
Protocol: corev1.ProtocolTCP,
|
|
||||||
})
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// Volume appends a volume to the container
|
|
||||||
func (c *ContainerBuilder) Volume(name string, path string) *ContainerBuilder {
|
|
||||||
c.obj.VolumeMounts = append(c.obj.VolumeMounts, v1.VolumeMount{
|
|
||||||
Name: name,
|
|
||||||
MountPath: path,
|
|
||||||
})
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resources defines the resource configuration for the container
|
|
||||||
func (c *ContainerBuilder) Resources(cpu int64, memory int64, storage int64, factor float64) *ContainerBuilder {
|
|
||||||
memory = memory * int64(units.Mebibyte)
|
|
||||||
storage = storage * int64(units.Megabyte)
|
|
||||||
|
|
||||||
cpuLimit := int64(float64(cpu) * factor)
|
|
||||||
memoryLimit := int64(float64(memory) * factor)
|
|
||||||
storageLimit := int64(float64(storage) * factor)
|
|
||||||
|
|
||||||
c.obj.Resources = v1.ResourceRequirements{
|
|
||||||
Limits: v1.ResourceList{
|
|
||||||
v1.ResourceCPU: *resource.NewMilliQuantity(cpuLimit, resource.DecimalSI),
|
|
||||||
v1.ResourceMemory: *resource.NewQuantity(memoryLimit, resource.BinarySI),
|
|
||||||
v1.ResourceEphemeralStorage: *resource.NewQuantity(storageLimit, resource.DecimalSI),
|
|
||||||
},
|
|
||||||
Requests: v1.ResourceList{
|
|
||||||
v1.ResourceCPU: *resource.NewMilliQuantity(cpu, resource.DecimalSI),
|
|
||||||
v1.ResourceMemory: *resource.NewQuantity(memory, resource.BinarySI),
|
|
||||||
v1.ResourceEphemeralStorage: *resource.NewQuantity(storage, resource.DecimalSI),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTPProbe creates both a readiness and liveness probe with provided intervals
|
|
||||||
func (c *ContainerBuilder) HTTPProbe(port string, path string, readyInterval int32, liveInterval int32) *ContainerBuilder {
|
|
||||||
handler := v1.Handler{
|
|
||||||
HTTPGet: &v1.HTTPGetAction{
|
|
||||||
Path: path,
|
|
||||||
Port: intstr.FromString(port),
|
|
||||||
Scheme: v1.URISchemeHTTP,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Probe(handler, readyInterval, liveInterval)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PortProbe creates both a readiness and liveness probe with provided intervals
|
|
||||||
func (c *ContainerBuilder) PortProbe(port string, readyInterval int32, liveInterval int32) *ContainerBuilder {
|
|
||||||
handler := v1.Handler{
|
|
||||||
TCPSocket: &v1.TCPSocketAction{
|
|
||||||
Port: intstr.FromString(port),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Probe(handler, readyInterval, liveInterval)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Probe creates both a readiness and liveness probe based on a handler provided
|
|
||||||
func (c *ContainerBuilder) Probe(handler v1.Handler, readyInterval int32, liveInterval int32) *ContainerBuilder {
|
|
||||||
c.obj.ReadinessProbe = &v1.Probe{
|
|
||||||
Handler: handler,
|
|
||||||
InitialDelaySeconds: 0,
|
|
||||||
PeriodSeconds: readyInterval,
|
|
||||||
TimeoutSeconds: 1,
|
|
||||||
SuccessThreshold: 1,
|
|
||||||
FailureThreshold: 3,
|
|
||||||
}
|
|
||||||
c.obj.LivenessProbe = &v1.Probe{
|
|
||||||
Handler: handler,
|
|
||||||
InitialDelaySeconds: 0,
|
|
||||||
PeriodSeconds: liveInterval,
|
|
||||||
TimeoutSeconds: 1,
|
|
||||||
SuccessThreshold: 1,
|
|
||||||
FailureThreshold: 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// EnvVarFromString register one environment variable set from the string pair.
|
|
||||||
func (c *ContainerBuilder) EnvVarFromString(name string, value string) *ContainerBuilder {
|
|
||||||
c.obj.Env = append(c.obj.Env, corev1.EnvVar{
|
|
||||||
Name: name,
|
|
||||||
Value: value,
|
|
||||||
})
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// EnvVarFromConfigMap register one environment variable set from the configMap.
|
|
||||||
func (c *ContainerBuilder) EnvVarFromConfigMap(name string, cfmName string, cfmKey string) *ContainerBuilder {
|
|
||||||
c.obj.Env = append(c.obj.Env, corev1.EnvVar{
|
|
||||||
Name: name,
|
|
||||||
ValueFrom: &corev1.EnvVarSource{
|
|
||||||
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
|
|
||||||
LocalObjectReference: corev1.LocalObjectReference{
|
|
||||||
Name: cfmName,
|
|
||||||
},
|
|
||||||
Key: cfmKey,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// EnvVarFromSecret register one environment variable set from the secret.
|
|
||||||
func (c *ContainerBuilder) EnvVarFromSecret(name string, scName string, scKey string) *ContainerBuilder {
|
|
||||||
c.obj.Env = append(c.obj.Env, corev1.EnvVar{
|
|
||||||
Name: name,
|
|
||||||
ValueFrom: &corev1.EnvVarSource{
|
|
||||||
SecretKeyRef: &corev1.SecretKeySelector{
|
|
||||||
LocalObjectReference: corev1.LocalObjectReference{
|
|
||||||
Name: scName,
|
|
||||||
},
|
|
||||||
Key: scKey,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns the object after making certain assertions
|
|
||||||
func (c *ContainerBuilder) Build() (corev1.Container, error) {
|
|
||||||
if c.securityContext == nil {
|
|
||||||
return corev1.Container{}, errors.New("missing security context")
|
|
||||||
}
|
|
||||||
securityContext, err := c.securityContext.Build()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return corev1.Container{}, err
|
|
||||||
}
|
|
||||||
c.obj.SecurityContext = &securityContext
|
|
||||||
return *c.obj, nil
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeploymentBuilder defines the interface to build a deployment
|
|
||||||
type DeploymentBuilder struct {
|
|
||||||
obj *appsv1.Deployment
|
|
||||||
podTemplateSpec *PodTemplateSpecBuilder
|
|
||||||
owner metav1.Object
|
|
||||||
scheme *runtime.Scheme
|
|
||||||
labels map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deployment returns a new deployment builder
|
|
||||||
func Deployment(existing *appsv1.Deployment, owner metav1.Object, scheme *runtime.Scheme) *DeploymentBuilder {
|
|
||||||
return &DeploymentBuilder{
|
|
||||||
obj: existing,
|
|
||||||
labels: map[string]string{},
|
|
||||||
owner: owner,
|
|
||||||
scheme: scheme,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Labels specifies labels for the deployment
|
|
||||||
func (d *DeploymentBuilder) Labels(labels map[string]string) *DeploymentBuilder {
|
|
||||||
d.labels = labels
|
|
||||||
d.obj.ObjectMeta.Labels = d.labels
|
|
||||||
d.obj.Spec.Selector = &metav1.LabelSelector{MatchLabels: d.labels}
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replicas defines the number of replicas
|
|
||||||
func (d *DeploymentBuilder) Replicas(replicas int32) *DeploymentBuilder {
|
|
||||||
d.obj.Spec.Replicas = pointer.Int32Ptr(replicas)
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodTemplateSpec defines a builder for the pod template spec
|
|
||||||
func (d *DeploymentBuilder) PodTemplateSpec(podTemplateSpec *PodTemplateSpecBuilder) *DeploymentBuilder {
|
|
||||||
d.podTemplateSpec = podTemplateSpec
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build creates a final deployment objet
|
|
||||||
func (d *DeploymentBuilder) Build() error {
|
|
||||||
podTemplateSpec, err := d.podTemplateSpec.Labels(d.labels).Build()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
d.obj.Spec.Template = podTemplateSpec
|
|
||||||
return controllerutil.SetControllerReference(d.owner, d.obj, d.scheme)
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
monitoringv1 "opendev.org/vexxhost/openstack-operator/api/monitoring/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PodMetricsEndpointBuilder provides an interface to build podmonitors
|
|
||||||
type PodMetricsEndpointBuilder struct {
|
|
||||||
obj *monitoringv1.PodMetricsEndpoint
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodMonitor returns a new podmonitor builder
|
|
||||||
func PodMetricsEndpoint() *PodMetricsEndpointBuilder {
|
|
||||||
podMetricsEndpoint := &monitoringv1.PodMetricsEndpoint{}
|
|
||||||
return &PodMetricsEndpointBuilder{
|
|
||||||
obj: podMetricsEndpoint,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) Port(port string) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.Port = port
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) Path(path string) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.Path = path
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) Scheme(scheme string) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.Scheme = scheme
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) Params(params map[string][]string) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.Params = params
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) Interval(interval string) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.Interval = interval
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) ScrapeTimeout(scrapeTimeout string) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.ScrapeTimeout = scrapeTimeout
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) HonorLabels(honorLabels bool) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.HonorLabels = honorLabels
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) HonorTimestamps(honorTimestamps bool) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.HonorTimestamps = &honorTimestamps
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pme *PodMetricsEndpointBuilder) ProxyURL(proxyURL string) *PodMetricsEndpointBuilder {
|
|
||||||
pme.obj.ProxyURL = &proxyURL
|
|
||||||
return pme
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns the object after making certain assertions
|
|
||||||
func (pme *PodMetricsEndpointBuilder) Build() (monitoringv1.PodMetricsEndpoint, error) {
|
|
||||||
return *pme.obj, nil
|
|
||||||
}
|
|
@ -1,111 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
monitoringv1 "opendev.org/vexxhost/openstack-operator/api/monitoring/v1"
|
|
||||||
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PodMonitorBuilder provides an interface to build podmonitors
|
|
||||||
type PodMonitorBuilder struct {
|
|
||||||
obj *monitoringv1.PodMonitor
|
|
||||||
podMetricsEndpoints []*PodMetricsEndpointBuilder
|
|
||||||
owner metav1.Object
|
|
||||||
scheme *runtime.Scheme
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodMonitor returns a new podmonitor builder
|
|
||||||
func PodMonitor(existing *monitoringv1.PodMonitor, owner metav1.Object, scheme *runtime.Scheme) *PodMonitorBuilder {
|
|
||||||
return &PodMonitorBuilder{
|
|
||||||
obj: existing,
|
|
||||||
owner: owner,
|
|
||||||
scheme: scheme,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pm *PodMonitorBuilder) Labels(labels map[string]string) *PodMonitorBuilder {
|
|
||||||
pm.obj.Labels = labels
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pm *PodMonitorBuilder) Selector(matchLabels map[string]string) *PodMonitorBuilder {
|
|
||||||
pm.obj.Spec.Selector = metav1.LabelSelector{
|
|
||||||
MatchLabels: matchLabels,
|
|
||||||
}
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pm *PodMonitorBuilder) PodTargetLabels(podTargetLabels []string) *PodMonitorBuilder {
|
|
||||||
pm.obj.Spec.PodTargetLabels = podTargetLabels
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
func (pm *PodMonitorBuilder) JobLabel(jobLabel string) *PodMonitorBuilder {
|
|
||||||
pm.obj.Spec.JobLabel = jobLabel
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
func (pm *PodMonitorBuilder) NamespaceSelector(any bool, matchNames []string) *PodMonitorBuilder {
|
|
||||||
pm.obj.Spec.NamespaceSelector = monitoringv1.NamespaceSelector{
|
|
||||||
Any: any,
|
|
||||||
MatchNames: matchNames,
|
|
||||||
}
|
|
||||||
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
func (pm *PodMonitorBuilder) SampleLimit(sampleLimit uint64) *PodMonitorBuilder {
|
|
||||||
pm.obj.Spec.SampleLimit = sampleLimit
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pm *PodMonitorBuilder) PodMetricsEndpoints(pme ...*PodMetricsEndpointBuilder) *PodMonitorBuilder {
|
|
||||||
pm.podMetricsEndpoints = pme
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns the object after making certain assertions
|
|
||||||
func (pm *PodMonitorBuilder) Build() error {
|
|
||||||
pm.obj.Spec.PodMetricsEndpoints = []monitoringv1.PodMetricsEndpoint{}
|
|
||||||
for _, pmeBuilder := range pm.podMetricsEndpoints {
|
|
||||||
podMetricsEndpoint, err := pmeBuilder.Build()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
pm.obj.Spec.PodMetricsEndpoints = append(pm.obj.Spec.PodMetricsEndpoints, podMetricsEndpoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !pm.isOwnedByOthers() {
|
|
||||||
return controllerutil.SetControllerReference(pm.owner, pm.obj, pm.scheme)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// isOwnedByOthers checks if this podMonitor has been possessed by an another object already.
|
|
||||||
func (pm *PodMonitorBuilder) isOwnedByOthers() bool {
|
|
||||||
ownerName := pm.owner.GetName()
|
|
||||||
|
|
||||||
existingRefs := pm.obj.GetOwnerReferences()
|
|
||||||
for _, r := range existingRefs {
|
|
||||||
if r.Name == ownerName {
|
|
||||||
return false
|
|
||||||
} else if r.Controller != nil && *r.Controller {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
v1 "k8s.io/api/core/v1"
|
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PodSpecBuilder is an interface for building a PodSpec
|
|
||||||
type PodSpecBuilder struct {
|
|
||||||
obj *corev1.PodSpec
|
|
||||||
containers []*ContainerBuilder
|
|
||||||
volumes []*VolumeBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodSpec returns a builder object for a PodSpec
|
|
||||||
func PodSpec() *PodSpecBuilder {
|
|
||||||
podSpec := &corev1.PodSpec{
|
|
||||||
DNSPolicy: corev1.DNSClusterFirst,
|
|
||||||
RestartPolicy: corev1.RestartPolicyAlways,
|
|
||||||
SchedulerName: "default-scheduler",
|
|
||||||
// SecurityContext: &v1.PodSecurityContext{
|
|
||||||
// RunAsNonRoot: pointer.BoolPtr(true),
|
|
||||||
// },
|
|
||||||
TerminationGracePeriodSeconds: pointer.Int64Ptr(10),
|
|
||||||
}
|
|
||||||
|
|
||||||
return &PodSpecBuilder{
|
|
||||||
obj: podSpec,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Containers appends a container builder to the PodSpec
|
|
||||||
func (ps *PodSpecBuilder) Containers(c ...*ContainerBuilder) *PodSpecBuilder {
|
|
||||||
ps.containers = c
|
|
||||||
return ps
|
|
||||||
}
|
|
||||||
|
|
||||||
// Volumes appends a volume builder to the PodSpec
|
|
||||||
func (ps *PodSpecBuilder) Volumes(v ...*VolumeBuilder) *PodSpecBuilder {
|
|
||||||
ps.volumes = v
|
|
||||||
return ps
|
|
||||||
}
|
|
||||||
|
|
||||||
// NodeSelector defines a NodeSelector for PodSpec
|
|
||||||
func (ps *PodSpecBuilder) NodeSelector(selector map[string]string) *PodSpecBuilder {
|
|
||||||
ps.obj.NodeSelector = selector
|
|
||||||
return ps
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tolerations defines tolerations for PodSpec
|
|
||||||
func (ps *PodSpecBuilder) Tolerations(tolerations []v1.Toleration) *PodSpecBuilder {
|
|
||||||
ps.obj.Tolerations = tolerations
|
|
||||||
return ps
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build generates an object ensuring that all sub-objects work
|
|
||||||
func (ps *PodSpecBuilder) Build() (corev1.PodSpec, error) {
|
|
||||||
for _, c := range ps.containers {
|
|
||||||
container, err := c.Build()
|
|
||||||
if err != nil {
|
|
||||||
return corev1.PodSpec{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ps.obj.Containers = append(ps.obj.Containers, container)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, v := range ps.volumes {
|
|
||||||
volume := v.Build()
|
|
||||||
ps.obj.Volumes = append(ps.obj.Volumes, volume)
|
|
||||||
}
|
|
||||||
|
|
||||||
return *ps.obj, nil
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PodTemplateSpecBuilder is an interface for building a PodTemplateSpecBuilder
|
|
||||||
type PodTemplateSpecBuilder struct {
|
|
||||||
obj *corev1.PodTemplateSpec
|
|
||||||
podSpec *PodSpecBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodTemplateSpec returns a builder object for a PodTemplateSpec
|
|
||||||
func PodTemplateSpec() *PodTemplateSpecBuilder {
|
|
||||||
podTemplateSpec := &corev1.PodTemplateSpec{}
|
|
||||||
|
|
||||||
return &PodTemplateSpecBuilder{
|
|
||||||
obj: podTemplateSpec,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Labels sets up the labels for a PodTemplateSpec
|
|
||||||
func (pts *PodTemplateSpecBuilder) Labels(labels map[string]string) *PodTemplateSpecBuilder {
|
|
||||||
pts.obj.ObjectMeta = metav1.ObjectMeta{
|
|
||||||
Labels: labels,
|
|
||||||
}
|
|
||||||
return pts
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodSpec points this builder to PodSpec builder
|
|
||||||
func (pts *PodTemplateSpecBuilder) PodSpec(podSpec *PodSpecBuilder) *PodTemplateSpecBuilder {
|
|
||||||
pts.podSpec = podSpec
|
|
||||||
return pts
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build generates an object ensuring that all sub-objects work
|
|
||||||
func (pts *PodTemplateSpecBuilder) Build() (corev1.PodTemplateSpec, error) {
|
|
||||||
podSpec, err := pts.podSpec.Build()
|
|
||||||
if err != nil {
|
|
||||||
return corev1.PodTemplateSpec{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
pts.obj.Spec = podSpec
|
|
||||||
return *pts.obj, nil
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
monitoringv1 "opendev.org/vexxhost/openstack-operator/api/monitoring/v1"
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PrometheusRuleBuilder provides an interface to build PrometheusRules
|
|
||||||
type PrometheusRuleBuilder struct {
|
|
||||||
obj *monitoringv1.PrometheusRule
|
|
||||||
ruleGroups []*RuleGroupBuilder
|
|
||||||
owner metav1.Object
|
|
||||||
scheme *runtime.Scheme
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrometheusRule returns a new PrometheusRule builder
|
|
||||||
func PrometheusRule(existing *monitoringv1.PrometheusRule, owner metav1.Object, scheme *runtime.Scheme) *PrometheusRuleBuilder {
|
|
||||||
return &PrometheusRuleBuilder{
|
|
||||||
obj: existing,
|
|
||||||
owner: owner,
|
|
||||||
scheme: scheme,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pm *PrometheusRuleBuilder) Labels(labels map[string]string) *PrometheusRuleBuilder {
|
|
||||||
pm.obj.Labels = labels
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
|
|
||||||
// RuleGroups returns the ruleGroups
|
|
||||||
func (pm *PrometheusRuleBuilder) RuleGroups(ruleGroups ...*RuleGroupBuilder) *PrometheusRuleBuilder {
|
|
||||||
pm.ruleGroups = ruleGroups
|
|
||||||
return pm
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns the object after making certain assertions
|
|
||||||
func (pm *PrometheusRuleBuilder) Build() error {
|
|
||||||
pm.obj.Spec.Groups = []monitoringv1.RuleGroup{}
|
|
||||||
for _, rgBuilder := range pm.ruleGroups {
|
|
||||||
ruleGroup, err := rgBuilder.Build()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
pm.obj.Spec.Groups = append(pm.obj.Spec.Groups, ruleGroup)
|
|
||||||
}
|
|
||||||
if !pm.isOwnedByOthers() {
|
|
||||||
return controllerutil.SetControllerReference(pm.owner, pm.obj, pm.scheme)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// isOwnedByOthers checks if this podMonitor has been possessed by an another object already.
|
|
||||||
func (pm *PrometheusRuleBuilder) isOwnedByOthers() bool {
|
|
||||||
ownerName := pm.owner.GetName()
|
|
||||||
|
|
||||||
existingRefs := pm.obj.GetOwnerReferences()
|
|
||||||
for _, r := range existingRefs {
|
|
||||||
if r.Name == ownerName {
|
|
||||||
return false
|
|
||||||
} else if r.Controller != nil && *r.Controller {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/alecthomas/units"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
v1 "k8s.io/api/core/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PersistentVolumeClaimBuilder defines the interface to build a PVC
|
|
||||||
type PersistentVolumeClaimBuilder struct {
|
|
||||||
obj *corev1.PersistentVolumeClaim
|
|
||||||
}
|
|
||||||
|
|
||||||
// PVC returns a new PVC builder
|
|
||||||
func PersistentVolumeClaim(existing *corev1.PersistentVolumeClaim) *PersistentVolumeClaimBuilder {
|
|
||||||
|
|
||||||
return &PersistentVolumeClaimBuilder{
|
|
||||||
obj: existing,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) ReadWriteOnce() *PersistentVolumeClaimBuilder {
|
|
||||||
pvc.obj.Spec.AccessModes = []corev1.PersistentVolumeAccessMode{"ReadWriteOnce"}
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resources defines the resource configuration for the PV
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) Resources(storage int64) *PersistentVolumeClaimBuilder {
|
|
||||||
storage = storage * int64(units.Megabyte)
|
|
||||||
pvc.obj.Spec.Resources = v1.ResourceRequirements{
|
|
||||||
Requests: v1.ResourceList{
|
|
||||||
v1.ResourceStorage: *resource.NewQuantity(storage, resource.DecimalSI),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) ReadOnlyMany() *PersistentVolumeClaimBuilder {
|
|
||||||
pvc.obj.Spec.AccessModes = []corev1.PersistentVolumeAccessMode{"ReadOnlyMany"}
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) ReadWriteMany() *PersistentVolumeClaimBuilder {
|
|
||||||
pvc.obj.Spec.AccessModes = []corev1.PersistentVolumeAccessMode{"ReadWriteMany"}
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) Selector(selector metav1.LabelSelector) *PersistentVolumeClaimBuilder {
|
|
||||||
pvc.obj.Spec.Selector = &selector
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) VolumeName(name string) *PersistentVolumeClaimBuilder {
|
|
||||||
pvc.obj.Spec.VolumeName = name
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) StorageClassName(name string) *PersistentVolumeClaimBuilder {
|
|
||||||
pvc.obj.Spec.StorageClassName = &name
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) Block() *PersistentVolumeClaimBuilder {
|
|
||||||
*pvc.obj.Spec.VolumeMode = corev1.PersistentVolumeBlock
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) Filesystem() *PersistentVolumeClaimBuilder {
|
|
||||||
*pvc.obj.Spec.VolumeMode = corev1.PersistentVolumeFilesystem
|
|
||||||
return pvc
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns a complete PVC object
|
|
||||||
func (pvc *PersistentVolumeClaimBuilder) Build() (corev1.PersistentVolumeClaim, error) {
|
|
||||||
return *pvc.obj, nil
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
|
||||||
monitoringv1 "opendev.org/vexxhost/openstack-operator/api/monitoring/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RuleBuilder provides an interface to build rule
|
|
||||||
type RuleBuilder struct {
|
|
||||||
obj *monitoringv1.Rule
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rule returns a new podmonitor builder
|
|
||||||
func Rule() *RuleBuilder {
|
|
||||||
Rule := &monitoringv1.Rule{
|
|
||||||
Annotations: map[string]string{},
|
|
||||||
}
|
|
||||||
return &RuleBuilder{
|
|
||||||
obj: Rule,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleBuilder) Alert(alert string) *RuleBuilder {
|
|
||||||
r.obj.Alert = alert
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleBuilder) Expr(expr string) *RuleBuilder {
|
|
||||||
r.obj.Expr = intstr.FromString(expr)
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleBuilder) For(duration string) *RuleBuilder {
|
|
||||||
r.obj.For = duration
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleBuilder) Priority(p int) *RuleBuilder {
|
|
||||||
r.obj.Annotations["priority"] = "P" + strconv.Itoa(p)
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleBuilder) Message(m string) *RuleBuilder {
|
|
||||||
r.obj.Annotations["message"] = m
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns the object after making certain assertions
|
|
||||||
func (r *RuleBuilder) Build() (monitoringv1.Rule, error) {
|
|
||||||
return *r.obj, nil
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
monitoringv1 "opendev.org/vexxhost/openstack-operator/api/monitoring/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RuleGroupBuilder provides an interface to build RuleGroup
|
|
||||||
type RuleGroupBuilder struct {
|
|
||||||
obj *monitoringv1.RuleGroup
|
|
||||||
rules []*RuleBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
// RuleGroup returns a new rulegroup builder
|
|
||||||
func RuleGroup() *RuleGroupBuilder {
|
|
||||||
RuleGroup := &monitoringv1.RuleGroup{}
|
|
||||||
return &RuleGroupBuilder{
|
|
||||||
obj: RuleGroup,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleGroupBuilder) Name(Name string) *RuleGroupBuilder {
|
|
||||||
r.obj.Name = Name
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleGroupBuilder) Interval(Interval string) *RuleGroupBuilder {
|
|
||||||
r.obj.Interval = Interval
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleGroupBuilder) Rules(Rules ...*RuleBuilder) *RuleGroupBuilder {
|
|
||||||
r.rules = Rules
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuleGroupBuilder) PartialResponseStrategy(prs string) *RuleGroupBuilder {
|
|
||||||
r.obj.PartialResponseStrategy = prs
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns the object after making certain assertions
|
|
||||||
func (r *RuleGroupBuilder) Build() (monitoringv1.RuleGroup, error) {
|
|
||||||
|
|
||||||
r.obj.Rules = []monitoringv1.Rule{}
|
|
||||||
for _, rBuilder := range r.rules {
|
|
||||||
rule, err := rBuilder.Build()
|
|
||||||
if err != nil {
|
|
||||||
return monitoringv1.RuleGroup{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.obj.Rules = append(r.obj.Rules, rule)
|
|
||||||
}
|
|
||||||
|
|
||||||
return *r.obj, nil
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SecretBuilder defines the interface to build a Secret
|
|
||||||
type SecretBuilder struct {
|
|
||||||
obj *corev1.Secret
|
|
||||||
owner metav1.Object
|
|
||||||
scheme *runtime.Scheme
|
|
||||||
}
|
|
||||||
|
|
||||||
// Secret returns a new secret builder
|
|
||||||
func Secret(existing *corev1.Secret, owner metav1.Object, scheme *runtime.Scheme) *SecretBuilder {
|
|
||||||
existing.Data = map[string][]byte{}
|
|
||||||
existing.StringData = map[string]string{}
|
|
||||||
|
|
||||||
return &SecretBuilder{
|
|
||||||
obj: existing,
|
|
||||||
owner: owner,
|
|
||||||
scheme: scheme,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Data sets a key inside this Secret
|
|
||||||
func (cm *SecretBuilder) Data(key, value string) *SecretBuilder {
|
|
||||||
cm.obj.Data[key] = []byte(value)
|
|
||||||
return cm
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringData sets a key inside this Secret
|
|
||||||
func (cm *SecretBuilder) StringData(key, value string) *SecretBuilder {
|
|
||||||
cm.obj.StringData[key] = value
|
|
||||||
return cm
|
|
||||||
}
|
|
||||||
|
|
||||||
// SecretType sets the secret type
|
|
||||||
func (cm *SecretBuilder) SecretType(value string) *SecretBuilder {
|
|
||||||
cm.obj.Type = corev1.SecretType(value)
|
|
||||||
return cm
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns a complete Secret object
|
|
||||||
func (cm *SecretBuilder) Build() error {
|
|
||||||
return controllerutil.SetControllerReference(cm.owner, cm.obj, cm.scheme)
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SecurityContextBuilder defines the interface to build a securityContext
|
|
||||||
type SecurityContextBuilder struct {
|
|
||||||
obj *corev1.SecurityContext
|
|
||||||
}
|
|
||||||
|
|
||||||
// SecurityContext returns a new SecurityContext builder
|
|
||||||
func SecurityContext() *SecurityContextBuilder {
|
|
||||||
securityContext := &corev1.SecurityContext{}
|
|
||||||
return &SecurityContextBuilder{
|
|
||||||
obj: securityContext,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RunAsUser sets the RunAsUser inside this SecurityContext
|
|
||||||
func (sc *SecurityContextBuilder) RunAsUser(userID int64) *SecurityContextBuilder {
|
|
||||||
sc.obj.RunAsUser = pointer.Int64Ptr(userID)
|
|
||||||
return sc
|
|
||||||
}
|
|
||||||
|
|
||||||
// RunAsGroup sets the RunAsGroup inside this SecurityContext
|
|
||||||
func (sc *SecurityContextBuilder) RunAsGroup(groupID int64) *SecurityContextBuilder {
|
|
||||||
sc.obj.RunAsGroup = pointer.Int64Ptr(groupID)
|
|
||||||
return sc
|
|
||||||
}
|
|
||||||
|
|
||||||
// RunAsNonRoot sets the RunAsNonRoot inside this SecurityContext
|
|
||||||
func (sc *SecurityContextBuilder) RunAsNonRoot(flag bool) *SecurityContextBuilder {
|
|
||||||
sc.obj.RunAsNonRoot = pointer.BoolPtr(flag)
|
|
||||||
return sc
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns a complete ConfigMap object
|
|
||||||
func (sc *SecurityContextBuilder) Build() (corev1.SecurityContext, error) {
|
|
||||||
return *sc.obj, nil
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
v1 "k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ServiceBuilder defines the interface to build a service
|
|
||||||
type ServiceBuilder struct {
|
|
||||||
obj *corev1.Service
|
|
||||||
owner metav1.Object
|
|
||||||
scheme *runtime.Scheme
|
|
||||||
}
|
|
||||||
|
|
||||||
// Service returns a new service builder
|
|
||||||
func Service(existing *corev1.Service, owner metav1.Object, scheme *runtime.Scheme) *ServiceBuilder {
|
|
||||||
existing.Spec.Ports = []corev1.ServicePort{}
|
|
||||||
|
|
||||||
return &ServiceBuilder{
|
|
||||||
obj: existing,
|
|
||||||
owner: owner,
|
|
||||||
scheme: scheme,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Port appends a port to the service
|
|
||||||
func (s *ServiceBuilder) Port(name string, port int32) *ServiceBuilder {
|
|
||||||
s.obj.Spec.Ports = append(s.obj.Spec.Ports, corev1.ServicePort{
|
|
||||||
Name: name,
|
|
||||||
Protocol: v1.ProtocolTCP,
|
|
||||||
Port: port,
|
|
||||||
TargetPort: intstr.FromString(name),
|
|
||||||
})
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// Selector defines the service selectors
|
|
||||||
func (s *ServiceBuilder) Selector(labels map[string]string) *ServiceBuilder {
|
|
||||||
s.obj.Spec.Selector = labels
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns a complete Service object
|
|
||||||
func (s *ServiceBuilder) Build() error {
|
|
||||||
return controllerutil.SetControllerReference(s.owner, s.obj, s.scheme)
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StatefulSetBuilder defines the interface to build a StatefulSet
|
|
||||||
type StatefulSetBuilder struct {
|
|
||||||
obj *appsv1.StatefulSet
|
|
||||||
podTemplateSpec *PodTemplateSpecBuilder
|
|
||||||
pvcs []*PersistentVolumeClaimBuilder
|
|
||||||
scheme *runtime.Scheme
|
|
||||||
labels map[string]string
|
|
||||||
owner metav1.Object
|
|
||||||
}
|
|
||||||
|
|
||||||
// StatefulSet returns a new StatefulSet builder
|
|
||||||
func StatefulSet(existing *appsv1.StatefulSet, owner metav1.Object, scheme *runtime.Scheme) *StatefulSetBuilder {
|
|
||||||
return &StatefulSetBuilder{
|
|
||||||
obj: existing,
|
|
||||||
labels: map[string]string{},
|
|
||||||
owner: owner,
|
|
||||||
scheme: scheme,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Labels specifies labels for the StatefulSet
|
|
||||||
func (d *StatefulSetBuilder) Labels(labels map[string]string) *StatefulSetBuilder {
|
|
||||||
d.labels = labels
|
|
||||||
d.obj.ObjectMeta.Labels = d.labels
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replicas defines the number of replicas
|
|
||||||
func (d *StatefulSetBuilder) Replicas(replicas int32) *StatefulSetBuilder {
|
|
||||||
d.obj.Spec.Replicas = pointer.Int32Ptr(replicas)
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodTemplateSpec defines a builder for the pod template spec
|
|
||||||
func (d *StatefulSetBuilder) PodTemplateSpec(podTemplateSpec *PodTemplateSpecBuilder) *StatefulSetBuilder {
|
|
||||||
d.podTemplateSpec = podTemplateSpec
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// PVCs defines a builder array for the PVC spec
|
|
||||||
func (d *StatefulSetBuilder) PVCs(pvcs ...*PersistentVolumeClaimBuilder) *StatefulSetBuilder {
|
|
||||||
d.pvcs = pvcs
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build creates a final StatefulSet objet
|
|
||||||
func (d *StatefulSetBuilder) Build() error {
|
|
||||||
podTemplateSpec, err := d.podTemplateSpec.Labels(d.labels).Build()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
d.obj.Spec.Template = podTemplateSpec
|
|
||||||
|
|
||||||
for _, c := range d.pvcs {
|
|
||||||
pvc, err := c.Build()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
d.obj.Spec.VolumeClaimTemplates = append(d.obj.Spec.VolumeClaimTemplates, pvc)
|
|
||||||
}
|
|
||||||
|
|
||||||
return controllerutil.SetControllerReference(d.owner, d.obj, d.scheme)
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package builders
|
|
||||||
|
|
||||||
import (
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
|
||||||
v1 "k8s.io/api/core/v1"
|
|
||||||
"k8s.io/utils/pointer"
|
|
||||||
)
|
|
||||||
|
|
||||||
// VolumeBuilder provides an interface to build volumes
|
|
||||||
type VolumeBuilder struct {
|
|
||||||
obj *corev1.Volume
|
|
||||||
}
|
|
||||||
|
|
||||||
// Volume returns a new volume builder
|
|
||||||
func Volume(name string) *VolumeBuilder {
|
|
||||||
volume := &corev1.Volume{
|
|
||||||
Name: name,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &VolumeBuilder{
|
|
||||||
obj: volume,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FromConfigMap sets the source of the volume from a ConfigMap
|
|
||||||
func (v *VolumeBuilder) FromConfigMap(name string) *VolumeBuilder {
|
|
||||||
v.obj.VolumeSource = corev1.VolumeSource{
|
|
||||||
ConfigMap: &corev1.ConfigMapVolumeSource{
|
|
||||||
LocalObjectReference: v1.LocalObjectReference{Name: name},
|
|
||||||
DefaultMode: pointer.Int32Ptr(420),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// FromSecret sets the source of the volume from a Secret
|
|
||||||
func (v *VolumeBuilder) FromSecret(name string) *VolumeBuilder {
|
|
||||||
v.obj.VolumeSource = corev1.VolumeSource{
|
|
||||||
Secret: &corev1.SecretVolumeSource{
|
|
||||||
SecretName: name,
|
|
||||||
DefaultMode: pointer.Int32Ptr(420),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// FromPersistentVolumeClaim sets the source of the volume from a PVC
|
|
||||||
func (v *VolumeBuilder) FromPersistentVolumeClaim(name string) *VolumeBuilder {
|
|
||||||
v.obj.VolumeSource = corev1.VolumeSource{
|
|
||||||
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
|
|
||||||
ClaimName: name,
|
|
||||||
ReadOnly: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build returns the object after checking assertions
|
|
||||||
func (v *VolumeBuilder) Build() corev1.Volume {
|
|
||||||
return *v.obj
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
@ -13,9 +13,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# Build-time arguments
|
|
||||||
ARG REV=latest
|
|
||||||
|
|
||||||
# Build the manager binary
|
# Build the manager binary
|
||||||
FROM golang:1.13 as builder
|
FROM golang:1.13 as builder
|
||||||
|
|
||||||
@ -33,10 +30,9 @@ COPY api/ api/
|
|||||||
COPY builders/ builders/
|
COPY builders/ builders/
|
||||||
COPY controllers/ controllers/
|
COPY controllers/ controllers/
|
||||||
COPY utils/ utils/
|
COPY utils/ utils/
|
||||||
COPY version/ version/
|
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags "-X version.Revision=${REV}" -a -o manager main.go
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
|
||||||
|
|
||||||
# NOTE(mnaser): Rename python-builder to builder
|
# NOTE(mnaser): Rename python-builder to builder
|
||||||
FROM docker.io/opendevorg/python-builder as python-builder
|
FROM docker.io/opendevorg/python-builder as python-builder
|
||||||
|
5
main.go
5
main.go
@ -25,10 +25,8 @@ import (
|
|||||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||||
|
|
||||||
dnsv1 "opendev.org/vexxhost/openstack-operator/api/dns/v1"
|
dnsv1 "opendev.org/vexxhost/openstack-operator/api/dns/v1"
|
||||||
monitoringv1 "opendev.org/vexxhost/openstack-operator/api/monitoring/v1"
|
|
||||||
"opendev.org/vexxhost/openstack-operator/controllers"
|
"opendev.org/vexxhost/openstack-operator/controllers"
|
||||||
"opendev.org/vexxhost/openstack-operator/utils/openstackutils"
|
"opendev.org/vexxhost/openstack-operator/utils/openstackutils"
|
||||||
"opendev.org/vexxhost/openstack-operator/version"
|
|
||||||
// +kubebuilder:scaffold:imports
|
// +kubebuilder:scaffold:imports
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,7 +37,6 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
_ = clientgoscheme.AddToScheme(scheme)
|
_ = clientgoscheme.AddToScheme(scheme)
|
||||||
_ = monitoringv1.AddToScheme(scheme)
|
|
||||||
_ = dnsv1.AddToScheme(scheme)
|
_ = dnsv1.AddToScheme(scheme)
|
||||||
// +kubebuilder:scaffold:scheme
|
// +kubebuilder:scaffold:scheme
|
||||||
}
|
}
|
||||||
@ -76,7 +73,7 @@ func main() {
|
|||||||
setupDesignateReconciler(mgr, designateClientBuilder)
|
setupDesignateReconciler(mgr, designateClientBuilder)
|
||||||
|
|
||||||
// +kubebuilder:scaffold:builder
|
// +kubebuilder:scaffold:builder
|
||||||
setupLog.Info("starting manager", "revision", version.Revision)
|
setupLog.Info("starting manager")
|
||||||
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
|
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
|
||||||
setupLog.Error(err, "problem running manager")
|
setupLog.Error(err, "problem running manager")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package baseutils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/base64"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Base64DecodeByte2Str returns plain text as string from the encrypted text as byte array
|
|
||||||
func Base64DecodeByte2Str(enc []byte) string {
|
|
||||||
encStr := string(enc)
|
|
||||||
decStr, err := base64.StdEncoding.DecodeString(encStr)
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return string(decStr)
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package baseutils
|
|
||||||
|
|
||||||
// MergeMaps merges all maps in the list
|
|
||||||
func MergeMaps(MapList ...map[string]string) map[string]string {
|
|
||||||
var baseMap = make(map[string]string)
|
|
||||||
for _, imap := range MapList {
|
|
||||||
for k, v := range imap {
|
|
||||||
baseMap[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return baseMap
|
|
||||||
}
|
|
||||||
|
|
||||||
// MergeMapsWithoutOverwrite merges all maps in the list without overwriting. The priority is the same as the sequence of the list.
|
|
||||||
func MergeMapsWithoutOverwrite(MapList ...map[string]string) map[string]string {
|
|
||||||
var baseMap = make(map[string]string)
|
|
||||||
for _, imap := range MapList {
|
|
||||||
for k, v := range imap {
|
|
||||||
if _, ok := baseMap[k]; !ok {
|
|
||||||
baseMap[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return baseMap
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package baseutils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func assertMergeMaps(t *testing.T, cr, instance, expected map[string]string) {
|
|
||||||
merged := MergeMapsWithoutOverwrite(cr, instance)
|
|
||||||
assert.Equal(t, expected, merged)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMergeMapsWithNoInstanceLabels(t *testing.T) {
|
|
||||||
cr := map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
}
|
|
||||||
instance := map[string]string{}
|
|
||||||
expected := map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
}
|
|
||||||
|
|
||||||
assertMergeMaps(t, cr, instance, expected)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMergeMapsWithDifferentInstanceLabels(t *testing.T) {
|
|
||||||
cr := map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
}
|
|
||||||
instance := map[string]string{
|
|
||||||
"more": "options",
|
|
||||||
}
|
|
||||||
expected := map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
"more": "options",
|
|
||||||
}
|
|
||||||
|
|
||||||
assertMergeMaps(t, cr, instance, expected)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMergeMapsWithCustomResourceLabelOverride(t *testing.T) {
|
|
||||||
cr := map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
}
|
|
||||||
instance := map[string]string{
|
|
||||||
"foo": "bar2",
|
|
||||||
"more": "options",
|
|
||||||
}
|
|
||||||
expected := map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
"more": "options",
|
|
||||||
}
|
|
||||||
|
|
||||||
assertMergeMaps(t, cr, instance, expected)
|
|
||||||
}
|
|
@ -16,9 +16,7 @@ package k8sutils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||||
@ -29,22 +27,11 @@ import (
|
|||||||
func CreateOrUpdate(ctx context.Context, c client.Client, obj runtime.Object, f controllerutil.MutateFn) (controllerutil.OperationResult, error) {
|
func CreateOrUpdate(ctx context.Context, c client.Client, obj runtime.Object, f controllerutil.MutateFn) (controllerutil.OperationResult, error) {
|
||||||
|
|
||||||
return controllerutil.CreateOrUpdate(ctx, c, obj, func() error {
|
return controllerutil.CreateOrUpdate(ctx, c, obj, func() error {
|
||||||
original := obj.DeepCopyObject()
|
|
||||||
|
|
||||||
err := f()
|
err := f()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
generateObjectDiff(original, obj)
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateObjectDiff(original runtime.Object, modified runtime.Object) {
|
|
||||||
diff := cmp.Diff(original, modified)
|
|
||||||
|
|
||||||
if len(diff) != 0 {
|
|
||||||
fmt.Println(diff)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
// Copyright 2020 VEXXHOST, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package version
|
|
||||||
|
|
||||||
// Revision contains the current revision of the project
|
|
||||||
var Revision string = "latest"
|
|
Loading…
x
Reference in New Issue
Block a user