Browse Source

fix volume size, add default size, nodeselector and tolerations

tags/0.0.2
Vladimir Smagin Gitea 8 months ago
parent
commit
415352a5c0
11 changed files with 227 additions and 46 deletions
  1. +1
    -1
      VERSION
  2. +61
    -0
      deploy/clusterrole.yaml
  3. +12
    -0
      deploy/clusterrole_binding.yaml
  4. +0
    -23
      deploy/crds/blindage_v1alpha1_wordpress_cr.yaml
  5. +1
    -3
      deploy/operator.yaml
  6. +33
    -0
      deploy/test-instance.yaml
  7. +1
    -0
      go.mod
  8. +14
    -9
      pkg/apis/blindage/v1alpha1/wordpress_types.go
  9. +54
    -2
      pkg/apis/blindage/v1alpha1/zz_generated.deepcopy.go
  10. +49
    -7
      pkg/controller/wordpress/manifests.go
  11. +1
    -1
      version/version.go

+ 1
- 1
VERSION View File

@@ -1 +1 @@
0.0.1
0.0.2

+ 61
- 0
deploy/clusterrole.yaml View File

@@ -0,0 +1,61 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: wordpress-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:
- wordpress-operator
resources:
- deployments/finalizers
verbs:
- update
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- apps
resources:
- replicasets
verbs:
- get
- apiGroups:
- blindage.org
resources:
- '*'
verbs:
- '*'

+ 12
- 0
deploy/clusterrole_binding.yaml View File

@@ -0,0 +1,12 @@
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: wordpress-operator
subjects:
- kind: ServiceAccount
name: wordpress-operator
namespace: operators
roleRef:
kind: ClusterRole
name: wordpress-operator
apiGroup: rbac.authorization.k8s.io

+ 0
- 23
deploy/crds/blindage_v1alpha1_wordpress_cr.yaml View File

@@ -1,23 +0,0 @@
---
apiVersion: blindage.org/v1alpha1
kind: Wordpress
metadata:
name: my-test-wordpress
spec:
replicas: 3
databaseVolumeSize: 1Gi
wordpressVolumeSize: 1Gi

---
apiVersion: blindage.org/v1alpha1
kind: Wordpress
metadata:
name: another
spec:
database:
database: wordpress
hostname: my-test-wordpress-database
password: wordpress
username: wordpress
replicas: 1
wordpressVolumeSize: 1Gi

+ 1
- 3
deploy/operator.yaml View File

@@ -21,9 +21,7 @@ spec:
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
value: ""
- name: POD_NAME
valueFrom:
fieldRef:


+ 33
- 0
deploy/test-instance.yaml View File

@@ -0,0 +1,33 @@
---
apiVersion: blindage.org/v1alpha1
kind: Wordpress
metadata:
name: my-pretty-wordpress
spec:
replicas: 3
databaseVolumeSize: 1Gi
wordpressVolumeSize: 2Gi
wordpressStorageClass: csi-s3

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-pretty-wordpress
annotations:
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
kubernetes.io/ingress.class: nginx
spec:
tls:
- hosts:
- "blog.k8s.blindage.org"
secretName: mycluster-staging-tls
rules:
- host: blog.k8s.blindage.org
http:
paths:
- path: /
backend:
serviceName: my-pretty-wordpress
servicePort: http


+ 1
- 0
go.mod View File

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

require (
github.com/NYTimes/gziphandler v1.0.1 // indirect
github.com/certifi/gocertifi v0.0.0-20190506164543-d2eda7129713 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect


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

@@ -27,19 +27,24 @@ type WordpressSpec struct {
// Define database if you want use external DB
Database *ExternalMysql `json:"database,omitempty"`
// Internal database will be initialized with this parametes
DatabaseImage string `json:"databaseImage,omitempty"` // default mariadb:latest
DatabasePodRequests *v1.ResourceList `json:"databasePodRequests,omitempty"`
DatabasePodLimits *v1.ResourceList `json:"databasePodLimits,omitempty"`
DatabaseAffinity *v1.Affinity `json:"databaseAffinity,omitempty"`
DatabaseVolumeSize resource.Quantity `json:"databaseVolumeSize,omitempty"` //default 1 Gb
DatabaseImage string `json:"databaseImage,omitempty"` // default mariadb:latest
DatabasePodRequests *v1.ResourceList `json:"databasePodRequests,omitempty"`
DatabasePodLimits *v1.ResourceList `json:"databasePodLimits,omitempty"`
DatabaseAffinity *v1.Affinity `json:"databaseAffinity,omitempty"`
DatabaseVolumeSize *resource.Quantity `json:"databaseVolumeSize,omitempty"` //default 1 Gb
DatabaseNodeSelector *map[string]string `json:"databaseNodeSelector"`
DatabaseTolerations *[]v1.Toleration `json:"databaseTolerations"`

// manage resources
WordpressPodRequests *v1.ResourceList `json:"wordpressPodRequests,omitempty"`
WordpressPodLimits *v1.ResourceList `json:"wordpressPodLimits,omitempty"`
WordpressAffinity *v1.Affinity `json:"wordpressAffinity,omitempty"`
WordpressPodRequests *v1.ResourceList `json:"wordpressPodRequests,omitempty"`
WordpressPodLimits *v1.ResourceList `json:"wordpressPodLimits,omitempty"`
WordpressAffinity *v1.Affinity `json:"wordpressAffinity,omitempty"`
WordpressNodeSelector *map[string]string `json:"wordpressNodeSelector"`
WordpressTolerations *[]v1.Toleration `json:"wordpressTolerations"`

// set volume size for wp-content
WordpressVolumeSize resource.Quantity `json:"wordpressVolumeSize,omitempty"` // default 1 Gb
WordpressVolumeSize *resource.Quantity `json:"wordpressVolumeSize,omitempty"` // default 1 Gb
WordpressStorageClass string `json:"wordpressStorageClass,omitempty"`

// set annotations to service and pod, default is empty
WordpressServiceAnnotations *map[string]string `json:"wordpressServiceAnnotations,omitempty"`


+ 54
- 2
pkg/apis/blindage/v1alpha1/zz_generated.deepcopy.go View File

@@ -127,7 +127,33 @@ func (in *WordpressSpec) DeepCopyInto(out *WordpressSpec) {
*out = new(v1.Affinity)
(*in).DeepCopyInto(*out)
}
out.DatabaseVolumeSize = in.DatabaseVolumeSize.DeepCopy()
if in.DatabaseVolumeSize != nil {
in, out := &in.DatabaseVolumeSize, &out.DatabaseVolumeSize
x := (*in).DeepCopy()
*out = &x
}
if in.DatabaseNodeSelector != nil {
in, out := &in.DatabaseNodeSelector, &out.DatabaseNodeSelector
*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.DatabaseTolerations != nil {
in, out := &in.DatabaseTolerations, &out.DatabaseTolerations
*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])
}
}
}
if in.WordpressPodRequests != nil {
in, out := &in.WordpressPodRequests, &out.WordpressPodRequests
*out = new(v1.ResourceList)
@@ -155,7 +181,33 @@ func (in *WordpressSpec) DeepCopyInto(out *WordpressSpec) {
*out = new(v1.Affinity)
(*in).DeepCopyInto(*out)
}
out.WordpressVolumeSize = in.WordpressVolumeSize.DeepCopy()
if in.WordpressNodeSelector != nil {
in, out := &in.WordpressNodeSelector, &out.WordpressNodeSelector
*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.WordpressTolerations != nil {
in, out := &in.WordpressTolerations, &out.WordpressTolerations
*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])
}
}
}
if in.WordpressVolumeSize != nil {
in, out := &in.WordpressVolumeSize, &out.WordpressVolumeSize
x := (*in).DeepCopy()
*out = &x
}
if in.WordpressServiceAnnotations != nil {
in, out := &in.WordpressServiceAnnotations, &out.WordpressServiceAnnotations
*out = new(map[string]string)


+ 49
- 7
pkg/controller/wordpress/manifests.go View File

@@ -2,9 +2,9 @@ package wordpress

import (
blindagev1alpha1 "git.blindage.org/21h/wordpress-operator/pkg/apis/blindage/v1alpha1"

v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
resource "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
@@ -150,28 +150,58 @@ func generateWordpressDeployment(cr *blindagev1alpha1.Wordpress) v1.Deployment {
},
}

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

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

return deployment
}

func generateWordpressContentVolume(cr *blindagev1alpha1.Wordpress) corev1.PersistentVolumeClaim {
return corev1.PersistentVolumeClaim{
volumeSize, _ := resource.ParseQuantity("1Gi")
if cr.Spec.WordpressVolumeSize != nil {
volumeSize = *cr.Spec.WordpressVolumeSize
}

claim := corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-content",
Namespace: cr.Namespace,
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
// allow read and write for many pods
// but if you using few pods on few nodes, block device can't replicate between nodes
// so you can set your own storage class with this ability, efs, s3 or something like this
// https://medium.com/asl19-developers/create-readwritemany-persistentvolumeclaims-on-your-kubernetes-cluster-3a8db51f98e3
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: cr.Spec.WordpressVolumeSize,
corev1.ResourceStorage: volumeSize,
},
},
},
}

// set your own storage class
if cr.Spec.WordpressStorageClass != "" {
claim.Spec.StorageClassName = &cr.Spec.WordpressStorageClass
}

return claim

}

func generateDatabaseVolume(cr *blindagev1alpha1.Wordpress) corev1.PersistentVolumeClaim {
return corev1.PersistentVolumeClaim{
volumeSize, _ := resource.ParseQuantity("1Gi")
if cr.Spec.DatabaseVolumeSize != nil {
volumeSize = *cr.Spec.DatabaseVolumeSize
}

claim := corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-database",
Namespace: cr.Namespace,
@@ -180,11 +210,13 @@ func generateDatabaseVolume(cr *blindagev1alpha1.Wordpress) corev1.PersistentVol
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: cr.Spec.WordpressVolumeSize,
corev1.ResourceStorage: volumeSize,
},
},
},
}

return claim
}

func generateConfigmap(cr *blindagev1alpha1.Wordpress) corev1.ConfigMap {
@@ -340,7 +372,7 @@ func generateDatabaseStatefulSet(cr *blindagev1alpha1.Wordpress) v1.StatefulSet
// wordpress operator is not mysql operator, so only one simple pod without replication and clustering
replicas := int32(1)

return v1.StatefulSet{
sts := v1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-database",
Namespace: cr.Namespace,
@@ -359,4 +391,14 @@ func generateDatabaseStatefulSet(cr *blindagev1alpha1.Wordpress) v1.StatefulSet
},
},
}

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

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

return sts
}

+ 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