Browse Source

go version removal v1

Change-Id: I5b2e90549c8ca4f6b1c91b0879470a2cee59bf59
changes/40/721040/1
Mohammed Naser 1 year ago
parent
commit
add918bd3c
27 changed files with 2 additions and 2116 deletions
  1. +0
    -33
      api/monitoring/v1/groupversion_info.go
  2. +0
    -207
      api/monitoring/v1/monitor_types.go
  3. +0
    -358
      api/monitoring/v1/zz_generated.deepcopy.go
  4. +0
    -51
      builders/config_map.go
  5. +0
    -203
      builders/container.go
  6. +0
    -73
      builders/deployment.go
  7. +0
    -82
      builders/pod_metrics_endpoint.go
  8. +0
    -111
      builders/pod_monitor.go
  9. +0
    -88
      builders/pod_spec.go
  10. +0
    -60
      builders/pod_template_spec.go
  11. +0
    -82
      builders/prometheus_rule.go
  12. +0
    -92
      builders/pvc.go
  13. +0
    -67
      builders/rule.go
  14. +0
    -69
      builders/rule_group.go
  15. +0
    -64
      builders/secret.go
  16. +0
    -56
      builders/security_context.go
  17. +0
    -64
      builders/service.go
  18. +0
    -90
      builders/statefulset.go
  19. +0
    -75
      builders/volume.go
  20. +0
    -13
      hack/boilerplate.go.txt
  21. +1
    -5
      images/openstack-operator/Dockerfile
  22. +1
    -4
      main.go
  23. +0
    -29
      utils/baseutils/codec.go
  24. +0
    -40
      utils/baseutils/map.go
  25. +0
    -69
      utils/baseutils/map_test.go
  26. +0
    -13
      utils/k8sutils/kubernetes.go
  27. +0
    -18
      version/main.go

+ 0
- 33
api/monitoring/v1/groupversion_info.go View File

@ -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
)

+ 0
- 207
api/monitoring/v1/monitor_types.go View File

@ -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{})
}

+ 0
- 358
api/monitoring/v1/zz_generated.deepcopy.go View File

@ -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
}

+ 0
- 51
builders/config_map.go View File

@ -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)
}

+ 0
- 203
builders/container.go View File

@ -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
}

+ 0
- 73
builders/deployment.go View File

@ -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)
}

+ 0
- 82
builders/pod_metrics_endpoint.go View File

@ -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
}

+ 0
- 111
builders/pod_monitor.go View File

@ -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
}

+ 0
- 88
builders/pod_spec.go View File

@ -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
}

+ 0
- 60
builders/pod_template_spec.go View File

@ -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
}

+ 0
- 82
builders/prometheus_rule.go View File

@ -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
}

+ 0
- 92
builders/pvc.go View File

@ -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
}

+ 0
- 67
builders/rule.go View File

@ -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
}

+ 0
- 69
builders/rule_group.go View File

@ -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
}

+ 0
- 64
builders/secret.go View File

@ -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)
}

+ 0
- 56
builders/security_context.go View File

@ -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{