From 0b90e9af4e252191d4bb3e8d11d3a0be9fa0d8f6 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Wed, 15 May 2024 14:41:42 +0200 Subject: [PATCH 01/13] [git] Ignoring the right path to the limitador-operator binary Signed-off-by: dd di cesare --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1797dba9..2980739b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ *.so *.dylib bin -limitador-operator +/limitador-operator # Test binary, build with `go test -c` *.test From 0fe0fd990014a1993edaf0beedcb689f148b0295 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Wed, 15 May 2024 14:42:23 +0200 Subject: [PATCH 02/13] [helm] Initial limitador-operator chart metadata Signed-off-by: dd di cesare --- charts/limitador-operator/.helmignore | 23 +++++++++++++++++++++++ charts/limitador-operator/Chart.yaml | 13 +++++++++++++ charts/limitador-operator/values.yaml | 0 3 files changed, 36 insertions(+) create mode 100644 charts/limitador-operator/.helmignore create mode 100644 charts/limitador-operator/Chart.yaml create mode 100644 charts/limitador-operator/values.yaml diff --git a/charts/limitador-operator/.helmignore b/charts/limitador-operator/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/limitador-operator/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/limitador-operator/Chart.yaml b/charts/limitador-operator/Chart.yaml new file mode 100644 index 00000000..b09a56b7 --- /dev/null +++ b/charts/limitador-operator/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: limitador-operator +description: A Helm chart for Limitador Operator +type: application +version: "0.1.0-dev" +appVersion: "latest" +maintainers: + - email: asnaps@redhat.com + name: Alex Snaps + - email: didier@redhat.com + name: Didier Di Cesare + - email: eastizle@redhat.com + name: Eguzki Astiz Lezaun diff --git a/charts/limitador-operator/values.yaml b/charts/limitador-operator/values.yaml new file mode 100644 index 00000000..e69de29b From 362f9e872024eff334b6b7091d16d8220a32d840 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Thu, 16 May 2024 16:26:20 +0200 Subject: [PATCH 03/13] [make] Adding `helm` target * Installs helm binary Signed-off-by: dd di cesare --- Makefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Makefile b/Makefile index c8a9b2a0..59b97c41 100644 --- a/Makefile +++ b/Makefile @@ -186,6 +186,23 @@ $(GINKGO): .PHONY: ginkgo ginkgo: $(GINKGO) ## Download ginkgo locally if necessary. +HELM = $(PROJECT_PATH)/bin/helm +HELM_VERSION = v3.15.0 +$(HELM): + @{ \ + set -e ;\ + mkdir -p $(dir $(HELM)) ;\ + OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ + wget -O helm.tar.gz https://get.helm.sh/helm-$(HELM_VERSION)-$${OS}-$${ARCH}.tar.gz ;\ + tar -zxvf helm.tar.gz ;\ + mv $${OS}-$${ARCH}/helm $(HELM) ;\ + chmod +x $(HELM) ;\ + rm -rf $${OS}-$${ARCH} helm.tar.gz ;\ + } + +.PHONY: helm +helm: $(HELM) ## Download helm locally if necessary. + ##@ General # The help target prints out all targets with their descriptions organized From ac5748f590e9cfdfcaa305223eb9a5487f98364a Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Fri, 17 May 2024 12:23:35 +0200 Subject: [PATCH 04/13] [make] Building helm chart templates (manifests) Signed-off-by: dd di cesare --- config/helm/kustomization.yaml | 2 ++ make/helm.mk | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 config/helm/kustomization.yaml create mode 100644 make/helm.mk diff --git a/config/helm/kustomization.yaml b/config/helm/kustomization.yaml new file mode 100644 index 00000000..ecbcca00 --- /dev/null +++ b/config/helm/kustomization.yaml @@ -0,0 +1,2 @@ +resources: +- ../default diff --git a/make/helm.mk b/make/helm.mk new file mode 100644 index 00000000..8c9b7a3a --- /dev/null +++ b/make/helm.mk @@ -0,0 +1,12 @@ +##@ Helm Charts + +.PHONY: helm-build +helm-build: ## Builds the helm chart from kustomize manifests + # Generate kustomize manifests out of code notations + $(OPERATOR_SDK) generate kustomize manifests -q + # Set desired operator image and related limitador image + V="$(RELATED_IMAGE_LIMITADOR)" $(YQ) eval '(select(.kind == "Deployment").spec.template.spec.containers[].env[] | select(.name == "RELATED_IMAGE_LIMITADOR").value) = strenv(V)' -i config/manager/manager.yaml + # Replace the controller image + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) + # Build the helm chart templates from kustomize manifests + $(KUSTOMIZE) build config/helm > charts/limitador-operator/templates/manifests.yaml From 9f6e16f5b6a9726e8637fd02846d9c31d4298cc0 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Fri, 17 May 2024 12:24:27 +0200 Subject: [PATCH 05/13] [helm] Default templates/manifests using `latest` tag Signed-off-by: dd di cesare --- .../templates/manifests.yaml | 1438 +++++++++++++++++ 1 file changed, 1438 insertions(+) create mode 100644 charts/limitador-operator/templates/manifests.yaml diff --git a/charts/limitador-operator/templates/manifests.yaml b/charts/limitador-operator/templates/manifests.yaml new file mode 100644 index 00000000..57839c31 --- /dev/null +++ b/charts/limitador-operator/templates/manifests.yaml @@ -0,0 +1,1438 @@ +apiVersion: v1 +kind: Namespace +metadata: + labels: + control-plane: controller-manager + name: limitador-operator-system +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + name: limitadors.limitador.kuadrant.io +spec: + group: limitador.kuadrant.io + names: + kind: Limitador + listKind: LimitadorList + plural: limitadors + singular: limitador + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: Limitador is the Schema for the limitadors API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: LimitadorSpec defines the desired state of Limitador + properties: + affinity: + description: Affinity is a group of affinity scheduling rules. + properties: + nodeAffinity: + description: Describes node affinity scheduling rules for the + pod. + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: The scheduler will prefer to schedule pods to + nodes that satisfy the affinity expressions specified by + this field, but it may choose a node that violates one or + more of the expressions. The node that is most preferred + is the one with the greatest sum of weights, i.e. for each + node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling affinity expressions, + etc.), compute a sum by iterating through the elements of + this field and adding "weight" to the sum if the node matches + the corresponding matchExpressions; the node(s) with the + highest sum are the most preferred. + items: + description: An empty preferred scheduling term matches + all objects with implicit weight 0 (i.e. it's a no-op). + A null preferred scheduling term matches no objects (i.e. + is also a no-op). + properties: + preference: + description: A node selector term, associated with the + corresponding weight. + properties: + matchExpressions: + description: A list of node selector requirements + by node's labels. + items: + description: A node selector requirement is a + selector that contains values, a key, and an + operator that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: Represents a key's relationship + to a set of values. Valid operators are + In, NotIn, Exists, DoesNotExist. Gt, and + Lt. + type: string + values: + description: An array of string values. If + the operator is In or NotIn, the values + array must be non-empty. If the operator + is Exists or DoesNotExist, the values array + must be empty. If the operator is Gt or + Lt, the values array must have a single + element, which will be interpreted as an + integer. This array is replaced during a + strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchFields: + description: A list of node selector requirements + by node's fields. + items: + description: A node selector requirement is a + selector that contains values, a key, and an + operator that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: Represents a key's relationship + to a set of values. Valid operators are + In, NotIn, Exists, DoesNotExist. Gt, and + Lt. + type: string + values: + description: An array of string values. If + the operator is In or NotIn, the values + array must be non-empty. If the operator + is Exists or DoesNotExist, the values array + must be empty. If the operator is Gt or + Lt, the values array must have a single + element, which will be interpreted as an + integer. This array is replaced during a + strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + type: object + x-kubernetes-map-type: atomic + weight: + description: Weight associated with matching the corresponding + nodeSelectorTerm, in the range 1-100. + format: int32 + type: integer + required: + - preference + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + description: If the affinity requirements specified by this + field are not met at scheduling time, the pod will not be + scheduled onto the node. If the affinity requirements specified + by this field cease to be met at some point during pod execution + (e.g. due to an update), the system may or may not try to + eventually evict the pod from its node. + properties: + nodeSelectorTerms: + description: Required. A list of node selector terms. + The terms are ORed. + items: + description: A null or empty node selector term matches + no objects. The requirements of them are ANDed. The + TopologySelectorTerm type implements a subset of the + NodeSelectorTerm. + properties: + matchExpressions: + description: A list of node selector requirements + by node's labels. + items: + description: A node selector requirement is a + selector that contains values, a key, and an + operator that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: Represents a key's relationship + to a set of values. Valid operators are + In, NotIn, Exists, DoesNotExist. Gt, and + Lt. + type: string + values: + description: An array of string values. If + the operator is In or NotIn, the values + array must be non-empty. If the operator + is Exists or DoesNotExist, the values array + must be empty. If the operator is Gt or + Lt, the values array must have a single + element, which will be interpreted as an + integer. This array is replaced during a + strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchFields: + description: A list of node selector requirements + by node's fields. + items: + description: A node selector requirement is a + selector that contains values, a key, and an + operator that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: Represents a key's relationship + to a set of values. Valid operators are + In, NotIn, Exists, DoesNotExist. Gt, and + Lt. + type: string + values: + description: An array of string values. If + the operator is In or NotIn, the values + array must be non-empty. If the operator + is Exists or DoesNotExist, the values array + must be empty. If the operator is Gt or + Lt, the values array must have a single + element, which will be interpreted as an + integer. This array is replaced during a + strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + type: object + x-kubernetes-map-type: atomic + type: array + required: + - nodeSelectorTerms + type: object + x-kubernetes-map-type: atomic + type: object + podAffinity: + description: Describes pod affinity scheduling rules (e.g. co-locate + this pod in the same node, zone, etc. as some other pod(s)). + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: The scheduler will prefer to schedule pods to + nodes that satisfy the affinity expressions specified by + this field, but it may choose a node that violates one or + more of the expressions. The node that is most preferred + is the one with the greatest sum of weights, i.e. for each + node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling affinity expressions, + etc.), compute a sum by iterating through the elements of + this field and adding "weight" to the sum if the node has + pods which matches the corresponding podAffinityTerm; the + node(s) with the highest sum are the most preferred. + items: + description: The weights of all of the matched WeightedPodAffinityTerm + fields are added per-node to find the most preferred node(s) + properties: + podAffinityTerm: + description: Required. A pod affinity term, associated + with the corresponding weight. + properties: + labelSelector: + description: A label query over a set of resources, + in this case pods. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: A label selector requirement + is a selector that contains values, a key, + and an operator that relates the key and + values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: operator represents a key's + relationship to a set of values. Valid + operators are In, NotIn, Exists and + DoesNotExist. + type: string + values: + description: values is an array of string + values. If the operator is In or NotIn, + the values array must be non-empty. + If the operator is Exists or DoesNotExist, + the values array must be empty. This + array is replaced during a strategic + merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} + pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, + whose key field is "key", the operator is + "In", and the values array contains only "value". + The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaceSelector: + description: A label query over the set of namespaces + that the term applies to. The term is applied + to the union of the namespaces selected by this + field and the ones listed in the namespaces field. + null selector and null or empty namespaces list + means "this pod's namespace". An empty selector + ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: A label selector requirement + is a selector that contains values, a key, + and an operator that relates the key and + values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: operator represents a key's + relationship to a set of values. Valid + operators are In, NotIn, Exists and + DoesNotExist. + type: string + values: + description: values is an array of string + values. If the operator is In or NotIn, + the values array must be non-empty. + If the operator is Exists or DoesNotExist, + the values array must be empty. This + array is replaced during a strategic + merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} + pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, + whose key field is "key", the operator is + "In", and the values array contains only "value". + The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: namespaces specifies a static list + of namespace names that the term applies to. The + term is applied to the union of the namespaces + listed in this field and the ones selected by + namespaceSelector. null or empty namespaces list + and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + topologyKey: + description: This pod should be co-located (affinity) + or not co-located (anti-affinity) with the pods + matching the labelSelector in the specified namespaces, + where co-located is defined as running on a node + whose value of the label with key topologyKey + matches that of any node on which any of the selected + pods is running. Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + weight: + description: weight associated with matching the corresponding + podAffinityTerm, in the range 1-100. + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + description: If the affinity requirements specified by this + field are not met at scheduling time, the pod will not be + scheduled onto the node. If the affinity requirements specified + by this field cease to be met at some point during pod execution + (e.g. due to a pod label update), the system may or may + not try to eventually evict the pod from its node. When + there are multiple elements, the lists of nodes corresponding + to each podAffinityTerm are intersected, i.e. all terms + must be satisfied. + items: + description: Defines a set of pods (namely those matching + the labelSelector relative to the given namespace(s)) + that this pod should be co-located (affinity) or not co-located + (anti-affinity) with, where co-located is defined as running + on a node whose value of the label with key + matches that of any node on which a pod of the set of + pods is running + properties: + labelSelector: + description: A label query over a set of resources, + in this case pods. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a + selector that contains values, a key, and an + operator that relates the key and values. + properties: + key: + description: key is the label key that the + selector applies to. + type: string + operator: + description: operator represents a key's relationship + to a set of values. Valid operators are + In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string + values. If the operator is In or NotIn, + the values array must be non-empty. If the + operator is Exists or DoesNotExist, the + values array must be empty. This array is + replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} + pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, + whose key field is "key", the operator is "In", + and the values array contains only "value". The + requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaceSelector: + description: A label query over the set of namespaces + that the term applies to. The term is applied to the + union of the namespaces selected by this field and + the ones listed in the namespaces field. null selector + and null or empty namespaces list means "this pod's + namespace". An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a + selector that contains values, a key, and an + operator that relates the key and values. + properties: + key: + description: key is the label key that the + selector applies to. + type: string + operator: + description: operator represents a key's relationship + to a set of values. Valid operators are + In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string + values. If the operator is In or NotIn, + the values array must be non-empty. If the + operator is Exists or DoesNotExist, the + values array must be empty. This array is + replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} + pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, + whose key field is "key", the operator is "In", + and the values array contains only "value". The + requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: namespaces specifies a static list of namespace + names that the term applies to. The term is applied + to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. null or + empty namespaces list and null namespaceSelector means + "this pod's namespace". + items: + type: string + type: array + topologyKey: + description: This pod should be co-located (affinity) + or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where + co-located is defined as running on a node whose value + of the label with key topologyKey matches that of + any node on which any of the selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + type: array + type: object + podAntiAffinity: + description: Describes pod anti-affinity scheduling rules (e.g. + avoid putting this pod in the same node, zone, etc. as some + other pod(s)). + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: The scheduler will prefer to schedule pods to + nodes that satisfy the anti-affinity expressions specified + by this field, but it may choose a node that violates one + or more of the expressions. The node that is most preferred + is the one with the greatest sum of weights, i.e. for each + node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling anti-affinity expressions, + etc.), compute a sum by iterating through the elements of + this field and adding "weight" to the sum if the node has + pods which matches the corresponding podAffinityTerm; the + node(s) with the highest sum are the most preferred. + items: + description: The weights of all of the matched WeightedPodAffinityTerm + fields are added per-node to find the most preferred node(s) + properties: + podAffinityTerm: + description: Required. A pod affinity term, associated + with the corresponding weight. + properties: + labelSelector: + description: A label query over a set of resources, + in this case pods. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: A label selector requirement + is a selector that contains values, a key, + and an operator that relates the key and + values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: operator represents a key's + relationship to a set of values. Valid + operators are In, NotIn, Exists and + DoesNotExist. + type: string + values: + description: values is an array of string + values. If the operator is In or NotIn, + the values array must be non-empty. + If the operator is Exists or DoesNotExist, + the values array must be empty. This + array is replaced during a strategic + merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} + pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, + whose key field is "key", the operator is + "In", and the values array contains only "value". + The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaceSelector: + description: A label query over the set of namespaces + that the term applies to. The term is applied + to the union of the namespaces selected by this + field and the ones listed in the namespaces field. + null selector and null or empty namespaces list + means "this pod's namespace". An empty selector + ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: A label selector requirement + is a selector that contains values, a key, + and an operator that relates the key and + values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: operator represents a key's + relationship to a set of values. Valid + operators are In, NotIn, Exists and + DoesNotExist. + type: string + values: + description: values is an array of string + values. If the operator is In or NotIn, + the values array must be non-empty. + If the operator is Exists or DoesNotExist, + the values array must be empty. This + array is replaced during a strategic + merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} + pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, + whose key field is "key", the operator is + "In", and the values array contains only "value". + The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: namespaces specifies a static list + of namespace names that the term applies to. The + term is applied to the union of the namespaces + listed in this field and the ones selected by + namespaceSelector. null or empty namespaces list + and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + topologyKey: + description: This pod should be co-located (affinity) + or not co-located (anti-affinity) with the pods + matching the labelSelector in the specified namespaces, + where co-located is defined as running on a node + whose value of the label with key topologyKey + matches that of any node on which any of the selected + pods is running. Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + weight: + description: weight associated with matching the corresponding + podAffinityTerm, in the range 1-100. + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + requiredDuringSchedulingIgnoredDuringExecution: + description: If the anti-affinity requirements specified by + this field are not met at scheduling time, the pod will + not be scheduled onto the node. If the anti-affinity requirements + specified by this field cease to be met at some point during + pod execution (e.g. due to a pod label update), the system + may or may not try to eventually evict the pod from its + node. When there are multiple elements, the lists of nodes + corresponding to each podAffinityTerm are intersected, i.e. + all terms must be satisfied. + items: + description: Defines a set of pods (namely those matching + the labelSelector relative to the given namespace(s)) + that this pod should be co-located (affinity) or not co-located + (anti-affinity) with, where co-located is defined as running + on a node whose value of the label with key + matches that of any node on which a pod of the set of + pods is running + properties: + labelSelector: + description: A label query over a set of resources, + in this case pods. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a + selector that contains values, a key, and an + operator that relates the key and values. + properties: + key: + description: key is the label key that the + selector applies to. + type: string + operator: + description: operator represents a key's relationship + to a set of values. Valid operators are + In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string + values. If the operator is In or NotIn, + the values array must be non-empty. If the + operator is Exists or DoesNotExist, the + values array must be empty. This array is + replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} + pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, + whose key field is "key", the operator is "In", + and the values array contains only "value". The + requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaceSelector: + description: A label query over the set of namespaces + that the term applies to. The term is applied to the + union of the namespaces selected by this field and + the ones listed in the namespaces field. null selector + and null or empty namespaces list means "this pod's + namespace". An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are ANDed. + items: + description: A label selector requirement is a + selector that contains values, a key, and an + operator that relates the key and values. + properties: + key: + description: key is the label key that the + selector applies to. + type: string + operator: + description: operator represents a key's relationship + to a set of values. Valid operators are + In, NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string + values. If the operator is In or NotIn, + the values array must be non-empty. If the + operator is Exists or DoesNotExist, the + values array must be empty. This array is + replaced during a strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} + pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, + whose key field is "key", the operator is "In", + and the values array contains only "value". The + requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: namespaces specifies a static list of namespace + names that the term applies to. The term is applied + to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. null or + empty namespaces list and null namespaceSelector means + "this pod's namespace". + items: + type: string + type: array + topologyKey: + description: This pod should be co-located (affinity) + or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where + co-located is defined as running on a node whose value + of the label with key topologyKey matches that of + any node on which any of the selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + type: array + type: object + type: object + image: + type: string + limits: + items: + description: RateLimit defines the desired Limitador limit + properties: + conditions: + items: + type: string + type: array + max_value: + type: integer + name: + type: string + namespace: + type: string + seconds: + type: integer + variables: + items: + type: string + type: array + required: + - conditions + - max_value + - namespace + - seconds + - variables + type: object + type: array + listener: + properties: + grpc: + properties: + port: + format: int32 + type: integer + type: object + http: + properties: + port: + format: int32 + type: integer + type: object + type: object + pdb: + properties: + maxUnavailable: + anyOf: + - type: integer + - type: string + description: An eviction is allowed if at most "maxUnavailable" + limitador pods are unavailable after the eviction, i.e. even + in absence of the evicted pod. For example, one can prevent + all voluntary evictions by specifying 0. This is a mutually + exclusive setting with "minAvailable". + x-kubernetes-int-or-string: true + minAvailable: + anyOf: + - type: integer + - type: string + description: An eviction is allowed if at least "minAvailable" + limitador pods will still be available after the eviction, i.e. + even in the absence of the evicted pod. So for example you + can prevent all voluntary evictions by specifying "100%". + x-kubernetes-int-or-string: true + type: object + rateLimitHeaders: + description: RateLimitHeadersType defines the valid options for the + --rate-limit-headers arg + enum: + - NONE + - DRAFT_VERSION_03 + type: string + replicas: + type: integer + resourceRequirements: + description: ResourceRequirements describes the compute resource requirements. + properties: + claims: + description: "Claims lists the names of resources, defined in + spec.resourceClaims, that are used by this container. \n This + is an alpha field and requires enabling the DynamicResourceAllocation + feature gate. \n This field is immutable. It can only be set + for containers." + items: + description: ResourceClaim references one entry in PodSpec.ResourceClaims. + properties: + name: + description: Name must match the name of one entry in pod.spec.resourceClaims + of the Pod where this field is used. It makes that resource + available inside a container. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'Limits describes the maximum amount of compute resources + allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'Requests describes the minimum amount of compute + resources required. If Requests is omitted for a container, + it defaults to Limits if that is explicitly specified, otherwise + to an implementation-defined value. Requests cannot exceed Limits. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + storage: + description: Storage contains the options for Limitador counters database + or in-memory data storage + properties: + disk: + properties: + optimize: + description: DiskOptimizeType defines the valid options for + "optimize" option of the disk persistence type + enum: + - throughput + - disk + type: string + persistentVolumeClaim: + properties: + resources: + description: Resources represents the minimum resources + the volume should have. Ignored when VolumeName field + is set + properties: + requests: + anyOf: + - type: integer + - type: string + description: 'Storage Resource requests to be used + on the PersistentVolumeClaim. To learn more about + resource requests see: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + required: + - requests + type: object + storageClassName: + type: string + volumeName: + description: VolumeName is the binding reference to the + PersistentVolume backing this claim. + type: string + type: object + type: object + redis: + properties: + configSecretRef: + description: LocalObjectReference contains enough information + to let you locate the referenced object inside the same + namespace. + properties: + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + type: object + x-kubernetes-map-type: atomic + type: object + redis-cached: + properties: + configSecretRef: + description: LocalObjectReference contains enough information + to let you locate the referenced object inside the same + namespace. + properties: + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + type: object + x-kubernetes-map-type: atomic + options: + properties: + flush-period: + description: 'FlushPeriod for counters in milliseconds + [default: 1000]' + type: integer + max-cached: + description: 'MaxCached refers to the maximum amount of + counters cached [default: 10000]' + type: integer + response-timeout: + description: 'ResponseTimeout defines the timeout for + Redis commands in milliseconds [default: 350]' + type: integer + type: object + type: object + type: object + telemetry: + description: Telemetry defines the level of metrics Limitador will + expose to the user + enum: + - basic + - exhaustive + type: string + tracing: + properties: + endpoint: + type: string + required: + - endpoint + type: object + verbosity: + description: Sets the level of verbosity + maximum: 4 + minimum: 1 + type: integer + version: + description: '[Deprecated] Use spec.image instead. Docker tag used + as limitador image. The repo is hardcoded to quay.io/kuadrant/limitador' + type: string + type: object + x-kubernetes-validations: + - message: disk storage does not allow multiple replicas + rule: (!has(self.storage) || !has(self.storage.disk)) || (!has(self.replicas) + || self.replicas < 2) + status: + description: LimitadorStatus defines the observed state of Limitador + properties: + conditions: + description: 'Represents the observations of a foo''s current state. + Known .status.conditions.type are: "Ready"' + items: + description: "Condition contains details for one aspect of the current + state of this API Resource. --- This struct is intended for direct + use as an array at the field path .status.conditions. For example, + \n type FooStatus struct{ // Represents the observations of a + foo's current state. // Known .status.conditions.type are: \"Available\", + \"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge + // +listType=map // +listMapKey=type Conditions []metav1.Condition + `json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\" + protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }" + properties: + lastTransitionTime: + description: lastTransitionTime is the last time the condition + transitioned from one status to another. This should be when + the underlying condition changed. If that is not known, then + using the time when the API field changed is acceptable. + format: date-time + type: string + message: + description: message is a human readable message indicating + details about the transition. This may be an empty string. + maxLength: 32768 + type: string + observedGeneration: + description: observedGeneration represents the .metadata.generation + that the condition was set based upon. For instance, if .metadata.generation + is currently 12, but the .status.conditions[x].observedGeneration + is 9, the condition is out of date with respect to the current + state of the instance. + format: int64 + minimum: 0 + type: integer + reason: + description: reason contains a programmatic identifier indicating + the reason for the condition's last transition. Producers + of specific condition types may define expected values and + meanings for this field, and whether the values are considered + a guaranteed API. The value should be a CamelCase string. + This field may not be empty. + maxLength: 1024 + minLength: 1 + pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ + type: string + status: + description: status of the condition, one of True, False, Unknown. + enum: + - "True" + - "False" + - Unknown + type: string + type: + description: type of condition in CamelCase or in foo.example.com/CamelCase. + --- Many .condition.type values are consistent across resources + like Available, but because arbitrary conditions can be useful + (see .node.status.conditions), the ability to deconflict is + important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) + maxLength: 316 + pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + type: array + x-kubernetes-list-map-keys: + - type + x-kubernetes-list-type: map + observedGeneration: + description: ObservedGeneration reflects the generation of the most + recently observed spec. + format: int64 + type: integer + service: + description: Service provides information about the service exposing + limitador API + properties: + host: + type: string + ports: + properties: + grpc: + format: int32 + type: integer + http: + format: int32 + type: integer + type: object + type: object + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: limitador-operator-controller-manager + namespace: limitador-operator-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: limitador-operator-leader-election-role + namespace: limitador-operator-system +rules: +- apiGroups: + - "" + - coordination.k8s.io + resources: + - configmaps + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + creationTimestamp: null + name: limitador-operator-manager-role +rules: +- apiGroups: + - "" + resources: + - configmaps + - persistentvolumeclaims + - secrets + - services + verbs: + - create + - delete + - get + - list + - update + - watch +- apiGroups: + - "" + resources: + - pods + verbs: + - list + - update + - watch +- apiGroups: + - apps + resources: + - deployments + verbs: + - create + - delete + - get + - list + - update + - watch +- apiGroups: + - limitador.kuadrant.io + resources: + - limitadors + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - limitador.kuadrant.io + resources: + - limitadors/finalizers + verbs: + - update +- apiGroups: + - limitador.kuadrant.io + resources: + - limitadors/status + verbs: + - get + - patch + - update +- apiGroups: + - policy + resources: + - poddisruptionbudgets + verbs: + - create + - delete + - get + - list + - update + - watch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: limitador-operator-leader-election-rolebinding + namespace: limitador-operator-system +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: limitador-operator-leader-election-role +subjects: +- kind: ServiceAccount + name: limitador-operator-controller-manager + namespace: limitador-operator-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: limitador-operator-manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: limitador-operator-manager-role +subjects: +- kind: ServiceAccount + name: limitador-operator-controller-manager + namespace: limitador-operator-system +--- +apiVersion: v1 +data: + controller_manager_config.yaml: | + apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 + kind: ControllerManagerConfig + health: + healthProbeBindAddress: :8081 + metrics: + bindAddress: :8080 + webhook: + port: 9443 + leaderElection: + leaderElect: true + resourceName: 3745a16e.kuadrant.io +kind: ConfigMap +metadata: + name: limitador-operator-manager-config + namespace: limitador-operator-system +--- +apiVersion: v1 +kind: Service +metadata: + labels: + control-plane: controller-manager + name: limitador-operator-controller-manager-metrics-service + namespace: limitador-operator-system +spec: + ports: + - name: metrics + port: 8080 + targetPort: metrics + selector: + control-plane: controller-manager +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + control-plane: controller-manager + name: limitador-operator-controller-manager + namespace: limitador-operator-system +spec: + replicas: 1 + selector: + matchLabels: + control-plane: controller-manager + template: + metadata: + labels: + control-plane: controller-manager + spec: + containers: + - args: + - --leader-elect + command: + - /manager + env: + - name: RELATED_IMAGE_LIMITADOR + value: quay.io/kuadrant/limitador:latest + image: quay.io/kuadrant/limitador-operator:latest + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + name: manager + ports: + - containerPort: 8080 + name: metrics + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: + limits: + cpu: 200m + memory: 300Mi + requests: + cpu: 200m + memory: 200Mi + securityContext: + allowPrivilegeEscalation: false + securityContext: + runAsNonRoot: true + serviceAccountName: limitador-operator-controller-manager + terminationGracePeriodSeconds: 10 From dd2da76372e2f3c27b868db51edcb6f647bbab04 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Fri, 17 May 2024 14:28:13 +0200 Subject: [PATCH 06/13] [make] Adding install, uninstall and upgrade targets Signed-off-by: dd di cesare --- make/helm.mk | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/make/helm.mk b/make/helm.mk index 8c9b7a3a..4c5f11d9 100644 --- a/make/helm.mk +++ b/make/helm.mk @@ -1,7 +1,7 @@ ##@ Helm Charts .PHONY: helm-build -helm-build: ## Builds the helm chart from kustomize manifests +helm-build: ## Build the helm chart from kustomize manifests # Generate kustomize manifests out of code notations $(OPERATOR_SDK) generate kustomize manifests -q # Set desired operator image and related limitador image @@ -10,3 +10,18 @@ helm-build: ## Builds the helm chart from kustomize manifests cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) # Build the helm chart templates from kustomize manifests $(KUSTOMIZE) build config/helm > charts/limitador-operator/templates/manifests.yaml + +.PHONY: helm-install +helm-install: $(HELM) ## Install the helm chart + # Install the helm chart in the cluster + $(HELM) install limitador-operator charts/limitador-operator + +.PHONY: helm-uninstall +helm-uninstall: $(HELM) ## Uninstall the helm chart + # Uninstall the helm chart from the cluster + $(HELM) uninstall limitador-operator + +.PHONY: helm-upgrade +helm-upgrade: $(HELM) ## Upgrade the helm chart + # Upgrade the helm chart in the cluster + $(HELM) upgrade limitador-operator charts/limitador-operator From 068724aedcf354dad917d0e5247ee67b2e6d1d5e Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Wed, 22 May 2024 15:27:39 +0200 Subject: [PATCH 07/13] [helm] Default versions for main branch Signed-off-by: dd di cesare --- charts/limitador-operator/Chart.yaml | 4 ++-- charts/limitador-operator/templates/manifests.yaml | 4 ++++ charts/limitador-operator/values.yaml | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/charts/limitador-operator/Chart.yaml b/charts/limitador-operator/Chart.yaml index b09a56b7..3d114ab2 100644 --- a/charts/limitador-operator/Chart.yaml +++ b/charts/limitador-operator/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: limitador-operator description: A Helm chart for Limitador Operator type: application -version: "0.1.0-dev" -appVersion: "latest" +# The version will be properly set when the chart is released matching the operator version +version: "0.0.0" maintainers: - email: asnaps@redhat.com name: Alex Snaps diff --git a/charts/limitador-operator/templates/manifests.yaml b/charts/limitador-operator/templates/manifests.yaml index 57839c31..4fac3740 100644 --- a/charts/limitador-operator/templates/manifests.yaml +++ b/charts/limitador-operator/templates/manifests.yaml @@ -1062,6 +1062,10 @@ spec: x-kubernetes-map-type: atomic options: properties: + batch-size: + description: 'BatchSize defines the size of entries to + flush in as single flush [default: 100]' + type: integer flush-period: description: 'FlushPeriod for counters in milliseconds [default: 1000]' diff --git a/charts/limitador-operator/values.yaml b/charts/limitador-operator/values.yaml index e69de29b..b230d9b7 100644 --- a/charts/limitador-operator/values.yaml +++ b/charts/limitador-operator/values.yaml @@ -0,0 +1 @@ +# For its first iteration, this chart won't be configurable with helm settings From e070b383c0a820497ae31da2b8b9e299ee35d341 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Wed, 29 May 2024 21:24:07 +0200 Subject: [PATCH 08/13] [make] Packaging, uploading and sync Signed-off-by: dd di cesare --- Makefile | 1 + make/helm.mk | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 59b97c41..e6861fcc 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ REGISTRY = quay.io # Organization in container resgistry ORG ?= kuadrant +REPO_NAME ?= limitador-operator # kubebuilder-tools still doesn't support darwin/arm64. This is a workaround (https://github.com/kubernetes-sigs/controller-runtime/issues/1657) ARCH_PARAM = diff --git a/make/helm.mk b/make/helm.mk index 4c5f11d9..81b63ee4 100644 --- a/make/helm.mk +++ b/make/helm.mk @@ -1,9 +1,7 @@ ##@ Helm Charts .PHONY: helm-build -helm-build: ## Build the helm chart from kustomize manifests - # Generate kustomize manifests out of code notations - $(OPERATOR_SDK) generate kustomize manifests -q +helm-build: $(KUSTOMIZE) $(OPERATOR_SDK) $(YQ) manifests ## Build the helm chart from kustomize manifests # Set desired operator image and related limitador image V="$(RELATED_IMAGE_LIMITADOR)" $(YQ) eval '(select(.kind == "Deployment").spec.template.spec.containers[].env[] | select(.name == "RELATED_IMAGE_LIMITADOR").value) = strenv(V)' -i config/manager/manager.yaml # Replace the controller image @@ -25,3 +23,43 @@ helm-uninstall: $(HELM) ## Uninstall the helm chart helm-upgrade: $(HELM) ## Upgrade the helm chart # Upgrade the helm chart in the cluster $(HELM) upgrade limitador-operator charts/limitador-operator + +.PHONY: helm-package +helm-package: $(HELM) ## Package the helm chart + # Package the helm chart + $(HELM) package charts/limitador-operator + +# GitHub Token with permissions to upload to the release assets +GITHUB_TOKEN ?= +# GitHub Release ID, to find the release_id query the GET /repos/{owner}/{repo}/releases/latest or GET /repos/{owner}/{repo}/releases endpoints +RELEASE_ID ?= +# GitHub Release Asset ID, it can be find in the output of the uploaded asset +ASSET_ID ?= +# GitHub Release Asset Browser Download URL, it can be find in the output of the uploaded asset +BROWSER_DOWNLOAD_URL ?= +ifeq (0.0.0,$(VERSION)) +CHART_VERSION = $(VERSION)-dev +else +CHART_VERSION = $(VERSION) +endif + +.PHONY: helm-upload-package +helm-upload-package: $(HELM) ## Upload the helm chart package to the GitHub release assets + curl -L -s \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $(GITHUB_TOKEN)" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/octet-stream" \ + "https://uploads.github.com/repos/$(ORG)/$(REPO_NAME)/releases/$(RELEASE_ID)/assets?name=chart-limitador-operator-$(CHART_VERSION).tgz" \ + --data-binary "@limitador-operator-$(CHART_VERSION).tgz" + +.PHONY: helm-sync-package +helm-sync-package: $(HELM) ## Sync the helm chart package to the helm-charts repo + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $(GITHUB_TOKEN)" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/$(ORG)/$(REPO_NAME)/dispatches \ + -d '{"event_type":"sync-chart","client_payload":{"chart":limitador-operator,"version":"$(CHART_VERSION)", "asset_id":"$(ASSET_ID)", "browser_download_url": "$(BROWSER_DOWNLOAD_URL)"}}' From cc8b65a0353c1f79d384662e84914f0c9865d31d Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Wed, 29 May 2024 21:24:42 +0200 Subject: [PATCH 09/13] [workflow] Release workflow Signed-off-by: dd di cesare --- .github/workflows/release-helm-chart.yaml | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/release-helm-chart.yaml diff --git a/.github/workflows/release-helm-chart.yaml b/.github/workflows/release-helm-chart.yaml new file mode 100644 index 00000000..594ce7fa --- /dev/null +++ b/.github/workflows/release-helm-chart.yaml @@ -0,0 +1,68 @@ +name: release-helm-chart +on: +# TODO: The following commented lines should be used depending on the release strategy +# release: +# types: +# - released +# OR for a full release workflow +# push: +# tags: +# - 'v*.*.*' + workflow_dispatch: + inputs: + operatorVersion: + description: Operator bundle version + default: 0.0.0 + type: string + limitadorVersion: + description: Limitador version + default: latest + type: string + releaseId: + description: Release ID + default: 0 + type: string + +jobs: + chart_release: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Build the Helm Chart manifests + run: | + make helm-build \ + VERSION=${{ inputs.operatorVersion }} \ + LIMITADOR_VERSION=${{ inputs.limitadorVersion }} + + - name: Package Helm Chart + run: | + make helm-package + + - name: Upload package to GitHub Release + run: | + response = make helm-upload-package \ + VERSION=${{ inputs.operatorVersion }} \ + GITHUB_TOKEN=${{ secrets.HELM_WORKFLOWS_TOKEN }} \ + RELEASE_ID=${{ inputs.releaseId }} + echo "response: $response" >> $GITHUB_ENV + + - name: Sync Helm Chart with repository + run: | + make helm-sync-package \ + VERSION=${{ inputs.operatorVersion }} \ + GITHUB_TOKEN=${{ secrets.HELM_WORKFLOWS_TOKEN }} \ + ASSET_ID=${{ env.response.id }} + BROWSER_DOWNLOAD_URL=${{ env.response.browser_download_url }} From 86ca780ba9ff0fb6e9a67d8837445bb3e5f5cfa4 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Tue, 4 Jun 2024 09:51:53 +0200 Subject: [PATCH 10/13] [make] Sertting chart version when building the chart --- make/helm.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/make/helm.mk b/make/helm.mk index 81b63ee4..a3057ab5 100644 --- a/make/helm.mk +++ b/make/helm.mk @@ -8,6 +8,7 @@ helm-build: $(KUSTOMIZE) $(OPERATOR_SDK) $(YQ) manifests ## Build the helm chart cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) # Build the helm chart templates from kustomize manifests $(KUSTOMIZE) build config/helm > charts/limitador-operator/templates/manifests.yaml + V="$(VERSION)" $(YQ) eval '.version = strenv(V)' -i charts/limitador-operator/Chart.yaml .PHONY: helm-install helm-install: $(HELM) ## Install the helm chart From 0ee0d26abebc8d0fd3f999a58a33315a8602f144 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Mon, 17 Jun 2024 16:15:43 +0200 Subject: [PATCH 11/13] [make] Changing the repository name for helm charts --- make/helm.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/make/helm.mk b/make/helm.mk index a3057ab5..68a6fbe9 100644 --- a/make/helm.mk +++ b/make/helm.mk @@ -38,6 +38,8 @@ RELEASE_ID ?= ASSET_ID ?= # GitHub Release Asset Browser Download URL, it can be find in the output of the uploaded asset BROWSER_DOWNLOAD_URL ?= +# Github repo name for the helm charts repository +HELM_REPO_NAME ?= helm-charts ifeq (0.0.0,$(VERSION)) CHART_VERSION = $(VERSION)-dev else @@ -62,5 +64,5 @@ helm-sync-package: $(HELM) ## Sync the helm chart package to the helm-charts rep -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $(GITHUB_TOKEN)" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/$(ORG)/$(REPO_NAME)/dispatches \ - -d '{"event_type":"sync-chart","client_payload":{"chart":limitador-operator,"version":"$(CHART_VERSION)", "asset_id":"$(ASSET_ID)", "browser_download_url": "$(BROWSER_DOWNLOAD_URL)"}}' + https://api.github.com/repos/$(ORG)/$(HELM_REPO_NAME)/dispatches \ + -d '{"event_type":"sync-chart","client_payload":{"chart":"$(REPO_NAME)","version":"$(CHART_VERSION)", "asset_id":"$(ASSET_ID)", "browser_download_url": "$(BROWSER_DOWNLOAD_URL)"}}' From 851cf39b3c8b0200918494359d2bb269c6cec98b Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Tue, 18 Jun 2024 09:49:52 +0200 Subject: [PATCH 12/13] [refactor] Using `svenstaro/upload-release-action@v2` * Instead of curl to endpoint * Removing makefile target previously used * Not passing asset_id to sync package target --- .github/workflows/release-helm-chart.yaml | 17 +++++++++-------- make/helm.mk | 17 +---------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/.github/workflows/release-helm-chart.yaml b/.github/workflows/release-helm-chart.yaml index 594ce7fa..76984699 100644 --- a/.github/workflows/release-helm-chart.yaml +++ b/.github/workflows/release-helm-chart.yaml @@ -52,17 +52,18 @@ jobs: make helm-package - name: Upload package to GitHub Release - run: | - response = make helm-upload-package \ - VERSION=${{ inputs.operatorVersion }} \ - GITHUB_TOKEN=${{ secrets.HELM_WORKFLOWS_TOKEN }} \ - RELEASE_ID=${{ inputs.releaseId }} - echo "response: $response" >> $GITHUB_ENV + uses: svenstaro/upload-release-action@v2 + id: upload-chart + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: charts/limitador-operator-${{ inputs.operatorVersion }}.tgz + asset_name: chart-limitador-operator-${{ inputs.operatorVersion }}.tgz + tag: ${{ github.ref }} + overwrite: true - name: Sync Helm Chart with repository run: | make helm-sync-package \ VERSION=${{ inputs.operatorVersion }} \ GITHUB_TOKEN=${{ secrets.HELM_WORKFLOWS_TOKEN }} \ - ASSET_ID=${{ env.response.id }} - BROWSER_DOWNLOAD_URL=${{ env.response.browser_download_url }} + BROWSER_DOWNLOAD_URL=${{ steps.upload-chart.outputs.browser_download_url }} diff --git a/make/helm.mk b/make/helm.mk index 68a6fbe9..768bcfac 100644 --- a/make/helm.mk +++ b/make/helm.mk @@ -32,10 +32,6 @@ helm-package: $(HELM) ## Package the helm chart # GitHub Token with permissions to upload to the release assets GITHUB_TOKEN ?= -# GitHub Release ID, to find the release_id query the GET /repos/{owner}/{repo}/releases/latest or GET /repos/{owner}/{repo}/releases endpoints -RELEASE_ID ?= -# GitHub Release Asset ID, it can be find in the output of the uploaded asset -ASSET_ID ?= # GitHub Release Asset Browser Download URL, it can be find in the output of the uploaded asset BROWSER_DOWNLOAD_URL ?= # Github repo name for the helm charts repository @@ -46,17 +42,6 @@ else CHART_VERSION = $(VERSION) endif -.PHONY: helm-upload-package -helm-upload-package: $(HELM) ## Upload the helm chart package to the GitHub release assets - curl -L -s \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $(GITHUB_TOKEN)" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -H "Content-Type: application/octet-stream" \ - "https://uploads.github.com/repos/$(ORG)/$(REPO_NAME)/releases/$(RELEASE_ID)/assets?name=chart-limitador-operator-$(CHART_VERSION).tgz" \ - --data-binary "@limitador-operator-$(CHART_VERSION).tgz" - .PHONY: helm-sync-package helm-sync-package: $(HELM) ## Sync the helm chart package to the helm-charts repo curl -L \ @@ -65,4 +50,4 @@ helm-sync-package: $(HELM) ## Sync the helm chart package to the helm-charts rep -H "Authorization: Bearer $(GITHUB_TOKEN)" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/$(ORG)/$(HELM_REPO_NAME)/dispatches \ - -d '{"event_type":"sync-chart","client_payload":{"chart":"$(REPO_NAME)","version":"$(CHART_VERSION)", "asset_id":"$(ASSET_ID)", "browser_download_url": "$(BROWSER_DOWNLOAD_URL)"}}' + -d '{"event_type":"sync-chart","client_payload":{"chart":"$(REPO_NAME)","version":"$(CHART_VERSION)", "browser_download_url": "$(BROWSER_DOWNLOAD_URL)"}}' From a3649adee2c48cd39a644e68d2b92edb42289bc3 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Tue, 18 Jun 2024 10:19:05 +0200 Subject: [PATCH 13/13] [refactor] Renaming the token to match the actual in use one --- .github/workflows/release-helm-chart.yaml | 2 +- make/helm.mk | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-helm-chart.yaml b/.github/workflows/release-helm-chart.yaml index 76984699..e6d627ea 100644 --- a/.github/workflows/release-helm-chart.yaml +++ b/.github/workflows/release-helm-chart.yaml @@ -65,5 +65,5 @@ jobs: run: | make helm-sync-package \ VERSION=${{ inputs.operatorVersion }} \ - GITHUB_TOKEN=${{ secrets.HELM_WORKFLOWS_TOKEN }} \ + HELM_WORKFLOWS_TOKEN=${{ secrets.HELM_WORKFLOWS_TOKEN }} \ BROWSER_DOWNLOAD_URL=${{ steps.upload-chart.outputs.browser_download_url }} diff --git a/make/helm.mk b/make/helm.mk index 768bcfac..b780b40d 100644 --- a/make/helm.mk +++ b/make/helm.mk @@ -31,7 +31,7 @@ helm-package: $(HELM) ## Package the helm chart $(HELM) package charts/limitador-operator # GitHub Token with permissions to upload to the release assets -GITHUB_TOKEN ?= +HELM_WORKFLOWS_TOKEN ?= # GitHub Release Asset Browser Download URL, it can be find in the output of the uploaded asset BROWSER_DOWNLOAD_URL ?= # Github repo name for the helm charts repository @@ -47,7 +47,7 @@ helm-sync-package: $(HELM) ## Sync the helm chart package to the helm-charts rep curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $(GITHUB_TOKEN)" \ + -H "Authorization: Bearer $(HELM_WORKFLOWS_TOKEN)" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/$(ORG)/$(HELM_REPO_NAME)/dispatches \ -d '{"event_type":"sync-chart","client_payload":{"chart":"$(REPO_NAME)","version":"$(CHART_VERSION)", "browser_download_url": "$(BROWSER_DOWNLOAD_URL)"}}'