Browse Source

node selector, tolerations, storage class, set limits

tags/0.0.2
Vladimir Smagin 1 month ago
parent
commit
6419d8a4e0

+ 0
- 1
README.md View File

@@ -37,7 +37,6 @@ spec:
autosaveInterval: 600
autosaveOnChanges: True
allowAnonymous: False
replicas: 1
persistent: True
persistentVolumeSize: 1Gi
users:

+ 1
- 1
VERSION View File

@@ -1 +1 @@
0.0.1
0.0.2

+ 30
- 0
deploy/rbac-cluster-scoped/operator.yaml View File

@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mqtt-operator
spec:
replicas: 1
selector:
matchLabels:
name: mqtt-operator
template:
metadata:
labels:
name: mqtt-operator
spec:
serviceAccountName: mqtt-operator
containers:
- name: mqtt-operator
image: iam21h/mqtt-operator
command:
- mqtt-operator
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
value: ""
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "mqtt-operator"

+ 61
- 0
deploy/rbac-cluster-scoped/role.yaml View File

@@ -0,0 +1,61 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: mqtt-operator
rules:
- apiGroups:
- ""
resources:
- pods
- services
- services/finalizers
- endpoints
- persistentvolumeclaims
- events
- configmaps
- secrets
verbs:
- '*'
- apiGroups:
- apps
resources:
- deployments
- daemonsets
- replicasets
- statefulsets
verbs:
- '*'
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- get
- create
- apiGroups:
- apps
resourceNames:
- mqtt-operator
resources:
- deployments/finalizers
verbs:
- update
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- apps
resources:
- replicasets
verbs:
- get
- apiGroups:
- blindage.org
resources:
- '*'
verbs:
- '*'

+ 13
- 0
deploy/rbac-cluster-scoped/role_binding.yaml View File

@@ -0,0 +1,13 @@
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: mqtt-operator
subjects:
- kind: ServiceAccount
name: mqtt-operator
# set namespace!
namespace: operators
roleRef:
kind: ClusterRole
name: mqtt-operator
apiGroup: rbac.authorization.k8s.io

deploy/service_account.yaml → deploy/rbac-cluster-scoped/service_account.yaml View File


+ 32
- 0
deploy/rbac-namespace-scoped/operator.yaml View File

@@ -0,0 +1,32 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mqtt-operator
spec:
replicas: 1
selector:
matchLabels:
name: mqtt-operator
template:
metadata:
labels:
name: mqtt-operator
spec:
serviceAccountName: mqtt-operator
containers:
- name: mqtt-operator
image: iam21h/mqtt-operator
command:
- mqtt-operator
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "mqtt-operator"

deploy/role.yaml → deploy/rbac-namespace-scoped/role.yaml View File


deploy/role_binding.yaml → deploy/rbac-namespace-scoped/role_binding.yaml View File


+ 4
- 0
deploy/rbac-namespace-scoped/service_account.yaml View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: mqtt-operator

+ 2
- 2
deploy/test-instance.yaml View File

@@ -6,9 +6,9 @@ spec:
autosaveInterval: 600
autosaveOnChanges: True
allowAnonymous: False
replicas: 1
persistent: True
persistentVolumeSize: 1Gi
users:
myuser: mypassword
penis: huy2
santa: buttman_sucks
penis: huy

+ 2
- 1
go.mod View File

@@ -1,7 +1,6 @@
module git.blindage.org/21h/mqtt-operator

require (
github.com/NYTimes/gziphandler v1.0.1 // indirect
github.com/certifi/gocertifi v0.0.0-20190506164543-d2eda7129713 // indirect
github.com/getsentry/raven-go v0.2.0
github.com/go-openapi/spec v0.19.0
@@ -32,3 +31,5 @@ replace (
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.1.12
sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde
)

go 1.13

+ 14
- 9
pkg/apis/blindage/v1alpha1/mqtt_types.go View File

@@ -15,7 +15,6 @@ import (
// MQTTSpec you what is it
type MQTTSpec struct {
// image specific settings
Replicas int32 `json:"replicas"` // default 1
PullPolicy *v1.PullPolicy `json:"pullPolicy,omitempty"` // default if not exists
Image string `json:"image,omitempty"` // default eclipse-mosquitto:latest

@@ -28,15 +27,21 @@ type MQTTSpec struct {
AutosaveOnChanges bool `json:"autosaveOnChanges,omitempty"` // false
CheckRetainSource bool `json:"checkRetainSource,omitempty"` // false
ConnectionMessages bool `json:"connectionMessages,omitempty"` // false
Persistent bool `json:"persistent,omitempty"` // false, no PVC for persistence mode
PersistentVolumeSize resource.Quantity `json:"persistentVolumeSize,omitempty"` // 1Gi
RetainAvailable bool `json:"retainAvailable,omitempty"` // false
RetainedPersistence bool `json:"retainedPersistence,omitempty"` // false

// manage resources
PodRequests *v1.ResourceList `json:"podRequests,omitempty"`
PodLimits *v1.ResourceList `json:"podLimits,omitempty"`
Affinity *v1.Affinity `json:"affinity,omitempty"`
// persistence means files on PVC
Persistent bool `json:"persistent,omitempty"` // false, no PVC for persistence mode
PersistentVolumeSize resource.Quantity `json:"persistentVolumeSize,omitempty"` // default 1Gi
PersistentStorageClass string `json:"persistentStorageClass,omitempty"` // if empty PVC will be created under default class

RetainAvailable bool `json:"retainAvailable,omitempty"` // false
RetainedPersistence bool `json:"retainedPersistence,omitempty"` // false

// manage resources, standart in Kubernetes, see official docs
PodRequests *v1.ResourceList `json:"podRequests,omitempty"`
PodLimits *v1.ResourceList `json:"podLimits,omitempty"`
Affinity *v1.Affinity `json:"affinity,omitempty"`
NodeSelector *map[string]string `json:"nodeSelector"`
Tolerations *[]v1.Toleration `json:"tolerations"`
}

// MQTTStatus defines the observed state of MQTT

+ 22
- 0
pkg/apis/blindage/v1alpha1/zz_generated.deepcopy.go View File

@@ -114,6 +114,28 @@ func (in *MQTTSpec) DeepCopyInto(out *MQTTSpec) {
*out = new(v1.Affinity)
(*in).DeepCopyInto(*out)
}
if in.NodeSelector != nil {
in, out := &in.NodeSelector, &out.NodeSelector
*out = new(map[string]string)
if **in != nil {
in, out := *in, *out
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
}
if in.Tolerations != nil {
in, out := &in.Tolerations, &out.Tolerations
*out = new([]v1.Toleration)
if **in != nil {
in, out := *in, *out
*out = make([]v1.Toleration, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
return
}


+ 32
- 4
pkg/controller/mqtt/manifests.go View File

@@ -8,6 +8,7 @@ import (

v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
@@ -62,6 +63,16 @@ func generateMQTTDeployment(cr *blindagev1alpha1.MQTT) v1.Deployment {
resourcesRequests = *cr.Spec.PodRequests
}

// advisor is a bash script, so tiny numbers
resourcesLimitsAdvisor := corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
corev1.ResourceMemory: resource.MustParse("64Mi"),
}
resourcesRequestsAdvisor := corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("50m"),
corev1.ResourceMemory: resource.MustParse("32Mi"),
}

ports := []corev1.ContainerPort{
{
Name: "mqtt",
@@ -82,6 +93,9 @@ func generateMQTTDeployment(cr *blindagev1alpha1.MQTT) v1.Deployment {

shareProcessNamespace := true

// mosquitto simply does not have clustering
replicas := int32(1)

deployment := v1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name,
@@ -92,7 +106,7 @@ func generateMQTTDeployment(cr *blindagev1alpha1.MQTT) v1.Deployment {
Selector: &metav1.LabelSelector{
MatchLabels: baseLabels(cr),
},
Replicas: &cr.Spec.Replicas,
Replicas: &replicas,
Strategy: v1.DeploymentStrategy{Type: v1.RollingUpdateDeploymentStrategyType, RollingUpdate: nil},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
@@ -158,8 +172,8 @@ func generateMQTTDeployment(cr *blindagev1alpha1.MQTT) v1.Deployment {
},
},
Resources: corev1.ResourceRequirements{
Limits: resourcesLimits,
Requests: resourcesRequests,
Limits: resourcesLimitsAdvisor,
Requests: resourcesRequestsAdvisor,
},
},
},
@@ -200,11 +214,19 @@ func generateMQTTDeployment(cr *blindagev1alpha1.MQTT) v1.Deployment {
},
}

if cr.Spec.NodeSelector != nil {
deployment.Spec.Template.Spec.NodeSelector = *cr.Spec.NodeSelector
}

if cr.Spec.Tolerations != nil {
deployment.Spec.Template.Spec.Tolerations = *cr.Spec.Tolerations
}

return deployment
}

func generateDataVolume(cr *blindagev1alpha1.MQTT) corev1.PersistentVolumeClaim {
return corev1.PersistentVolumeClaim{
pv := corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-data",
Namespace: cr.Namespace,
@@ -218,6 +240,12 @@ func generateDataVolume(cr *blindagev1alpha1.MQTT) corev1.PersistentVolumeClaim
},
},
}

if cr.Spec.PersistentStorageClass != "" {
pv.Spec.StorageClassName = &cr.Spec.PersistentStorageClass
}

return pv
}

func generateMQTTConfig(cr *blindagev1alpha1.MQTT) corev1.ConfigMap {

+ 1
- 1
version/version.go View File

@@ -1,5 +1,5 @@
package version

var (
Version = "0.0.1"
Version = "0.0.2"
)

Loading…
Cancel
Save