diff --git a/.gitignore b/.gitignore index 10ad0bb..398df55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ config/manifests/bases/* -bundle/* bundle.Dockerfile # Binaries for programs and plugins diff --git a/api/v1alpha1/webserver_types.go b/api/v1alpha1/webserver_types.go index ebbe7c5..feca2cf 100644 --- a/api/v1alpha1/webserver_types.go +++ b/api/v1alpha1/webserver_types.go @@ -37,7 +37,7 @@ type WebServerSpec struct { // (Deployment method 2) Imagestream WebImageStream *WebImageStreamSpec `json:"webImageStream,omitempty"` // Configuration of the resources used by the WebServer, ie CPU and memory, use limits and requests - Resources *corev1.ResourceRequirements `json:"resources,omitempty"` + PodResources corev1.ResourceRequirements `json:"podResources,omitempty"` //If true operator will create a PVC to save the logs. PersistentLogs bool `json:"persistentLogs,omitempty"` //If true operator will log tomcat's access logs diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 4f877f5..75eba6f 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -220,11 +220,7 @@ func (in *WebServerSpec) DeepCopyInto(out *WebServerSpec) { *out = new(WebImageStreamSpec) (*in).DeepCopyInto(*out) } - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = new(v1.ResourceRequirements) - (*in).DeepCopyInto(*out) - } + in.PodResources.DeepCopyInto(&out.PodResources) if in.SecurityContext != nil { in, out := &in.SecurityContext, &out.SecurityContext *out = new(v1.SecurityContext) diff --git a/bundle/manifests/jws-operator.clusterserviceversion.yaml b/bundle/manifests/jws-operator.clusterserviceversion.yaml new file mode 100644 index 0000000..05b5279 --- /dev/null +++ b/bundle/manifests/jws-operator.clusterserviceversion.yaml @@ -0,0 +1,340 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: ClusterServiceVersion +metadata: + annotations: + alm-examples: '[]' + capabilities: Basic Install + operators.operatorframework.io/builder: operator-sdk-v1.25.3 + operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 + name: jws-operator.v0.0.1 + namespace: placeholder +spec: + apiservicedefinitions: {} + customresourcedefinitions: + owned: + - kind: WebServer + name: webservers.web.servers.org + version: v1alpha1 + specDescriptors: + - description: Pod resources + displayName: Pod Resources + path: podResources + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:resourceRequirements + description: jws-mm + displayName: jws-mm + icon: + - base64data: "" + mediatype: "" + install: + spec: + clusterPermissions: + - rules: + - apiGroups: + - apps + resources: + - deployments + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - apps + resources: + - deployments/finalizers + verbs: + - update + - apiGroups: + - apps + resources: + - jws-operator + verbs: + - update + - apiGroups: + - apps.openshift.io + resources: + - deploymentconfigs + verbs: + - create + - delete + - get + - list + - update + - watch + - apiGroups: + - build.openshift.io + resources: + - buildconfigs + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - build.openshift.io + resources: + - builds + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - "" + resources: + - namespaces + verbs: + - get + - apiGroups: + - "" + resources: + - persistentvolumeclaims + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - "" + resources: + - pods + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - "" + resources: + - services + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - "" + resources: + - services/finalizers + verbs: + - update + - apiGroups: + - image.openshift.io + resources: + - imagestreams + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - monitoring.coreos.com + resources: + - servicemonitors + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - rbac.authorization.k8s.io + resources: + - rolebindings + verbs: + - create + - get + - grant + - list + - watch + - apiGroups: + - route.openshift.io + resources: + - routes + verbs: + - create + - delete + - get + - list + - watch + - apiGroups: + - route.openshift.io + resources: + - routes/custom-host + verbs: + - create + - get + - apiGroups: + - web.servers.org + resources: + - webservers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - web.servers.org + resources: + - webservers/finalizers + verbs: + - update + - apiGroups: + - web.servers.org + resources: + - webservers/status + verbs: + - get + - patch + - update + - apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create + - apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create + serviceAccountName: jws-operator-controller-manager + deployments: + - label: + control-plane: controller-manager + name: jws-operator-controller-manager + spec: + replicas: 1 + selector: + matchLabels: + control-plane: controller-manager + strategy: {} + template: + metadata: + labels: + control-plane: controller-manager + spec: + containers: + - args: + - --secure-listen-address=0.0.0.0:8443 + - --upstream=http://127.0.0.1:8080/ + - --logtostderr=true + - --v=10 + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 + name: kube-rbac-proxy + ports: + - containerPort: 8443 + name: https + protocol: TCP + resources: {} + - args: + - --health-probe-bind-address=:8081 + - --metrics-bind-address=127.0.0.1:8080 + - --leader-elect + command: + - /manager + image: quay.io/mmadzin/jws-operator:latest + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + name: manager + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: + limits: + cpu: 200m + memory: 100Mi + requests: + cpu: 100m + memory: 20Mi + securityContext: + allowPrivilegeEscalation: false + securityContext: + runAsNonRoot: true + serviceAccountName: jws-operator-controller-manager + terminationGracePeriodSeconds: 10 + permissions: + - rules: + - apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - "" + resources: + - events + verbs: + - create + - patch + serviceAccountName: jws-operator-controller-manager + strategy: deployment + installModes: + - supported: false + type: OwnNamespace + - supported: false + type: SingleNamespace + - supported: false + type: MultiNamespace + - supported: true + type: AllNamespaces + keywords: + - jws + - mm + links: + - name: Jws Operator + url: https://jws-operator.domain + maturity: alpha + provider: + name: mm + version: 0.0.1 diff --git a/config/crd/bases/web.servers.org_webservers.yaml b/config/crd/bases/web.servers.org_webservers.yaml index d5bbbd8..a5f10cc 100644 --- a/config/crd/bases/web.servers.org_webservers.yaml +++ b/config/crd/bases/web.servers.org_webservers.yaml @@ -159,12 +159,7 @@ spec: persistentLogs: description: If true operator will create a PVC to save the logs. type: boolean - replicas: - description: The desired number of replicas for the application - format: int32 - minimum: 0 - type: integer - resources: + podResources: description: Configuration of the resources used by the WebServer, ie CPU and memory, use limits and requests properties: @@ -191,6 +186,11 @@ spec: to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' type: object type: object + replicas: + description: The desired number of replicas for the application + format: int32 + minimum: 0 + type: integer routeHostname: description: Route behaviour:[tls]hostname/NONE or empty. type: string diff --git a/controllers/templates.go b/controllers/templates.go index 3f6ca8e..f1aefff 100644 --- a/controllers/templates.go +++ b/controllers/templates.go @@ -749,7 +749,7 @@ func (r *WebServerReconciler) generatePodTemplate(webServer *webserversv1alpha1. ImagePullPolicy: "Always", ReadinessProbe: r.generateReadinessProbe(webServer, health), LivenessProbe: r.generateLivenessProbe(webServer, health), - Resources: generateResources(webServer.Spec.Resources), + Resources: webServer.Spec.PodResources, Ports: []corev1.ContainerPort{{ Name: "jolokia", ContainerPort: 8778, @@ -781,9 +781,7 @@ func (r *WebServerReconciler) generatePodTemplate(webServer *webserversv1alpha1. template.Spec.Containers[0].Args = append(template.Spec.Containers[0].Args, "-c", "/opt/start/start.sh") } // if the user specified the resources directive propagate it to the container (required for HPA). - if webServer.Spec.Resources != nil { - template.Spec.Containers[0].Resources = *webServer.Spec.Resources - } + template.Spec.Containers[0].Resources = webServer.Spec.PodResources return template } @@ -1280,26 +1278,6 @@ func (r *WebServerReconciler) generateLoggingProperties(webServer *webserversv1a return cmd } -// generateResources supplements a default ResourceRequirements and returns it. -func generateResources(r *corev1.ResourceRequirements) corev1.ResourceRequirements { - rTemplate := corev1.ResourceRequirements{ - Limits: nil, - Requests: nil, - } - - if r != nil { - if r.Limits != nil && len(r.Limits) > 0 { - rTemplate.Limits = r.Limits - } - - if r.Requests != nil && len(r.Requests) > 0 { - rTemplate.Requests = r.Requests - } - } - - return rTemplate -} - // generateSecurityContext supplements a default SecurityContext and returns it. func generateSecurityContext(s *corev1.SecurityContext) *corev1.SecurityContext { allowPrivilegeEscalation := new(bool) diff --git a/test/framework/common.go b/test/framework/common.go index 887cb74..222ebe3 100644 --- a/test/framework/common.go +++ b/test/framework/common.go @@ -465,7 +465,7 @@ func HPATest(clt client.Client, ctx context.Context, t *testing.T, namespace str WebImage: &webserversv1alpha1.WebImageSpec{ ApplicationImage: "quay.io/web-servers/tomcat-demo", }, - Resources: &corev1.ResourceRequirements{ + PodResources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("2Gi"),