From 99d86cfe17c2f235c15225cb829e3472c038019b Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Fri, 10 Feb 2023 14:03:22 -0500 Subject: [PATCH 001/160] Initial Commit of ECK for Logstash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initial commit of a simple operator. The first operator will create: * A Service exposing the logstash metrics API, so it can be used for monitoring purposes * Secrets holding logstash.yml * A StatefulSet deploying the logstash pods * Pods with default liveness and readiness probes The sample logstash yml file as located in config/samples/logstash/logstash.yaml will create: ``` ✗ kubectl tree logstash logstash-sample NAMESPACE NAME READY REASON AGE default Logstash/logstash-sample - 4m5s default ├─Secret/logstash-sample-ls-config - 4m4s default ├─Service/logstash-sample-ls-http - 4m5s default │ └─EndpointSlice/logstash-sample-ls-http-kwfsg - 4m5s default └─StatefulSet/logstash-sample-ls - 4m4s default ├─ControllerRevision/logstash-sample-ls-79bd59f869 - 4m4s default ├─Pod/logstash-sample-ls-0 True 3m59s default ├─Pod/logstash-sample-ls-1 True 3m59s default └─Pod/logstash-sample-ls-2 True 3m59s ``` And shows status: ``` ✗ kubectl get logstash logstash-sample NAME AVAILABLE EXPECTED AGE VERSION logstash-sample 3 3 9m1s 8.6.1 ``` Still TODO: * Unit Tests * End to end Tests * Certificate handling on the HTTP Metrics API Tidy up Co-authored-by: Kaise Cheng --- cmd/manager/main.go | 21 +- config/crds/v1/all-crds.yaml | 590 ++ config/crds/v1/bases/kustomization.yaml | 1 + .../logstash.k8s.elastic.co_logstashes.yaml | 7997 +++++++++++++++++ config/crds/v1/patches/kustomization.yaml | 8 + config/crds/v1/patches/logstash-patches.yaml | 7 + config/samples/logstash/logstash.yaml | 27 + config/webhook/manifests.yaml | 22 + .../eck-operator-crds/templates/all-crds.yaml | 596 ++ docs/reference/api-docs.asciidoc | 125 + hack/upgrade-test-harness/go.mod | 1 - hack/upgrade-test-harness/go.sum | 132 - pkg/apis/common/v1/association.go | 2 + pkg/apis/logstash/v1alpha1/doc.go | 11 + .../logstash/v1alpha1/groupversion_info.go | 21 + pkg/apis/logstash/v1alpha1/labels.go | 17 + pkg/apis/logstash/v1alpha1/logstash_types.go | 130 + pkg/apis/logstash/v1alpha1/name.go | 36 + pkg/apis/logstash/v1alpha1/validations.go | 56 + pkg/apis/logstash/v1alpha1/webhook.go | 88 + .../v1alpha1/zz_generated.deepcopy.go | 127 + pkg/controller/common/container/container.go | 1 + pkg/controller/common/container/defaulter.go | 7 + .../common/defaults/pod_template.go | 6 + pkg/controller/common/scheme/scheme.go | 3 + pkg/controller/common/version/version.go | 1 + pkg/controller/elasticsearch/user/roles.go | 11 + pkg/controller/logstash/config.go | 123 + pkg/controller/logstash/driver.go | 133 + pkg/controller/logstash/init_configuration.go | 75 + pkg/controller/logstash/labels.go | 16 + .../logstash/logstash_controller.go | 199 + pkg/controller/logstash/network/ports.go | 10 + pkg/controller/logstash/pod.go | 147 + pkg/controller/logstash/reconcile.go | 90 + pkg/controller/logstash/sset/sset.go | 93 + 36 files changed, 10789 insertions(+), 141 deletions(-) create mode 100644 config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml create mode 100644 config/crds/v1/patches/logstash-patches.yaml create mode 100644 config/samples/logstash/logstash.yaml create mode 100644 pkg/apis/logstash/v1alpha1/doc.go create mode 100644 pkg/apis/logstash/v1alpha1/groupversion_info.go create mode 100644 pkg/apis/logstash/v1alpha1/labels.go create mode 100644 pkg/apis/logstash/v1alpha1/logstash_types.go create mode 100644 pkg/apis/logstash/v1alpha1/name.go create mode 100644 pkg/apis/logstash/v1alpha1/validations.go create mode 100644 pkg/apis/logstash/v1alpha1/webhook.go create mode 100644 pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go create mode 100644 pkg/controller/logstash/config.go create mode 100644 pkg/controller/logstash/driver.go create mode 100644 pkg/controller/logstash/init_configuration.go create mode 100644 pkg/controller/logstash/labels.go create mode 100644 pkg/controller/logstash/logstash_controller.go create mode 100644 pkg/controller/logstash/network/ports.go create mode 100644 pkg/controller/logstash/pod.go create mode 100644 pkg/controller/logstash/reconcile.go create mode 100644 pkg/controller/logstash/sset/sset.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index fba83a755c..16cf2c55cb 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -8,6 +8,8 @@ import ( "context" "errors" "fmt" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "net/http" "net/http/pprof" "os" @@ -847,6 +849,7 @@ func registerControllers(mgr manager.Manager, params operator.Parameters, access {name: "Agent", registerFunc: agent.Add}, {name: "Maps", registerFunc: maps.Add}, {name: "StackConfigPolicy", registerFunc: stackconfigpolicy.Add}, + {name: "Logstash", registerFunc: logstash.Add}, } for _, c := range controllers { @@ -925,14 +928,15 @@ func garbageCollectSoftOwnedSecrets(ctx context.Context, k8sClient k8s.Client) { defer span.End() if err := reconciler.GarbageCollectAllSoftOwnedOrphanSecrets(ctx, k8sClient, map[string]client.Object{ - esv1.Kind: &esv1.Elasticsearch{}, - apmv1.Kind: &apmv1.ApmServer{}, - kbv1.Kind: &kbv1.Kibana{}, - entv1.Kind: &entv1.EnterpriseSearch{}, - beatv1beta1.Kind: &beatv1beta1.Beat{}, - agentv1alpha1.Kind: &agentv1alpha1.Agent{}, - emsv1alpha1.Kind: &emsv1alpha1.ElasticMapsServer{}, - policyv1alpha1.Kind: &policyv1alpha1.StackConfigPolicy{}, + esv1.Kind: &esv1.Elasticsearch{}, + apmv1.Kind: &apmv1.ApmServer{}, + kbv1.Kind: &kbv1.Kibana{}, + entv1.Kind: &entv1.EnterpriseSearch{}, + beatv1beta1.Kind: &beatv1beta1.Beat{}, + agentv1alpha1.Kind: &agentv1alpha1.Agent{}, + emsv1alpha1.Kind: &emsv1alpha1.ElasticMapsServer{}, + policyv1alpha1.Kind: &policyv1alpha1.StackConfigPolicy{}, + logstashv1alpha1.Kind: &logstashv1alpha1.Logstash{}, }); err != nil { log.Error(err, "Orphan secrets garbage collection failed, will be attempted again at next operator restart.") return @@ -973,6 +977,7 @@ func setupWebhook( &kbv1.Kibana{}, &kbv1beta1.Kibana{}, &emsv1alpha1.ElasticMapsServer{}, + &logstashv1alpha1.Logstash{}, } for _, obj := range webhookObjects { if err := commonwebhook.SetupValidatingWebhookWithConfig(&commonwebhook.Config{ diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 94bf0bcd2b..ab495fab43 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9045,6 +9045,596 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + name: logstashes.logstash.k8s.elastic.co +spec: + group: logstash.k8s.elastic.co + names: + categories: + - elastic + kind: Logstash + listKind: LogstashList + plural: logstashes + shortNames: + - ls + singular: logstash + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Available nodes + jsonPath: .status.availableNodes + name: available + type: integer + - description: Expected nodes + jsonPath: .status.expectedNodes + name: expected + type: integer + - jsonPath: .metadata.creationTimestamp + name: age + type: date + - description: Logstash version + jsonPath: .status.version + name: version + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Logstash is the Schema for the logstashes 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: LogstashSpec defines the desired state of Logstash + properties: + config: + description: Config holds the Logstash configuration. At most one + of [`Config`, `ConfigRef`] can be specified. + type: object + x-kubernetes-preserve-unknown-fields: true + configRef: + description: ConfigRef contains a reference to an existing Kubernetes + Secret holding the Logstash configuration. Logstash settings must + be specified as yaml, under a single "logstash.yml" entry. At most + one of [`Config`, `ConfigRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + count: + format: int32 + type: integer + http: + description: HTTP holds the HTTP layer configuration for the Agent + in Fleet mode with Fleet Server enabled. + properties: + service: + description: Service defines the template for the associated Kubernetes + Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. The + name and namespace provided here are managed by ECK and + will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may be + set to "false" if the cluster load-balancer does not + rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests will + be respected, regardless of this field. This field may + only be set for services with type LoadBalancer and + will be cleared if the type is changed to any other + type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is specified + manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This field + may not be changed through updates unless the type field + is also being changed to ExternalName (which requires + this field to be blank) or the type field is being changed + from ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + "None", empty string (""), or a valid IP address. Setting + this to "None" makes a "headless service" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range (as + per system configuration), and is not in use, it will + be allocated to the service; otherwise creation of the + service will fail. This field may not be changed through + updates unless the type field is also being changed + to ExternalName (which requires this field to be empty) + or the type field is being changed from ExternalName + (in which case this field may optionally be specified, + as describe above). Valid values are \"None\", empty + string (\"\"), or a valid IP address. Setting this + to \"None\" makes a \"headless service\" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. If this field is not + specified, it will be initialized from the clusterIP + field. If this field is specified, clients must ensure + that clusterIPs[0] and clusterIP have the same value. + \n This field may hold a maximum of two entries (dual-stack + IPs, in either order). These IPs must correspond to + the values of the ipFamilies field. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy field. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes system. + items: + type: string + type: array + externalName: + description: externalName is the external reference that + discovery mechanisms will return as an alias for this + service (e.g. a DNS CNAME record). No proxying will + be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires `type` + to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of the + Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that assumes + that external load balancers will take care of balancing + the service traffic between nodes, and so each node + will deliver traffic only to the node-local endpoints + of the service, without masquerading the client source + IP. (Traffic mistakenly sent to a node with no endpoints + will be dropped.) The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + Note that traffic sent to an External IP or LoadBalancer + IP from within the cluster will always get "Cluster" + semantics, but clients sending to a NodePort from within + the cluster may need to take traffic policy into account + when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External systems + (e.g. load-balancers) can use this port to determine + if a given node holds endpoints for this service or + not. If this field is specified when creating a Service + which does not need it, creation will fail. This field + will be wiped when updating a Service to no longer need + it (e.g. changing type). This field cannot be updated + once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods only + want to talk to endpoints of the service on the same + node as the pod, dropping the traffic if there are no + local endpoints. The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the cluster, + and ipFamilyPolicy allows it, it will be used; otherwise + creation of the service will fail. This field is conditionally + mutable: it allows for adding or removing a secondary + IP family, but it does not allow changing the primary + IP family of the Service. Valid values are \"IPv4\" + and \"IPv6\". This field only applies to Services of + types ClusterIP, NodePort, and LoadBalancer, and does + apply to \"headless\" services. This field will be wiped + when updating a Service to type ExternalName. \n This + field may hold a maximum of two entries (dual-stack + families, in either order). These families must correspond + to the values of the clusterIPs field, if specified. + Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is no + value provided, then this field will be set to SingleStack. + Services can be "SingleStack" (a single IP family), + "PreferDualStack" (two IP families on dual-stack configured + clusters or a single IP family on single-stack clusters), + or "RequireDualStack" (two IP families on dual-stack + configured clusters, otherwise fail). The ipFamilies + and clusterIPs fields depend on the value of this field. + This field will be wiped when updating a service to + type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set when + the Service type is 'LoadBalancer'. If not set, the + default load balancer implementation is used, today + this is typically done through the cloud provider integration, + but should apply for any default implementation. If + set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated to + a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load balancer + is created. This field will be ignored if the cloud-provider + does not support the feature. Deprecated: This field + was under-specified and its meaning varies across implementations, + and it cannot support dual-stack. As of Kubernetes v1.24, + users are encouraged to use implementation-specific + annotations when available. This field may be removed + in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified client + IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by this + service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this port. + This field follows standard Kubernetes label syntax. + Un-prefixed names are reserved for IANA standard + service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the service. + This must be a DNS_LABEL. All ports within a ServiceSpec + must have unique names. When considering the endpoints + for a Service, this must match the 'name' field + in the EndpointPort. Optional if only one ServicePort + is defined on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or LoadBalancer. Usually + assigned by the system. If a value is specified, + in-range, and not in use it will be used, otherwise + the operation will fail. If not specified, a + port will be allocated if this Service requires + one. If this field is specified when creating + a Service which does not need it, creation will + fail. This field will be wiped when updating a + Service to no longer need it (e.g. changing type + from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by this + service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number must + be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + If this is a string, it will be looked up as a + named port in the target Pod''s container ports. + If this is not specified, the value of the ''port'' + field is used (an identity map). This field is + ignored for services with clusterIP=None, and + should be omitted or set equal to the ''port'' + field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that any + agent which deals with endpoints for this Service should + disregard any indications of ready/not-ready. The primary + use case for setting this field is for a StatefulSet's + Headless Service to propagate SRV DNS records for its + Pods for the purpose of peer discovery. The Kubernetes + controllers that generate Endpoints and EndpointSlice + resources for Services interpret this to mean that all + endpoints are considered "ready" even if the Pods themselves + are not. Agents which consume only Kubernetes generated + endpoints through the Endpoints or EndpointSlice resources + can safely assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. More + info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based session + affinity. Must be ClientIP or None. Defaults to None. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The value + must be >0 && <=86400(for 1 day) if ServiceAffinity + == "ClientIP". Default value is 10800(for 3 + hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates + a cluster-internal IP address for load-balancing to + endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints rather + than a virtual IP. "NodePort" builds on ClusterIP and + allocates a port on every node which routes to the same + endpoints as the clusterIP. "LoadBalancer" builds on + NodePort and creates an external load-balancer (if supported + in the current cloud) which routes to the same endpoints + as the clusterIP. "ExternalName" aliases this service + to the specified externalName. Several other fields + do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes secret + that contains the certificate and private key for enabling + TLS. The referenced secret should contain the following: + \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: + The certificate (or a chain). - `tls.key`: The private key + to the first certificate in the certificate chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + image: + description: Image is the Logstash Docker image to deploy. Version + and Type have to match the Logstash in the image. + type: string + podTemplate: + description: PodTemplate provides customisation options for the Logstash + pods. + type: object + revisionHistoryLimit: + description: RevisionHistoryLimit is the number of revisions to retain + to allow rollback in the underlying StatefulSet. + format: int32 + type: integer + secureSettings: + description: SecureSettings is a list of references to Kubernetes + Secrets containing sensitive configuration options for the Logstash. + Secrets data can be then referenced in the Logstash config using + the Secret's keys or as specified in `Entries` field of each SecureSetting. + items: + description: SecretSource defines a data source based on a Kubernetes + Secret. + properties: + entries: + description: Entries define how to project each key-value pair + in the secret to filesystem paths. If not defined, all keys + will be projected to similarly named paths in the filesystem. + If defined, only the specified keys will be projected to the + corresponding paths. + items: + description: KeyToPath defines how to map a key in a Secret + object to a filesystem path. + properties: + key: + description: Key is the key contained in the secret. + type: string + path: + description: Path is the relative file path to map the + key to. Path must not be an absolute file path and must + not contain any ".." components. + type: string + required: + - key + type: object + type: array + secretName: + description: SecretName is the name of the secret. + type: string + required: + - secretName + type: object + type: array + serviceAccountName: + description: ServiceAccountName is used to check access from the current + resource to Elasticsearch resource in a different namespace. Can + only be used if ECK is enforcing RBAC on references. + type: string + version: + description: Version of the Logstash. + type: string + required: + - version + type: object + status: + description: LogstashStatus defines the observed state of Logstash + properties: + availableNodes: + format: int32 + type: integer + expectedNodes: + format: int32 + type: integer + observedGeneration: + description: ObservedGeneration is the most recent generation observed + for this Logstash instance. It corresponds to the metadata generation, + which is updated on mutation by the API Server. If the generation + observed in status diverges from the generation in metadata, the + Logstash controller has not yet processed the changes contained + in the Logstash specification. + format: int64 + type: integer + version: + description: 'Version of the stack resource currently running. During + version upgrades, multiple versions may run in parallel: this value + specifies the lowest version currently running.' + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.11.3 diff --git a/config/crds/v1/bases/kustomization.yaml b/config/crds/v1/bases/kustomization.yaml index 07d18db313..1c750971ee 100644 --- a/config/crds/v1/bases/kustomization.yaml +++ b/config/crds/v1/bases/kustomization.yaml @@ -8,3 +8,4 @@ resources: - agent.k8s.elastic.co_agents.yaml - maps.k8s.elastic.co_elasticmapsservers.yaml - stackconfigpolicy.k8s.elastic.co_stackconfigpolicies.yaml + - logstash.k8s.elastic.co_logstashes.yaml diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml new file mode 100644 index 0000000000..861b378eb4 --- /dev/null +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -0,0 +1,7997 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + name: logstashes.logstash.k8s.elastic.co +spec: + group: logstash.k8s.elastic.co + names: + categories: + - elastic + kind: Logstash + listKind: LogstashList + plural: logstashes + shortNames: + - ls + singular: logstash + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Available nodes + jsonPath: .status.availableNodes + name: available + type: integer + - description: Expected nodes + jsonPath: .status.expectedNodes + name: expected + type: integer + - jsonPath: .metadata.creationTimestamp + name: age + type: date + - description: Logstash version + jsonPath: .status.version + name: version + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Logstash is the Schema for the logstashes 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: LogstashSpec defines the desired state of Logstash + properties: + config: + description: Config holds the Logstash configuration. At most one + of [`Config`, `ConfigRef`] can be specified. + type: object + x-kubernetes-preserve-unknown-fields: true + configRef: + description: ConfigRef contains a reference to an existing Kubernetes + Secret holding the Logstash configuration. Logstash settings must + be specified as yaml, under a single "logstash.yml" entry. At most + one of [`Config`, `ConfigRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + count: + format: int32 + type: integer + http: + description: HTTP holds the HTTP layer configuration for the Agent + in Fleet mode with Fleet Server enabled. + properties: + service: + description: Service defines the template for the associated Kubernetes + Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. The + name and namespace provided here are managed by ECK and + will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may be + set to "false" if the cluster load-balancer does not + rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests will + be respected, regardless of this field. This field may + only be set for services with type LoadBalancer and + will be cleared if the type is changed to any other + type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is specified + manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This field + may not be changed through updates unless the type field + is also being changed to ExternalName (which requires + this field to be blank) or the type field is being changed + from ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + "None", empty string (""), or a valid IP address. Setting + this to "None" makes a "headless service" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range (as + per system configuration), and is not in use, it will + be allocated to the service; otherwise creation of the + service will fail. This field may not be changed through + updates unless the type field is also being changed + to ExternalName (which requires this field to be empty) + or the type field is being changed from ExternalName + (in which case this field may optionally be specified, + as describe above). Valid values are \"None\", empty + string (\"\"), or a valid IP address. Setting this + to \"None\" makes a \"headless service\" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. If this field is not + specified, it will be initialized from the clusterIP + field. If this field is specified, clients must ensure + that clusterIPs[0] and clusterIP have the same value. + \n This field may hold a maximum of two entries (dual-stack + IPs, in either order). These IPs must correspond to + the values of the ipFamilies field. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy field. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes system. + items: + type: string + type: array + externalName: + description: externalName is the external reference that + discovery mechanisms will return as an alias for this + service (e.g. a DNS CNAME record). No proxying will + be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires `type` + to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of the + Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that assumes + that external load balancers will take care of balancing + the service traffic between nodes, and so each node + will deliver traffic only to the node-local endpoints + of the service, without masquerading the client source + IP. (Traffic mistakenly sent to a node with no endpoints + will be dropped.) The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + Note that traffic sent to an External IP or LoadBalancer + IP from within the cluster will always get "Cluster" + semantics, but clients sending to a NodePort from within + the cluster may need to take traffic policy into account + when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External systems + (e.g. load-balancers) can use this port to determine + if a given node holds endpoints for this service or + not. If this field is specified when creating a Service + which does not need it, creation will fail. This field + will be wiped when updating a Service to no longer need + it (e.g. changing type). This field cannot be updated + once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods only + want to talk to endpoints of the service on the same + node as the pod, dropping the traffic if there are no + local endpoints. The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the cluster, + and ipFamilyPolicy allows it, it will be used; otherwise + creation of the service will fail. This field is conditionally + mutable: it allows for adding or removing a secondary + IP family, but it does not allow changing the primary + IP family of the Service. Valid values are \"IPv4\" + and \"IPv6\". This field only applies to Services of + types ClusterIP, NodePort, and LoadBalancer, and does + apply to \"headless\" services. This field will be wiped + when updating a Service to type ExternalName. \n This + field may hold a maximum of two entries (dual-stack + families, in either order). These families must correspond + to the values of the clusterIPs field, if specified. + Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is no + value provided, then this field will be set to SingleStack. + Services can be "SingleStack" (a single IP family), + "PreferDualStack" (two IP families on dual-stack configured + clusters or a single IP family on single-stack clusters), + or "RequireDualStack" (two IP families on dual-stack + configured clusters, otherwise fail). The ipFamilies + and clusterIPs fields depend on the value of this field. + This field will be wiped when updating a service to + type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set when + the Service type is 'LoadBalancer'. If not set, the + default load balancer implementation is used, today + this is typically done through the cloud provider integration, + but should apply for any default implementation. If + set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated to + a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load balancer + is created. This field will be ignored if the cloud-provider + does not support the feature. Deprecated: This field + was under-specified and its meaning varies across implementations, + and it cannot support dual-stack. As of Kubernetes v1.24, + users are encouraged to use implementation-specific + annotations when available. This field may be removed + in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified client + IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by this + service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this port. + This field follows standard Kubernetes label syntax. + Un-prefixed names are reserved for IANA standard + service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the service. + This must be a DNS_LABEL. All ports within a ServiceSpec + must have unique names. When considering the endpoints + for a Service, this must match the 'name' field + in the EndpointPort. Optional if only one ServicePort + is defined on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or LoadBalancer. Usually + assigned by the system. If a value is specified, + in-range, and not in use it will be used, otherwise + the operation will fail. If not specified, a + port will be allocated if this Service requires + one. If this field is specified when creating + a Service which does not need it, creation will + fail. This field will be wiped when updating a + Service to no longer need it (e.g. changing type + from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by this + service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number must + be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + If this is a string, it will be looked up as a + named port in the target Pod''s container ports. + If this is not specified, the value of the ''port'' + field is used (an identity map). This field is + ignored for services with clusterIP=None, and + should be omitted or set equal to the ''port'' + field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that any + agent which deals with endpoints for this Service should + disregard any indications of ready/not-ready. The primary + use case for setting this field is for a StatefulSet's + Headless Service to propagate SRV DNS records for its + Pods for the purpose of peer discovery. The Kubernetes + controllers that generate Endpoints and EndpointSlice + resources for Services interpret this to mean that all + endpoints are considered "ready" even if the Pods themselves + are not. Agents which consume only Kubernetes generated + endpoints through the Endpoints or EndpointSlice resources + can safely assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. More + info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based session + affinity. Must be ClientIP or None. Defaults to None. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The value + must be >0 && <=86400(for 1 day) if ServiceAffinity + == "ClientIP". Default value is 10800(for 3 + hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates + a cluster-internal IP address for load-balancing to + endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints rather + than a virtual IP. "NodePort" builds on ClusterIP and + allocates a port on every node which routes to the same + endpoints as the clusterIP. "LoadBalancer" builds on + NodePort and creates an external load-balancer (if supported + in the current cloud) which routes to the same endpoints + as the clusterIP. "ExternalName" aliases this service + to the specified externalName. Several other fields + do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes secret + that contains the certificate and private key for enabling + TLS. The referenced secret should contain the following: + \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: + The certificate (or a chain). - `tls.key`: The private key + to the first certificate in the certificate chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + image: + description: Image is the Logstash Docker image to deploy. Version + and Type have to match the Logstash in the image. + type: string + podTemplate: + description: PodTemplate provides customisation options for the Logstash + pods. + properties: + metadata: + description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata' + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: 'Specification of the desired behavior of the pod. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status' + properties: + activeDeadlineSeconds: + description: Optional duration in seconds the pod may be active + on the node relative to StartTime before the system will + actively try to mark it failed and kill associated containers. + Value must be a positive integer. + format: int64 + type: integer + affinity: + description: If specified, the pod's scheduling constraints + 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 + automountServiceAccountToken: + description: AutomountServiceAccountToken indicates whether + a service account token should be automatically mounted. + type: boolean + containers: + description: List of containers belonging to the pod. Containers + cannot currently be added or removed. There must be at least + one container in a Pod. Cannot be updated. + items: + description: A single application container that you want + to run within a pod. + properties: + args: + description: 'Arguments to the entrypoint. The container + image''s CMD is used if this is not provided. Variable + references $(VAR_NAME) are expanded using the container''s + environment. If a variable cannot be resolved, the + reference in the input string will be unchanged. Double + $$ are reduced to a single $, which allows for escaping + the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce + the string literal "$(VAR_NAME)". Escaped references + will never be expanded, regardless of whether the + variable exists or not. Cannot be updated. More info: + https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + command: + description: 'Entrypoint array. Not executed within + a shell. The container image''s ENTRYPOINT is used + if this is not provided. Variable references $(VAR_NAME) + are expanded using the container''s environment. If + a variable cannot be resolved, the reference in the + input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) + syntax: i.e. "$$(VAR_NAME)" will produce the string + literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists + or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + env: + description: List of environment variables to set in + the container. Cannot be updated. + items: + description: EnvVar represents an environment variable + present in a Container. + properties: + name: + description: Name of the environment variable. + Must be a C_IDENTIFIER. + type: string + value: + description: 'Variable references $(VAR_NAME) + are expanded using the previously defined environment + variables in the container and any service environment + variables. If a variable cannot be resolved, + the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows + for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" + will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults + to "".' + type: string + valueFrom: + description: Source for the environment variable's + value. Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + 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 + optional: + description: Specify whether the ConfigMap + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + description: 'Selects a field of the pod: + supports metadata.name, metadata.namespace, + `metadata.labels['''']`, `metadata.annotations['''']`, + spec.nodeName, spec.serviceAccountName, + status.hostIP, status.podIP, status.podIPs.' + properties: + apiVersion: + description: Version of the schema the + FieldPath is written in terms of, defaults + to "v1". + type: string + fieldPath: + description: Path of the field to select + in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, limits.ephemeral-storage, + requests.cpu, requests.memory and requests.ephemeral-storage) + are currently supported.' + properties: + containerName: + description: 'Container name: required + for volumes, optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format + of the exposed resources, defaults to + "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + description: Selects a key of a secret in + the pod's namespace + properties: + key: + description: The key of the secret to + select from. Must be a valid secret + key. + type: string + 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 + optional: + description: Specify whether the Secret + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + envFrom: + description: List of sources to populate environment + variables in the container. The keys defined within + a source must be a C_IDENTIFIER. All invalid keys + will be reported as an event when the container is + starting. When a key exists in multiple sources, the + value associated with the last source will take precedence. + Values defined by an Env with a duplicate key will + take precedence. Cannot be updated. + items: + description: EnvFromSource represents the source of + a set of ConfigMaps + properties: + configMapRef: + description: The ConfigMap to select from + 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 + optional: + description: Specify whether the ConfigMap + must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + prefix: + description: An optional identifier to prepend + to each key in the ConfigMap. Must be a C_IDENTIFIER. + type: string + secretRef: + description: The Secret to select from + 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 + optional: + description: Specify whether the Secret must + be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + type: object + type: array + image: + description: 'Container image name. More info: https://kubernetes.io/docs/concepts/containers/images + This field is optional to allow higher level config + management to default or override container images + in workload controllers like Deployments and StatefulSets.' + type: string + imagePullPolicy: + description: 'Image pull policy. One of Always, Never, + IfNotPresent. Defaults to Always if :latest tag is + specified, or IfNotPresent otherwise. Cannot be updated. + More info: https://kubernetes.io/docs/concepts/containers/images#updating-images' + type: string + lifecycle: + description: Actions that the management system should + take in response to container lifecycle events. Cannot + be updated. + properties: + postStart: + description: 'PostStart is called immediately after + a container is created. If the handler fails, + the container is terminated and restarted according + to its restart policy. Other management of the + container blocks until the hook completes. More + info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before + a container is terminated due to an API request + or management event such as liveness/startup probe + failure, preemption, resource contention, etc. + The handler is not called if the container crashes + or exits. The Pod''s termination grace period + countdown begins before the PreStop hook is executed. + Regardless of the outcome of the handler, the + container will eventually terminate within the + Pod''s termination grace period (unless delayed + by finalizers). Other management of the container + blocks until the hook completes or until the termination + grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object + livenessProbe: + description: 'Periodic probe of container liveness. + Container will be restarted if the probe fails. Cannot + be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + name: + description: Name of the container specified as a DNS_LABEL. + Each container in a pod must have a unique name (DNS_LABEL). + Cannot be updated. + type: string + ports: + description: List of ports to expose from the container. + Not specifying a port here DOES NOT prevent that port + from being exposed. Any port which is listening on + the default "0.0.0.0" address inside a container will + be accessible from the network. Modifying this array + with strategic merge patch may corrupt the data. For + more information See https://github.com/kubernetes/kubernetes/issues/108255. + Cannot be updated. + items: + description: ContainerPort represents a network port + in a single container. + properties: + containerPort: + description: Number of port to expose on the pod's + IP address. This must be a valid port number, + 0 < x < 65536. + format: int32 + type: integer + hostIP: + description: What host IP to bind the external + port to. + type: string + hostPort: + description: Number of port to expose on the host. + If specified, this must be a valid port number, + 0 < x < 65536. If HostNetwork is specified, + this must match ContainerPort. Most containers + do not need this. + format: int32 + type: integer + name: + description: If specified, this must be an IANA_SVC_NAME + and unique within the pod. Each named port in + a pod must have a unique name. Name for the + port that can be referred to by services. + type: string + protocol: + default: TCP + description: Protocol for port. Must be UDP, TCP, + or SCTP. Defaults to "TCP". + type: string + required: + - containerPort + type: object + type: array + x-kubernetes-list-map-keys: + - containerPort + - protocol + x-kubernetes-list-type: map + readinessProbe: + description: 'Periodic probe of container service readiness. + Container will be removed from service endpoints if + the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + resources: + description: 'Compute Resources required by this container. + Cannot be updated. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + 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." + 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. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + securityContext: + description: 'SecurityContext defines the security options + the container should be run with. If set, the fields + of SecurityContext override the equivalent fields + of PodSecurityContext. More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/' + properties: + allowPrivilegeEscalation: + description: 'AllowPrivilegeEscalation controls + whether a process can gain more privileges than + its parent process. This bool directly controls + if the no_new_privs flag will be set on the container + process. AllowPrivilegeEscalation is true always + when the container is: 1) run as Privileged 2) + has CAP_SYS_ADMIN Note that this field cannot + be set when spec.os.name is windows.' + type: boolean + capabilities: + description: The capabilities to add/drop when running + containers. Defaults to the default set of capabilities + granted by the container runtime. Note that this + field cannot be set when spec.os.name is windows. + properties: + add: + description: Added capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + drop: + description: Removed capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + type: object + privileged: + description: Run container in privileged mode. Processes + in privileged containers are essentially equivalent + to root on the host. Defaults to false. Note that + this field cannot be set when spec.os.name is + windows. + type: boolean + procMount: + description: procMount denotes the type of proc + mount to use for the containers. The default is + DefaultProcMount which uses the container runtime + defaults for readonly paths and masked paths. + This requires the ProcMountType feature flag to + be enabled. Note that this field cannot be set + when spec.os.name is windows. + type: string + readOnlyRootFilesystem: + description: Whether this container has a read-only + root filesystem. Default is false. Note that this + field cannot be set when spec.os.name is windows. + type: boolean + runAsGroup: + description: The GID to run the entrypoint of the + container process. Uses runtime default if unset. + May also be set in PodSecurityContext. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + format: int64 + type: integer + runAsNonRoot: + description: Indicates that the container must run + as a non-root user. If true, the Kubelet will + validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start + the container if it does. If unset or false, no + such validation will be performed. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. + type: boolean + runAsUser: + description: The UID to run the entrypoint of the + container process. Defaults to user specified + in image metadata if unspecified. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. Note that this + field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: The SELinux context to be applied to + the container. If unspecified, the container runtime + will allocate a random SELinux context for each + container. May also be set in PodSecurityContext. If + set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + properties: + level: + description: Level is SELinux level label that + applies to the container. + type: string + role: + description: Role is a SELinux role label that + applies to the container. + type: string + type: + description: Type is a SELinux type label that + applies to the container. + type: string + user: + description: User is a SELinux user label that + applies to the container. + type: string + type: object + seccompProfile: + description: The seccomp options to use by this + container. If seccomp options are provided at + both the pod & container level, the container + options override the pod options. Note that this + field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: localhostProfile indicates a profile + defined in a file on the node should be used. + The profile must be preconfigured on the node + to work. Must be a descending path, relative + to the kubelet's configured seccomp profile + location. Must only be set if type is "Localhost". + type: string + type: + description: "type indicates which kind of seccomp + profile will be applied. Valid options are: + \n Localhost - a profile defined in a file + on the node should be used. RuntimeDefault + - the container runtime default profile should + be used. Unconfined - no profile should be + applied." + type: string + required: + - type + type: object + windowsOptions: + description: The Windows specific settings applied + to all containers. If unspecified, the options + from the PodSecurityContext will be used. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is linux. + properties: + gmsaCredentialSpec: + description: GMSACredentialSpec is where the + GMSA admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) + inlines the contents of the GMSA credential + spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name + of the GMSA credential spec to use. + type: string + hostProcess: + description: HostProcess determines if a container + should be run as a 'Host Process' container. + This field is alpha-level and will only be + honored by components that enable the WindowsHostProcessContainers + feature flag. Setting this field without the + feature flag will result in errors when validating + the Pod. All of a Pod's containers must have + the same effective HostProcess value (it is + not allowed to have a mix of HostProcess containers + and non-HostProcess containers). In addition, + if HostProcess is true then HostNetwork must + also be set to true. + type: boolean + runAsUserName: + description: The UserName in Windows to run + the entrypoint of the container process. Defaults + to the user specified in image metadata if + unspecified. May also be set in PodSecurityContext. + If set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes + precedence. + type: string + type: object + type: object + startupProbe: + description: 'StartupProbe indicates that the Pod has + successfully initialized. If specified, no other probes + are executed until this completes successfully. If + this probe fails, the Pod will be restarted, just + as if the livenessProbe failed. This can be used to + provide different probe parameters at the beginning + of a Pod''s lifecycle, when it might take a long time + to load data or warm a cache, than during steady-state + operation. This cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + stdin: + description: Whether this container should allocate + a buffer for stdin in the container runtime. If this + is not set, reads from stdin in the container will + always result in EOF. Default is false. + type: boolean + stdinOnce: + description: Whether the container runtime should close + the stdin channel after it has been opened by a single + attach. When stdin is true the stdin stream will remain + open across multiple attach sessions. If stdinOnce + is set to true, stdin is opened on container start, + is empty until the first client attaches to stdin, + and then remains open and accepts data until the client + disconnects, at which time stdin is closed and remains + closed until the container is restarted. If this flag + is false, a container processes that reads from stdin + will never receive an EOF. Default is false + type: boolean + terminationMessagePath: + description: 'Optional: Path at which the file to which + the container''s termination message will be written + is mounted into the container''s filesystem. Message + written is intended to be brief final status, such + as an assertion failure message. Will be truncated + by the node if greater than 4096 bytes. The total + message length across all containers will be limited + to 12kb. Defaults to /dev/termination-log. Cannot + be updated.' + type: string + terminationMessagePolicy: + description: Indicate how the termination message should + be populated. File will use the contents of terminationMessagePath + to populate the container status message on both success + and failure. FallbackToLogsOnError will use the last + chunk of container log output if the termination message + file is empty and the container exited with an error. + The log output is limited to 2048 bytes or 80 lines, + whichever is smaller. Defaults to File. Cannot be + updated. + type: string + tty: + description: Whether this container should allocate + a TTY for itself, also requires 'stdin' to be true. + Default is false. + type: boolean + volumeDevices: + description: volumeDevices is the list of block devices + to be used by the container. + items: + description: volumeDevice describes a mapping of a + raw block device within a container. + properties: + devicePath: + description: devicePath is the path inside of + the container that the device will be mapped + to. + type: string + name: + description: name must match the name of a persistentVolumeClaim + in the pod + type: string + required: + - devicePath + - name + type: object + type: array + volumeMounts: + description: Pod volumes to mount into the container's + filesystem. Cannot be updated. + items: + description: VolumeMount describes a mounting of a + Volume within a container. + properties: + mountPath: + description: Path within the container at which + the volume should be mounted. Must not contain + ':'. + type: string + mountPropagation: + description: mountPropagation determines how mounts + are propagated from the host to container and + the other way around. When not set, MountPropagationNone + is used. This field is beta in 1.10. + type: string + name: + description: This must match the Name of a Volume. + type: string + readOnly: + description: Mounted read-only if true, read-write + otherwise (false or unspecified). Defaults to + false. + type: boolean + subPath: + description: Path within the volume from which + the container's volume should be mounted. Defaults + to "" (volume's root). + type: string + subPathExpr: + description: Expanded path within the volume from + which the container's volume should be mounted. + Behaves similarly to SubPath but environment + variable references $(VAR_NAME) are expanded + using the container's environment. Defaults + to "" (volume's root). SubPathExpr and SubPath + are mutually exclusive. + type: string + required: + - mountPath + - name + type: object + type: array + workingDir: + description: Container's working directory. If not specified, + the container runtime's default will be used, which + might be configured in the container image. Cannot + be updated. + type: string + required: + - name + type: object + type: array + dnsConfig: + description: Specifies the DNS parameters of a pod. Parameters + specified here will be merged to the generated DNS configuration + based on DNSPolicy. + properties: + nameservers: + description: A list of DNS name server IP addresses. This + will be appended to the base nameservers generated from + DNSPolicy. Duplicated nameservers will be removed. + items: + type: string + type: array + options: + description: A list of DNS resolver options. This will + be merged with the base options generated from DNSPolicy. + Duplicated entries will be removed. Resolution options + given in Options will override those that appear in + the base DNSPolicy. + items: + description: PodDNSConfigOption defines DNS resolver + options of a pod. + properties: + name: + description: Required. + type: string + value: + type: string + type: object + type: array + searches: + description: A list of DNS search domains for host-name + lookup. This will be appended to the base search paths + generated from DNSPolicy. Duplicated search paths will + be removed. + items: + type: string + type: array + type: object + dnsPolicy: + description: Set DNS policy for the pod. Defaults to "ClusterFirst". + Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', + 'Default' or 'None'. DNS parameters given in DNSConfig will + be merged with the policy selected with DNSPolicy. To have + DNS options set along with hostNetwork, you have to specify + DNS policy explicitly to 'ClusterFirstWithHostNet'. + type: string + enableServiceLinks: + description: 'EnableServiceLinks indicates whether information + about services should be injected into pod''s environment + variables, matching the syntax of Docker links. Optional: + Defaults to true.' + type: boolean + ephemeralContainers: + description: List of ephemeral containers run in this pod. + Ephemeral containers may be run in an existing pod to perform + user-initiated actions such as debugging. This list cannot + be specified when creating a pod, and it cannot be modified + by updating the pod spec. In order to add an ephemeral container + to an existing pod, use the pod's ephemeralcontainers subresource. + items: + description: "An EphemeralContainer is a temporary container + that you may add to an existing Pod for user-initiated + activities such as debugging. Ephemeral containers have + no resource or scheduling guarantees, and they will not + be restarted when they exit or when a Pod is removed or + restarted. The kubelet may evict a Pod if an ephemeral + container causes the Pod to exceed its resource allocation. + \n To add an ephemeral container, use the ephemeralcontainers + subresource of an existing Pod. Ephemeral containers may + not be removed or restarted." + properties: + args: + description: 'Arguments to the entrypoint. The image''s + CMD is used if this is not provided. Variable references + $(VAR_NAME) are expanded using the container''s environment. + If a variable cannot be resolved, the reference in + the input string will be unchanged. Double $$ are + reduced to a single $, which allows for escaping the + $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce + the string literal "$(VAR_NAME)". Escaped references + will never be expanded, regardless of whether the + variable exists or not. Cannot be updated. More info: + https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + command: + description: 'Entrypoint array. Not executed within + a shell. The image''s ENTRYPOINT is used if this is + not provided. Variable references $(VAR_NAME) are + expanded using the container''s environment. If a + variable cannot be resolved, the reference in the + input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) + syntax: i.e. "$$(VAR_NAME)" will produce the string + literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists + or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + env: + description: List of environment variables to set in + the container. Cannot be updated. + items: + description: EnvVar represents an environment variable + present in a Container. + properties: + name: + description: Name of the environment variable. + Must be a C_IDENTIFIER. + type: string + value: + description: 'Variable references $(VAR_NAME) + are expanded using the previously defined environment + variables in the container and any service environment + variables. If a variable cannot be resolved, + the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows + for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" + will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults + to "".' + type: string + valueFrom: + description: Source for the environment variable's + value. Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + 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 + optional: + description: Specify whether the ConfigMap + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + description: 'Selects a field of the pod: + supports metadata.name, metadata.namespace, + `metadata.labels['''']`, `metadata.annotations['''']`, + spec.nodeName, spec.serviceAccountName, + status.hostIP, status.podIP, status.podIPs.' + properties: + apiVersion: + description: Version of the schema the + FieldPath is written in terms of, defaults + to "v1". + type: string + fieldPath: + description: Path of the field to select + in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, limits.ephemeral-storage, + requests.cpu, requests.memory and requests.ephemeral-storage) + are currently supported.' + properties: + containerName: + description: 'Container name: required + for volumes, optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format + of the exposed resources, defaults to + "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + description: Selects a key of a secret in + the pod's namespace + properties: + key: + description: The key of the secret to + select from. Must be a valid secret + key. + type: string + 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 + optional: + description: Specify whether the Secret + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + envFrom: + description: List of sources to populate environment + variables in the container. The keys defined within + a source must be a C_IDENTIFIER. All invalid keys + will be reported as an event when the container is + starting. When a key exists in multiple sources, the + value associated with the last source will take precedence. + Values defined by an Env with a duplicate key will + take precedence. Cannot be updated. + items: + description: EnvFromSource represents the source of + a set of ConfigMaps + properties: + configMapRef: + description: The ConfigMap to select from + 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 + optional: + description: Specify whether the ConfigMap + must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + prefix: + description: An optional identifier to prepend + to each key in the ConfigMap. Must be a C_IDENTIFIER. + type: string + secretRef: + description: The Secret to select from + 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 + optional: + description: Specify whether the Secret must + be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + type: object + type: array + image: + description: 'Container image name. More info: https://kubernetes.io/docs/concepts/containers/images' + type: string + imagePullPolicy: + description: 'Image pull policy. One of Always, Never, + IfNotPresent. Defaults to Always if :latest tag is + specified, or IfNotPresent otherwise. Cannot be updated. + More info: https://kubernetes.io/docs/concepts/containers/images#updating-images' + type: string + lifecycle: + description: Lifecycle is not allowed for ephemeral + containers. + properties: + postStart: + description: 'PostStart is called immediately after + a container is created. If the handler fails, + the container is terminated and restarted according + to its restart policy. Other management of the + container blocks until the hook completes. More + info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before + a container is terminated due to an API request + or management event such as liveness/startup probe + failure, preemption, resource contention, etc. + The handler is not called if the container crashes + or exits. The Pod''s termination grace period + countdown begins before the PreStop hook is executed. + Regardless of the outcome of the handler, the + container will eventually terminate within the + Pod''s termination grace period (unless delayed + by finalizers). Other management of the container + blocks until the hook completes or until the termination + grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object + livenessProbe: + description: Probes are not allowed for ephemeral containers. + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + name: + description: Name of the ephemeral container specified + as a DNS_LABEL. This name must be unique among all + containers, init containers and ephemeral containers. + type: string + ports: + description: Ports are not allowed for ephemeral containers. + items: + description: ContainerPort represents a network port + in a single container. + properties: + containerPort: + description: Number of port to expose on the pod's + IP address. This must be a valid port number, + 0 < x < 65536. + format: int32 + type: integer + hostIP: + description: What host IP to bind the external + port to. + type: string + hostPort: + description: Number of port to expose on the host. + If specified, this must be a valid port number, + 0 < x < 65536. If HostNetwork is specified, + this must match ContainerPort. Most containers + do not need this. + format: int32 + type: integer + name: + description: If specified, this must be an IANA_SVC_NAME + and unique within the pod. Each named port in + a pod must have a unique name. Name for the + port that can be referred to by services. + type: string + protocol: + default: TCP + description: Protocol for port. Must be UDP, TCP, + or SCTP. Defaults to "TCP". + type: string + required: + - containerPort + type: object + type: array + x-kubernetes-list-map-keys: + - containerPort + - protocol + x-kubernetes-list-type: map + readinessProbe: + description: Probes are not allowed for ephemeral containers. + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + resources: + description: Resources are not allowed for ephemeral + containers. Ephemeral containers use spare resources + already allocated to the pod. + 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." + 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. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + securityContext: + description: 'Optional: SecurityContext defines the + security options the ephemeral container should be + run with. If set, the fields of SecurityContext override + the equivalent fields of PodSecurityContext.' + properties: + allowPrivilegeEscalation: + description: 'AllowPrivilegeEscalation controls + whether a process can gain more privileges than + its parent process. This bool directly controls + if the no_new_privs flag will be set on the container + process. AllowPrivilegeEscalation is true always + when the container is: 1) run as Privileged 2) + has CAP_SYS_ADMIN Note that this field cannot + be set when spec.os.name is windows.' + type: boolean + capabilities: + description: The capabilities to add/drop when running + containers. Defaults to the default set of capabilities + granted by the container runtime. Note that this + field cannot be set when spec.os.name is windows. + properties: + add: + description: Added capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + drop: + description: Removed capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + type: object + privileged: + description: Run container in privileged mode. Processes + in privileged containers are essentially equivalent + to root on the host. Defaults to false. Note that + this field cannot be set when spec.os.name is + windows. + type: boolean + procMount: + description: procMount denotes the type of proc + mount to use for the containers. The default is + DefaultProcMount which uses the container runtime + defaults for readonly paths and masked paths. + This requires the ProcMountType feature flag to + be enabled. Note that this field cannot be set + when spec.os.name is windows. + type: string + readOnlyRootFilesystem: + description: Whether this container has a read-only + root filesystem. Default is false. Note that this + field cannot be set when spec.os.name is windows. + type: boolean + runAsGroup: + description: The GID to run the entrypoint of the + container process. Uses runtime default if unset. + May also be set in PodSecurityContext. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + format: int64 + type: integer + runAsNonRoot: + description: Indicates that the container must run + as a non-root user. If true, the Kubelet will + validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start + the container if it does. If unset or false, no + such validation will be performed. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. + type: boolean + runAsUser: + description: The UID to run the entrypoint of the + container process. Defaults to user specified + in image metadata if unspecified. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. Note that this + field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: The SELinux context to be applied to + the container. If unspecified, the container runtime + will allocate a random SELinux context for each + container. May also be set in PodSecurityContext. If + set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + properties: + level: + description: Level is SELinux level label that + applies to the container. + type: string + role: + description: Role is a SELinux role label that + applies to the container. + type: string + type: + description: Type is a SELinux type label that + applies to the container. + type: string + user: + description: User is a SELinux user label that + applies to the container. + type: string + type: object + seccompProfile: + description: The seccomp options to use by this + container. If seccomp options are provided at + both the pod & container level, the container + options override the pod options. Note that this + field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: localhostProfile indicates a profile + defined in a file on the node should be used. + The profile must be preconfigured on the node + to work. Must be a descending path, relative + to the kubelet's configured seccomp profile + location. Must only be set if type is "Localhost". + type: string + type: + description: "type indicates which kind of seccomp + profile will be applied. Valid options are: + \n Localhost - a profile defined in a file + on the node should be used. RuntimeDefault + - the container runtime default profile should + be used. Unconfined - no profile should be + applied." + type: string + required: + - type + type: object + windowsOptions: + description: The Windows specific settings applied + to all containers. If unspecified, the options + from the PodSecurityContext will be used. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is linux. + properties: + gmsaCredentialSpec: + description: GMSACredentialSpec is where the + GMSA admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) + inlines the contents of the GMSA credential + spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name + of the GMSA credential spec to use. + type: string + hostProcess: + description: HostProcess determines if a container + should be run as a 'Host Process' container. + This field is alpha-level and will only be + honored by components that enable the WindowsHostProcessContainers + feature flag. Setting this field without the + feature flag will result in errors when validating + the Pod. All of a Pod's containers must have + the same effective HostProcess value (it is + not allowed to have a mix of HostProcess containers + and non-HostProcess containers). In addition, + if HostProcess is true then HostNetwork must + also be set to true. + type: boolean + runAsUserName: + description: The UserName in Windows to run + the entrypoint of the container process. Defaults + to the user specified in image metadata if + unspecified. May also be set in PodSecurityContext. + If set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes + precedence. + type: string + type: object + type: object + startupProbe: + description: Probes are not allowed for ephemeral containers. + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + stdin: + description: Whether this container should allocate + a buffer for stdin in the container runtime. If this + is not set, reads from stdin in the container will + always result in EOF. Default is false. + type: boolean + stdinOnce: + description: Whether the container runtime should close + the stdin channel after it has been opened by a single + attach. When stdin is true the stdin stream will remain + open across multiple attach sessions. If stdinOnce + is set to true, stdin is opened on container start, + is empty until the first client attaches to stdin, + and then remains open and accepts data until the client + disconnects, at which time stdin is closed and remains + closed until the container is restarted. If this flag + is false, a container processes that reads from stdin + will never receive an EOF. Default is false + type: boolean + targetContainerName: + description: "If set, the name of the container from + PodSpec that this ephemeral container targets. The + ephemeral container will be run in the namespaces + (IPC, PID, etc) of this container. If not set then + the ephemeral container uses the namespaces configured + in the Pod spec. \n The container runtime must implement + support for this feature. If the runtime does not + support namespace targeting then the result of setting + this field is undefined." + type: string + terminationMessagePath: + description: 'Optional: Path at which the file to which + the container''s termination message will be written + is mounted into the container''s filesystem. Message + written is intended to be brief final status, such + as an assertion failure message. Will be truncated + by the node if greater than 4096 bytes. The total + message length across all containers will be limited + to 12kb. Defaults to /dev/termination-log. Cannot + be updated.' + type: string + terminationMessagePolicy: + description: Indicate how the termination message should + be populated. File will use the contents of terminationMessagePath + to populate the container status message on both success + and failure. FallbackToLogsOnError will use the last + chunk of container log output if the termination message + file is empty and the container exited with an error. + The log output is limited to 2048 bytes or 80 lines, + whichever is smaller. Defaults to File. Cannot be + updated. + type: string + tty: + description: Whether this container should allocate + a TTY for itself, also requires 'stdin' to be true. + Default is false. + type: boolean + volumeDevices: + description: volumeDevices is the list of block devices + to be used by the container. + items: + description: volumeDevice describes a mapping of a + raw block device within a container. + properties: + devicePath: + description: devicePath is the path inside of + the container that the device will be mapped + to. + type: string + name: + description: name must match the name of a persistentVolumeClaim + in the pod + type: string + required: + - devicePath + - name + type: object + type: array + volumeMounts: + description: Pod volumes to mount into the container's + filesystem. Subpath mounts are not allowed for ephemeral + containers. Cannot be updated. + items: + description: VolumeMount describes a mounting of a + Volume within a container. + properties: + mountPath: + description: Path within the container at which + the volume should be mounted. Must not contain + ':'. + type: string + mountPropagation: + description: mountPropagation determines how mounts + are propagated from the host to container and + the other way around. When not set, MountPropagationNone + is used. This field is beta in 1.10. + type: string + name: + description: This must match the Name of a Volume. + type: string + readOnly: + description: Mounted read-only if true, read-write + otherwise (false or unspecified). Defaults to + false. + type: boolean + subPath: + description: Path within the volume from which + the container's volume should be mounted. Defaults + to "" (volume's root). + type: string + subPathExpr: + description: Expanded path within the volume from + which the container's volume should be mounted. + Behaves similarly to SubPath but environment + variable references $(VAR_NAME) are expanded + using the container's environment. Defaults + to "" (volume's root). SubPathExpr and SubPath + are mutually exclusive. + type: string + required: + - mountPath + - name + type: object + type: array + workingDir: + description: Container's working directory. If not specified, + the container runtime's default will be used, which + might be configured in the container image. Cannot + be updated. + type: string + required: + - name + type: object + type: array + hostAliases: + description: HostAliases is an optional list of hosts and + IPs that will be injected into the pod's hosts file if specified. + This is only valid for non-hostNetwork pods. + items: + description: HostAlias holds the mapping between IP and + hostnames that will be injected as an entry in the pod's + hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + ip: + description: IP address of the host file entry. + type: string + type: object + type: array + hostIPC: + description: 'Use the host''s ipc namespace. Optional: Default + to false.' + type: boolean + hostNetwork: + description: Host networking requested for this pod. Use the + host's network namespace. If this option is set, the ports + that will be used must be specified. Default to false. + type: boolean + hostPID: + description: 'Use the host''s pid namespace. Optional: Default + to false.' + type: boolean + hostUsers: + description: 'Use the host''s user namespace. Optional: Default + to true. If set to true or not present, the pod will be + run in the host user namespace, useful for when the pod + needs a feature only available to the host user namespace, + such as loading a kernel module with CAP_SYS_MODULE. When + set to false, a new userns is created for the pod. Setting + false is useful for mitigating container breakout vulnerabilities + even allowing users to run their containers as root without + actually having root privileges on the host. This field + is alpha-level and is only honored by servers that enable + the UserNamespacesSupport feature.' + type: boolean + hostname: + description: Specifies the hostname of the Pod If not specified, + the pod's hostname will be set to a system-defined value. + type: string + imagePullSecrets: + description: 'ImagePullSecrets is an optional list of references + to secrets in the same namespace to use for pulling any + of the images used by this PodSpec. If specified, these + secrets will be passed to individual puller implementations + for them to use. More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod' + items: + 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: array + initContainers: + description: 'List of initialization containers belonging + to the pod. Init containers are executed in order prior + to containers being started. If any init container fails, + the pod is considered to have failed and is handled according + to its restartPolicy. The name for an init container or + normal container must be unique among all containers. Init + containers may not have Lifecycle actions, Readiness probes, + Liveness probes, or Startup probes. The resourceRequirements + of an init container are taken into account during scheduling + by finding the highest request/limit for each resource type, + and then using the max of of that value or the sum of the + normal containers. Limits are applied to init containers + in a similar fashion. Init containers cannot currently be + added or removed. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/' + items: + description: A single application container that you want + to run within a pod. + properties: + args: + description: 'Arguments to the entrypoint. The container + image''s CMD is used if this is not provided. Variable + references $(VAR_NAME) are expanded using the container''s + environment. If a variable cannot be resolved, the + reference in the input string will be unchanged. Double + $$ are reduced to a single $, which allows for escaping + the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce + the string literal "$(VAR_NAME)". Escaped references + will never be expanded, regardless of whether the + variable exists or not. Cannot be updated. More info: + https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + command: + description: 'Entrypoint array. Not executed within + a shell. The container image''s ENTRYPOINT is used + if this is not provided. Variable references $(VAR_NAME) + are expanded using the container''s environment. If + a variable cannot be resolved, the reference in the + input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) + syntax: i.e. "$$(VAR_NAME)" will produce the string + literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists + or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + env: + description: List of environment variables to set in + the container. Cannot be updated. + items: + description: EnvVar represents an environment variable + present in a Container. + properties: + name: + description: Name of the environment variable. + Must be a C_IDENTIFIER. + type: string + value: + description: 'Variable references $(VAR_NAME) + are expanded using the previously defined environment + variables in the container and any service environment + variables. If a variable cannot be resolved, + the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows + for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" + will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults + to "".' + type: string + valueFrom: + description: Source for the environment variable's + value. Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + 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 + optional: + description: Specify whether the ConfigMap + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + description: 'Selects a field of the pod: + supports metadata.name, metadata.namespace, + `metadata.labels['''']`, `metadata.annotations['''']`, + spec.nodeName, spec.serviceAccountName, + status.hostIP, status.podIP, status.podIPs.' + properties: + apiVersion: + description: Version of the schema the + FieldPath is written in terms of, defaults + to "v1". + type: string + fieldPath: + description: Path of the field to select + in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, limits.ephemeral-storage, + requests.cpu, requests.memory and requests.ephemeral-storage) + are currently supported.' + properties: + containerName: + description: 'Container name: required + for volumes, optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format + of the exposed resources, defaults to + "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + description: Selects a key of a secret in + the pod's namespace + properties: + key: + description: The key of the secret to + select from. Must be a valid secret + key. + type: string + 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 + optional: + description: Specify whether the Secret + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + envFrom: + description: List of sources to populate environment + variables in the container. The keys defined within + a source must be a C_IDENTIFIER. All invalid keys + will be reported as an event when the container is + starting. When a key exists in multiple sources, the + value associated with the last source will take precedence. + Values defined by an Env with a duplicate key will + take precedence. Cannot be updated. + items: + description: EnvFromSource represents the source of + a set of ConfigMaps + properties: + configMapRef: + description: The ConfigMap to select from + 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 + optional: + description: Specify whether the ConfigMap + must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + prefix: + description: An optional identifier to prepend + to each key in the ConfigMap. Must be a C_IDENTIFIER. + type: string + secretRef: + description: The Secret to select from + 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 + optional: + description: Specify whether the Secret must + be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + type: object + type: array + image: + description: 'Container image name. More info: https://kubernetes.io/docs/concepts/containers/images + This field is optional to allow higher level config + management to default or override container images + in workload controllers like Deployments and StatefulSets.' + type: string + imagePullPolicy: + description: 'Image pull policy. One of Always, Never, + IfNotPresent. Defaults to Always if :latest tag is + specified, or IfNotPresent otherwise. Cannot be updated. + More info: https://kubernetes.io/docs/concepts/containers/images#updating-images' + type: string + lifecycle: + description: Actions that the management system should + take in response to container lifecycle events. Cannot + be updated. + properties: + postStart: + description: 'PostStart is called immediately after + a container is created. If the handler fails, + the container is terminated and restarted according + to its restart policy. Other management of the + container blocks until the hook completes. More + info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before + a container is terminated due to an API request + or management event such as liveness/startup probe + failure, preemption, resource contention, etc. + The handler is not called if the container crashes + or exits. The Pod''s termination grace period + countdown begins before the PreStop hook is executed. + Regardless of the outcome of the handler, the + container will eventually terminate within the + Pod''s termination grace period (unless delayed + by finalizers). Other management of the container + blocks until the hook completes or until the termination + grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object + livenessProbe: + description: 'Periodic probe of container liveness. + Container will be restarted if the probe fails. Cannot + be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + name: + description: Name of the container specified as a DNS_LABEL. + Each container in a pod must have a unique name (DNS_LABEL). + Cannot be updated. + type: string + ports: + description: List of ports to expose from the container. + Not specifying a port here DOES NOT prevent that port + from being exposed. Any port which is listening on + the default "0.0.0.0" address inside a container will + be accessible from the network. Modifying this array + with strategic merge patch may corrupt the data. For + more information See https://github.com/kubernetes/kubernetes/issues/108255. + Cannot be updated. + items: + description: ContainerPort represents a network port + in a single container. + properties: + containerPort: + description: Number of port to expose on the pod's + IP address. This must be a valid port number, + 0 < x < 65536. + format: int32 + type: integer + hostIP: + description: What host IP to bind the external + port to. + type: string + hostPort: + description: Number of port to expose on the host. + If specified, this must be a valid port number, + 0 < x < 65536. If HostNetwork is specified, + this must match ContainerPort. Most containers + do not need this. + format: int32 + type: integer + name: + description: If specified, this must be an IANA_SVC_NAME + and unique within the pod. Each named port in + a pod must have a unique name. Name for the + port that can be referred to by services. + type: string + protocol: + default: TCP + description: Protocol for port. Must be UDP, TCP, + or SCTP. Defaults to "TCP". + type: string + required: + - containerPort + type: object + type: array + x-kubernetes-list-map-keys: + - containerPort + - protocol + x-kubernetes-list-type: map + readinessProbe: + description: 'Periodic probe of container service readiness. + Container will be removed from service endpoints if + the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + resources: + description: 'Compute Resources required by this container. + Cannot be updated. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + 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." + 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. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + securityContext: + description: 'SecurityContext defines the security options + the container should be run with. If set, the fields + of SecurityContext override the equivalent fields + of PodSecurityContext. More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/' + properties: + allowPrivilegeEscalation: + description: 'AllowPrivilegeEscalation controls + whether a process can gain more privileges than + its parent process. This bool directly controls + if the no_new_privs flag will be set on the container + process. AllowPrivilegeEscalation is true always + when the container is: 1) run as Privileged 2) + has CAP_SYS_ADMIN Note that this field cannot + be set when spec.os.name is windows.' + type: boolean + capabilities: + description: The capabilities to add/drop when running + containers. Defaults to the default set of capabilities + granted by the container runtime. Note that this + field cannot be set when spec.os.name is windows. + properties: + add: + description: Added capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + drop: + description: Removed capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + type: object + privileged: + description: Run container in privileged mode. Processes + in privileged containers are essentially equivalent + to root on the host. Defaults to false. Note that + this field cannot be set when spec.os.name is + windows. + type: boolean + procMount: + description: procMount denotes the type of proc + mount to use for the containers. The default is + DefaultProcMount which uses the container runtime + defaults for readonly paths and masked paths. + This requires the ProcMountType feature flag to + be enabled. Note that this field cannot be set + when spec.os.name is windows. + type: string + readOnlyRootFilesystem: + description: Whether this container has a read-only + root filesystem. Default is false. Note that this + field cannot be set when spec.os.name is windows. + type: boolean + runAsGroup: + description: The GID to run the entrypoint of the + container process. Uses runtime default if unset. + May also be set in PodSecurityContext. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + format: int64 + type: integer + runAsNonRoot: + description: Indicates that the container must run + as a non-root user. If true, the Kubelet will + validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start + the container if it does. If unset or false, no + such validation will be performed. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. + type: boolean + runAsUser: + description: The UID to run the entrypoint of the + container process. Defaults to user specified + in image metadata if unspecified. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. Note that this + field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: The SELinux context to be applied to + the container. If unspecified, the container runtime + will allocate a random SELinux context for each + container. May also be set in PodSecurityContext. If + set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + properties: + level: + description: Level is SELinux level label that + applies to the container. + type: string + role: + description: Role is a SELinux role label that + applies to the container. + type: string + type: + description: Type is a SELinux type label that + applies to the container. + type: string + user: + description: User is a SELinux user label that + applies to the container. + type: string + type: object + seccompProfile: + description: The seccomp options to use by this + container. If seccomp options are provided at + both the pod & container level, the container + options override the pod options. Note that this + field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: localhostProfile indicates a profile + defined in a file on the node should be used. + The profile must be preconfigured on the node + to work. Must be a descending path, relative + to the kubelet's configured seccomp profile + location. Must only be set if type is "Localhost". + type: string + type: + description: "type indicates which kind of seccomp + profile will be applied. Valid options are: + \n Localhost - a profile defined in a file + on the node should be used. RuntimeDefault + - the container runtime default profile should + be used. Unconfined - no profile should be + applied." + type: string + required: + - type + type: object + windowsOptions: + description: The Windows specific settings applied + to all containers. If unspecified, the options + from the PodSecurityContext will be used. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is linux. + properties: + gmsaCredentialSpec: + description: GMSACredentialSpec is where the + GMSA admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) + inlines the contents of the GMSA credential + spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name + of the GMSA credential spec to use. + type: string + hostProcess: + description: HostProcess determines if a container + should be run as a 'Host Process' container. + This field is alpha-level and will only be + honored by components that enable the WindowsHostProcessContainers + feature flag. Setting this field without the + feature flag will result in errors when validating + the Pod. All of a Pod's containers must have + the same effective HostProcess value (it is + not allowed to have a mix of HostProcess containers + and non-HostProcess containers). In addition, + if HostProcess is true then HostNetwork must + also be set to true. + type: boolean + runAsUserName: + description: The UserName in Windows to run + the entrypoint of the container process. Defaults + to the user specified in image metadata if + unspecified. May also be set in PodSecurityContext. + If set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes + precedence. + type: string + type: object + type: object + startupProbe: + description: 'StartupProbe indicates that the Pod has + successfully initialized. If specified, no other probes + are executed until this completes successfully. If + this probe fails, the Pod will be restarted, just + as if the livenessProbe failed. This can be used to + provide different probe parameters at the beginning + of a Pod''s lifecycle, when it might take a long time + to load data or warm a cache, than during steady-state + operation. This cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + stdin: + description: Whether this container should allocate + a buffer for stdin in the container runtime. If this + is not set, reads from stdin in the container will + always result in EOF. Default is false. + type: boolean + stdinOnce: + description: Whether the container runtime should close + the stdin channel after it has been opened by a single + attach. When stdin is true the stdin stream will remain + open across multiple attach sessions. If stdinOnce + is set to true, stdin is opened on container start, + is empty until the first client attaches to stdin, + and then remains open and accepts data until the client + disconnects, at which time stdin is closed and remains + closed until the container is restarted. If this flag + is false, a container processes that reads from stdin + will never receive an EOF. Default is false + type: boolean + terminationMessagePath: + description: 'Optional: Path at which the file to which + the container''s termination message will be written + is mounted into the container''s filesystem. Message + written is intended to be brief final status, such + as an assertion failure message. Will be truncated + by the node if greater than 4096 bytes. The total + message length across all containers will be limited + to 12kb. Defaults to /dev/termination-log. Cannot + be updated.' + type: string + terminationMessagePolicy: + description: Indicate how the termination message should + be populated. File will use the contents of terminationMessagePath + to populate the container status message on both success + and failure. FallbackToLogsOnError will use the last + chunk of container log output if the termination message + file is empty and the container exited with an error. + The log output is limited to 2048 bytes or 80 lines, + whichever is smaller. Defaults to File. Cannot be + updated. + type: string + tty: + description: Whether this container should allocate + a TTY for itself, also requires 'stdin' to be true. + Default is false. + type: boolean + volumeDevices: + description: volumeDevices is the list of block devices + to be used by the container. + items: + description: volumeDevice describes a mapping of a + raw block device within a container. + properties: + devicePath: + description: devicePath is the path inside of + the container that the device will be mapped + to. + type: string + name: + description: name must match the name of a persistentVolumeClaim + in the pod + type: string + required: + - devicePath + - name + type: object + type: array + volumeMounts: + description: Pod volumes to mount into the container's + filesystem. Cannot be updated. + items: + description: VolumeMount describes a mounting of a + Volume within a container. + properties: + mountPath: + description: Path within the container at which + the volume should be mounted. Must not contain + ':'. + type: string + mountPropagation: + description: mountPropagation determines how mounts + are propagated from the host to container and + the other way around. When not set, MountPropagationNone + is used. This field is beta in 1.10. + type: string + name: + description: This must match the Name of a Volume. + type: string + readOnly: + description: Mounted read-only if true, read-write + otherwise (false or unspecified). Defaults to + false. + type: boolean + subPath: + description: Path within the volume from which + the container's volume should be mounted. Defaults + to "" (volume's root). + type: string + subPathExpr: + description: Expanded path within the volume from + which the container's volume should be mounted. + Behaves similarly to SubPath but environment + variable references $(VAR_NAME) are expanded + using the container's environment. Defaults + to "" (volume's root). SubPathExpr and SubPath + are mutually exclusive. + type: string + required: + - mountPath + - name + type: object + type: array + workingDir: + description: Container's working directory. If not specified, + the container runtime's default will be used, which + might be configured in the container image. Cannot + be updated. + type: string + required: + - name + type: object + type: array + nodeName: + description: NodeName is a request to schedule this pod onto + a specific node. If it is non-empty, the scheduler simply + schedules this pod onto that node, assuming that it fits + resource requirements. + type: string + nodeSelector: + additionalProperties: + type: string + description: 'NodeSelector is a selector which must be true + for the pod to fit on a node. Selector which must match + a node''s labels for the pod to be scheduled on that node. + More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/' + type: object + x-kubernetes-map-type: atomic + os: + description: "Specifies the OS of the containers in the pod. + Some pod and container fields are restricted if this is + set. \n If the OS field is set to linux, the following fields + must be unset: -securityContext.windowsOptions \n If the + OS field is set to windows, following fields must be unset: + - spec.hostPID - spec.hostIPC - spec.hostUsers - spec.securityContext.seLinuxOptions + - spec.securityContext.seccompProfile - spec.securityContext.fsGroup + - spec.securityContext.fsGroupChangePolicy - spec.securityContext.sysctls + - spec.shareProcessNamespace - spec.securityContext.runAsUser + - spec.securityContext.runAsGroup - spec.securityContext.supplementalGroups + - spec.containers[*].securityContext.seLinuxOptions - spec.containers[*].securityContext.seccompProfile + - spec.containers[*].securityContext.capabilities - spec.containers[*].securityContext.readOnlyRootFilesystem + - spec.containers[*].securityContext.privileged - spec.containers[*].securityContext.allowPrivilegeEscalation + - spec.containers[*].securityContext.procMount - spec.containers[*].securityContext.runAsUser + - spec.containers[*].securityContext.runAsGroup" + properties: + name: + description: 'Name is the name of the operating system. + The currently supported values are linux and windows. + Additional value may be defined in future and can be + one of: https://github.com/opencontainers/runtime-spec/blob/master/config.md#platform-specific-configuration + Clients should expect to handle additional values and + treat unrecognized values in this field as os: null' + type: string + required: + - name + type: object + overhead: + 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: 'Overhead represents the resource overhead associated + with running a pod for a given RuntimeClass. This field + will be autopopulated at admission time by the RuntimeClass + admission controller. If the RuntimeClass admission controller + is enabled, overhead must not be set in Pod create requests. + The RuntimeClass admission controller will reject Pod create + requests which have the overhead already set. If RuntimeClass + is configured and selected in the PodSpec, Overhead will + be set to the value defined in the corresponding RuntimeClass, + otherwise it will remain unset and treated as zero. More + info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md' + type: object + preemptionPolicy: + description: PreemptionPolicy is the Policy for preempting + pods with lower priority. One of Never, PreemptLowerPriority. + Defaults to PreemptLowerPriority if unset. + type: string + priority: + description: The priority value. Various system components + use this field to find the priority of the pod. When Priority + Admission Controller is enabled, it prevents users from + setting this field. The admission controller populates this + field from PriorityClassName. The higher the value, the + higher the priority. + format: int32 + type: integer + priorityClassName: + description: If specified, indicates the pod's priority. "system-node-critical" + and "system-cluster-critical" are two special keywords which + indicate the highest priorities with the former being the + highest priority. Any other name must be defined by creating + a PriorityClass object with that name. If not specified, + the pod priority will be default or zero if there is no + default. + type: string + readinessGates: + description: 'If specified, all readiness gates will be evaluated + for pod readiness. A pod is ready when all its containers + are ready AND all conditions specified in the readiness + gates have status equal to "True" More info: https://git.k8s.io/enhancements/keps/sig-network/580-pod-readiness-gates' + items: + description: PodReadinessGate contains the reference to + a pod condition + properties: + conditionType: + description: ConditionType refers to a condition in + the pod's condition list with matching type. + type: string + required: + - conditionType + type: object + type: array + resourceClaims: + description: "ResourceClaims defines which ResourceClaims + must be allocated and reserved before the Pod is allowed + to start. The resources will be made available to those + containers which consume them by name. \n This is an alpha + field and requires enabling the DynamicResourceAllocation + feature gate. \n This field is immutable." + items: + description: PodResourceClaim references exactly one ResourceClaim + through a ClaimSource. It adds a name to it that uniquely + identifies the ResourceClaim inside the Pod. Containers + that need access to the ResourceClaim reference it with + this name. + properties: + name: + description: Name uniquely identifies this resource + claim inside the pod. This must be a DNS_LABEL. + type: string + source: + description: Source describes where to find the ResourceClaim. + properties: + resourceClaimName: + description: ResourceClaimName is the name of a + ResourceClaim object in the same namespace as + this pod. + type: string + resourceClaimTemplateName: + description: "ResourceClaimTemplateName is the name + of a ResourceClaimTemplate object in the same + namespace as this pod. \n The template will be + used to create a new ResourceClaim, which will + be bound to this pod. When this pod is deleted, + the ResourceClaim will also be deleted. The name + of the ResourceClaim will be -, where is the PodResourceClaim.Name. + Pod validation will reject the pod if the concatenated + name is not valid for a ResourceClaim (e.g. too + long). \n An existing ResourceClaim with that + name that is not owned by the pod will not be + used for the pod to avoid using an unrelated resource + by mistake. Scheduling and pod startup are then + blocked until the unrelated ResourceClaim is removed. + \n This field is immutable and no changes will + be made to the corresponding ResourceClaim by + the control plane after creating the ResourceClaim." + type: string + type: object + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + restartPolicy: + description: 'Restart policy for all containers within the + pod. One of Always, OnFailure, Never. Default to Always. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy' + type: string + runtimeClassName: + description: 'RuntimeClassName refers to a RuntimeClass object + in the node.k8s.io group, which should be used to run this + pod. If no RuntimeClass resource matches the named class, + the pod will not be run. If unset or empty, the "legacy" + RuntimeClass will be used, which is an implicit class with + an empty definition that uses the default runtime handler. + More info: https://git.k8s.io/enhancements/keps/sig-node/585-runtime-class' + type: string + schedulerName: + description: If specified, the pod will be dispatched by specified + scheduler. If not specified, the pod will be dispatched + by default scheduler. + type: string + schedulingGates: + description: "SchedulingGates is an opaque list of values + that if specified will block scheduling the pod. More info: + \ https://git.k8s.io/enhancements/keps/sig-scheduling/3521-pod-scheduling-readiness. + \n This is an alpha-level feature enabled by PodSchedulingReadiness + feature gate." + items: + description: PodSchedulingGate is associated to a Pod to + guard its scheduling. + properties: + name: + description: Name of the scheduling gate. Each scheduling + gate must have a unique name field. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + securityContext: + description: 'SecurityContext holds pod-level security attributes + and common container settings. Optional: Defaults to empty. See + type description for default values of each field.' + properties: + fsGroup: + description: "A special supplemental group that applies + to all containers in a pod. Some volume types allow + the Kubelet to change the ownership of that volume to + be owned by the pod: \n 1. The owning GID will be the + FSGroup 2. The setgid bit is set (new files created + in the volume will be owned by FSGroup) 3. The permission + bits are OR'd with rw-rw---- \n If unset, the Kubelet + will not modify the ownership and permissions of any + volume. Note that this field cannot be set when spec.os.name + is windows." + format: int64 + type: integer + fsGroupChangePolicy: + description: 'fsGroupChangePolicy defines behavior of + changing ownership and permission of the volume before + being exposed inside Pod. This field will only apply + to volume types which support fsGroup based ownership(and + permissions). It will have no effect on ephemeral volume + types such as: secret, configmaps and emptydir. Valid + values are "OnRootMismatch" and "Always". If not specified, + "Always" is used. Note that this field cannot be set + when spec.os.name is windows.' + type: string + runAsGroup: + description: The GID to run the entrypoint of the container + process. Uses runtime default if unset. May also be + set in SecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in SecurityContext + takes precedence for that container. Note that this + field cannot be set when spec.os.name is windows. + format: int64 + type: integer + runAsNonRoot: + description: Indicates that the container must run as + a non-root user. If true, the Kubelet will validate + the image at runtime to ensure that it does not run + as UID 0 (root) and fail to start the container if it + does. If unset or false, no such validation will be + performed. May also be set in SecurityContext. If set + in both SecurityContext and PodSecurityContext, the + value specified in SecurityContext takes precedence. + type: boolean + runAsUser: + description: The UID to run the entrypoint of the container + process. Defaults to user specified in image metadata + if unspecified. May also be set in SecurityContext. If + set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence + for that container. Note that this field cannot be set + when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: The SELinux context to be applied to all + containers. If unspecified, the container runtime will + allocate a random SELinux context for each container. May + also be set in SecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in SecurityContext + takes precedence for that container. Note that this + field cannot be set when spec.os.name is windows. + properties: + level: + description: Level is SELinux level label that applies + to the container. + type: string + role: + description: Role is a SELinux role label that applies + to the container. + type: string + type: + description: Type is a SELinux type label that applies + to the container. + type: string + user: + description: User is a SELinux user label that applies + to the container. + type: string + type: object + seccompProfile: + description: The seccomp options to use by the containers + in this pod. Note that this field cannot be set when + spec.os.name is windows. + properties: + localhostProfile: + description: localhostProfile indicates a profile + defined in a file on the node should be used. The + profile must be preconfigured on the node to work. + Must be a descending path, relative to the kubelet's + configured seccomp profile location. Must only be + set if type is "Localhost". + type: string + type: + description: "type indicates which kind of seccomp + profile will be applied. Valid options are: \n Localhost + - a profile defined in a file on the node should + be used. RuntimeDefault - the container runtime + default profile should be used. Unconfined - no + profile should be applied." + type: string + required: + - type + type: object + supplementalGroups: + description: A list of groups applied to the first process + run in each container, in addition to the container's + primary GID, the fsGroup (if specified), and group memberships + defined in the container image for the uid of the container + process. If unspecified, no additional groups are added + to any container. Note that group memberships defined + in the container image for the uid of the container + process are still effective, even if they are not included + in this list. Note that this field cannot be set when + spec.os.name is windows. + items: + format: int64 + type: integer + type: array + sysctls: + description: Sysctls hold a list of namespaced sysctls + used for the pod. Pods with unsupported sysctls (by + the container runtime) might fail to launch. Note that + this field cannot be set when spec.os.name is windows. + items: + description: Sysctl defines a kernel parameter to be + set + properties: + name: + description: Name of a property to set + type: string + value: + description: Value of a property to set + type: string + required: + - name + - value + type: object + type: array + windowsOptions: + description: The Windows specific settings applied to + all containers. If unspecified, the options within a + container's SecurityContext will be used. If set in + both SecurityContext and PodSecurityContext, the value + specified in SecurityContext takes precedence. Note + that this field cannot be set when spec.os.name is linux. + properties: + gmsaCredentialSpec: + description: GMSACredentialSpec is where the GMSA + admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) + inlines the contents of the GMSA credential spec + named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name of + the GMSA credential spec to use. + type: string + hostProcess: + description: HostProcess determines if a container + should be run as a 'Host Process' container. This + field is alpha-level and will only be honored by + components that enable the WindowsHostProcessContainers + feature flag. Setting this field without the feature + flag will result in errors when validating the Pod. + All of a Pod's containers must have the same effective + HostProcess value (it is not allowed to have a mix + of HostProcess containers and non-HostProcess containers). In + addition, if HostProcess is true then HostNetwork + must also be set to true. + type: boolean + runAsUserName: + description: The UserName in Windows to run the entrypoint + of the container process. Defaults to the user specified + in image metadata if unspecified. May also be set + in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in SecurityContext + takes precedence. + type: string + type: object + type: object + serviceAccount: + description: 'DeprecatedServiceAccount is a depreciated alias + for ServiceAccountName. Deprecated: Use serviceAccountName + instead.' + type: string + serviceAccountName: + description: 'ServiceAccountName is the name of the ServiceAccount + to use to run this pod. More info: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/' + type: string + setHostnameAsFQDN: + description: If true the pod's hostname will be configured + as the pod's FQDN, rather than the leaf name (the default). + In Linux containers, this means setting the FQDN in the + hostname field of the kernel (the nodename field of struct + utsname). In Windows containers, this means setting the + registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters + to FQDN. If a pod does not have FQDN, this has no effect. + Default to false. + type: boolean + shareProcessNamespace: + description: 'Share a single process namespace between all + of the containers in a pod. When this is set containers + will be able to view and signal processes from other containers + in the same pod, and the first process in each container + will not be assigned PID 1. HostPID and ShareProcessNamespace + cannot both be set. Optional: Default to false.' + type: boolean + subdomain: + description: If specified, the fully qualified Pod hostname + will be "...svc.". If not specified, the pod will not have a domainname + at all. + type: string + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod needs to + terminate gracefully. May be decreased in delete request. + Value must be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity to + shut down). If this value is nil, the default grace period + will be used instead. The grace period is the duration in + seconds after the processes running in the pod are sent + a termination signal and the time when the processes are + forcibly halted with a kill signal. Set this value longer + than the expected cleanup time for your process. Defaults + to 30 seconds. + format: int64 + type: integer + tolerations: + description: If specified, the pod's tolerations. + items: + description: The pod this Toleration is attached to tolerates + any taint that matches the triple using + the matching operator . + properties: + effect: + description: Effect indicates the taint effect to match. + Empty means match all taint effects. When specified, + allowed values are NoSchedule, PreferNoSchedule and + NoExecute. + type: string + key: + description: Key is the taint key that the toleration + applies to. Empty means match all taint keys. If the + key is empty, operator must be Exists; this combination + means to match all values and all keys. + type: string + operator: + description: Operator represents a key's relationship + to the value. Valid operators are Exists and Equal. + Defaults to Equal. Exists is equivalent to wildcard + for value, so that a pod can tolerate all taints of + a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the period + of time the toleration (which must be of effect NoExecute, + otherwise this field is ignored) tolerates the taint. + By default, it is not set, which means tolerate the + taint forever (do not evict). Zero and negative values + will be treated as 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration + matches to. If the operator is Exists, the value should + be empty, otherwise just a regular string. + type: string + type: object + type: array + topologySpreadConstraints: + description: TopologySpreadConstraints describes how a group + of pods ought to spread across topology domains. Scheduler + will schedule pods in a way which abides by the constraints. + All topologySpreadConstraints are ANDed. + items: + description: TopologySpreadConstraint specifies how to spread + matching pods among the given topology. + properties: + labelSelector: + description: LabelSelector is used to find matching + pods. Pods that match this label selector are counted + to determine the number of pods in their corresponding + topology domain. + 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 + matchLabelKeys: + description: MatchLabelKeys is a set of pod label keys + to select the pods over which spreading will be calculated. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are ANDed with + labelSelector to select the group of existing pods + over which spreading will be calculated for the incoming + pod. Keys that don't exist in the incoming pod labels + will be ignored. A null or empty list means only match + against labelSelector. + items: + type: string + type: array + x-kubernetes-list-type: atomic + maxSkew: + description: 'MaxSkew describes the degree to which + pods may be unevenly distributed. When `whenUnsatisfiable=DoNotSchedule`, + it is the maximum permitted difference between the + number of matching pods in the target topology and + the global minimum. The global minimum is the minimum + number of matching pods in an eligible domain or zero + if the number of eligible domains is less than MinDomains. + For example, in a 3-zone cluster, MaxSkew is set to + 1, and pods with the same labelSelector spread as + 2/2/1: In this case, the global minimum is 1. | zone1 + | zone2 | zone3 | | P P | P P | P | - if MaxSkew + is 1, incoming pod can only be scheduled to zone3 + to become 2/2/2; scheduling it onto zone1(zone2) would + make the ActualSkew(3-1) on zone1(zone2) violate MaxSkew(1). + - if MaxSkew is 2, incoming pod can be scheduled onto + any zone. When `whenUnsatisfiable=ScheduleAnyway`, + it is used to give higher precedence to topologies + that satisfy it. It''s a required field. Default value + is 1 and 0 is not allowed.' + format: int32 + type: integer + minDomains: + description: "MinDomains indicates a minimum number + of eligible domains. When the number of eligible domains + with matching topology keys is less than minDomains, + Pod Topology Spread treats \"global minimum\" as 0, + and then the calculation of Skew is performed. And + when the number of eligible domains with matching + topology keys equals or greater than minDomains, this + value has no effect on scheduling. As a result, when + the number of eligible domains is less than minDomains, + scheduler won't schedule more than maxSkew Pods to + those domains. If value is nil, the constraint behaves + as if MinDomains is equal to 1. Valid values are integers + greater than 0. When value is not nil, WhenUnsatisfiable + must be DoNotSchedule. \n For example, in a 3-zone + cluster, MaxSkew is set to 2, MinDomains is set to + 5 and pods with the same labelSelector spread as 2/2/2: + | zone1 | zone2 | zone3 | | P P | P P | P P | + The number of domains is less than 5(MinDomains), + so \"global minimum\" is treated as 0. In this situation, + new pod with the same labelSelector cannot be scheduled, + because computed skew will be 3(3 - 0) if new Pod + is scheduled to any of the three zones, it will violate + MaxSkew. \n This is a beta field and requires the + MinDomainsInPodTopologySpread feature gate to be enabled + (enabled by default)." + format: int32 + type: integer + nodeAffinityPolicy: + description: "NodeAffinityPolicy indicates how we will + treat Pod's nodeAffinity/nodeSelector when calculating + pod topology spread skew. Options are: - Honor: only + nodes matching nodeAffinity/nodeSelector are included + in the calculations. - Ignore: nodeAffinity/nodeSelector + are ignored. All nodes are included in the calculations. + \n If this value is nil, the behavior is equivalent + to the Honor policy. This is a beta-level feature + default enabled by the NodeInclusionPolicyInPodTopologySpread + feature flag." + type: string + nodeTaintsPolicy: + description: "NodeTaintsPolicy indicates how we will + treat node taints when calculating pod topology spread + skew. Options are: - Honor: nodes without taints, + along with tainted nodes for which the incoming pod + has a toleration, are included. - Ignore: node taints + are ignored. All nodes are included. \n If this value + is nil, the behavior is equivalent to the Ignore policy. + This is a beta-level feature default enabled by the + NodeInclusionPolicyInPodTopologySpread feature flag." + type: string + topologyKey: + description: TopologyKey is the key of node labels. + Nodes that have a label with this key and identical + values are considered to be in the same topology. + We consider each as a "bucket", and try + to put balanced number of pods into each bucket. We + define a domain as a particular instance of a topology. + Also, we define an eligible domain as a domain whose + nodes meet the requirements of nodeAffinityPolicy + and nodeTaintsPolicy. e.g. If TopologyKey is "kubernetes.io/hostname", + each Node is a domain of that topology. And, if TopologyKey + is "topology.kubernetes.io/zone", each zone is a domain + of that topology. It's a required field. + type: string + whenUnsatisfiable: + description: 'WhenUnsatisfiable indicates how to deal + with a pod if it doesn''t satisfy the spread constraint. + - DoNotSchedule (default) tells the scheduler not + to schedule it. - ScheduleAnyway tells the scheduler + to schedule the pod in any location, but giving higher + precedence to topologies that would help reduce the + skew. A constraint is considered "Unsatisfiable" for + an incoming pod if and only if every possible node + assignment for that pod would violate "MaxSkew" on + some topology. For example, in a 3-zone cluster, MaxSkew + is set to 1, and pods with the same labelSelector + spread as 3/1/1: | zone1 | zone2 | zone3 | | P P P + | P | P | If WhenUnsatisfiable is set to DoNotSchedule, + incoming pod can only be scheduled to zone2(zone3) + to become 3/2/1(3/1/2) as ActualSkew(2-1) on zone2(zone3) + satisfies MaxSkew(1). In other words, the cluster + can still be imbalanced, but scheduler won''t make + it *more* imbalanced. It''s a required field.' + type: string + required: + - maxSkew + - topologyKey + - whenUnsatisfiable + type: object + type: array + x-kubernetes-list-map-keys: + - topologyKey + - whenUnsatisfiable + x-kubernetes-list-type: map + volumes: + description: 'List of volumes that can be mounted by containers + belonging to the pod. More info: https://kubernetes.io/docs/concepts/storage/volumes' + items: + description: Volume represents a named volume in a pod that + may be accessed by any container in the pod. + properties: + awsElasticBlockStore: + description: 'awsElasticBlockStore represents an AWS + Disk resource that is attached to a kubelet''s host + machine and then exposed to the pod. More info: https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore' + properties: + fsType: + description: 'fsType is the filesystem type of the + volume that you want to mount. Tip: Ensure that + the filesystem type is supported by the host operating + system. Examples: "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. More info: + https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore + TODO: how do we prevent errors in the filesystem + from compromising the machine' + type: string + partition: + description: 'partition is the partition in the + volume that you want to mount. If omitted, the + default is to mount by volume name. Examples: + For volume /dev/sda1, you specify the partition + as "1". Similarly, the volume partition for /dev/sda + is "0" (or you can leave the property empty).' + format: int32 + type: integer + readOnly: + description: 'readOnly value true will force the + readOnly setting in VolumeMounts. More info: https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore' + type: boolean + volumeID: + description: 'volumeID is unique ID of the persistent + disk resource in AWS (Amazon EBS volume). More + info: https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore' + type: string + required: + - volumeID + type: object + azureDisk: + description: azureDisk represents an Azure Data Disk + mount on the host and bind mount to the pod. + properties: + cachingMode: + description: 'cachingMode is the Host Caching mode: + None, Read Only, Read Write.' + type: string + diskName: + description: diskName is the Name of the data disk + in the blob storage + type: string + diskURI: + description: diskURI is the URI of data disk in + the blob storage + type: string + fsType: + description: fsType is Filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. + type: string + kind: + description: 'kind expected values are Shared: multiple + blob disks per storage account Dedicated: single + blob disk per storage account Managed: azure + managed data disk (only in managed availability + set). defaults to shared' + type: string + readOnly: + description: readOnly Defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + required: + - diskName + - diskURI + type: object + azureFile: + description: azureFile represents an Azure File Service + mount on the host and bind mount to the pod. + properties: + readOnly: + description: readOnly defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + secretName: + description: secretName is the name of secret that + contains Azure Storage Account Name and Key + type: string + shareName: + description: shareName is the azure share Name + type: string + required: + - secretName + - shareName + type: object + cephfs: + description: cephFS represents a Ceph FS mount on the + host that shares a pod's lifetime + properties: + monitors: + description: 'monitors is Required: Monitors is + a collection of Ceph monitors More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + items: + type: string + type: array + path: + description: 'path is Optional: Used as the mounted + root, rather than the full Ceph tree, default + is /' + type: string + readOnly: + description: 'readOnly is Optional: Defaults to + false (read/write). ReadOnly here will force the + ReadOnly setting in VolumeMounts. More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + type: boolean + secretFile: + description: 'secretFile is Optional: SecretFile + is the path to key ring for User, default is /etc/ceph/user.secret + More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + type: string + secretRef: + description: 'secretRef is Optional: SecretRef is + reference to the authentication secret for User, + default is empty. More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + 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 + user: + description: 'user is optional: User is the rados + user name, default is admin More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + type: string + required: + - monitors + type: object + cinder: + description: 'cinder represents a cinder volume attached + and mounted on kubelets host machine. More info: https://examples.k8s.io/mysql-cinder-pd/README.md' + properties: + fsType: + description: 'fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Examples: "ext4", "xfs", "ntfs". + Implicitly inferred to be "ext4" if unspecified. + More info: https://examples.k8s.io/mysql-cinder-pd/README.md' + type: string + readOnly: + description: 'readOnly defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. More info: https://examples.k8s.io/mysql-cinder-pd/README.md' + type: boolean + secretRef: + description: 'secretRef is optional: points to a + secret object containing parameters used to connect + to OpenStack.' + 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 + volumeID: + description: 'volumeID used to identify the volume + in cinder. More info: https://examples.k8s.io/mysql-cinder-pd/README.md' + type: string + required: + - volumeID + type: object + configMap: + description: configMap represents a configMap that should + populate this volume + properties: + defaultMode: + description: 'defaultMode is optional: mode bits + used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or + a decimal value between 0 and 511. YAML accepts + both octal and decimal values, JSON requires decimal + values for mode bits. Defaults to 0644. Directories + within the path are not affected by this setting. + This might be in conflict with other options that + affect the file mode, like fsGroup, and the result + can be other mode bits set.' + format: int32 + type: integer + items: + description: items if unspecified, each key-value + pair in the Data field of the referenced ConfigMap + will be projected into the volume as a file whose + name is the key and content is the value. If specified, + the listed keys will be projected into the specified + paths, and unlisted keys will not be present. + If a key is specified which is not present in + the ConfigMap, the volume setup will error unless + it is marked optional. Paths must be relative + and may not contain the '..' path or start with + '..'. + items: + description: Maps a string key to a path within + a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: 'mode is Optional: mode bits + used to set permissions on this file. Must + be an octal value between 0000 and 0777 + or a decimal value between 0 and 511. YAML + accepts both octal and decimal values, JSON + requires decimal values for mode bits. If + not specified, the volume defaultMode will + be used. This might be in conflict with + other options that affect the file mode, + like fsGroup, and the result can be other + mode bits set.' + format: int32 + type: integer + path: + description: path is the relative path of + the file to map the key to. May not be an + absolute path. May not contain the path + element '..'. May not start with the string + '..'. + type: string + required: + - key + - path + type: object + type: array + 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 + optional: + description: optional specify whether the ConfigMap + or its keys must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + csi: + description: csi (Container Storage Interface) represents + ephemeral storage that is handled by certain external + CSI drivers (Beta feature). + properties: + driver: + description: driver is the name of the CSI driver + that handles this volume. Consult with your admin + for the correct name as registered in the cluster. + type: string + fsType: + description: fsType to mount. Ex. "ext4", "xfs", + "ntfs". If not provided, the empty value is passed + to the associated CSI driver which will determine + the default filesystem to apply. + type: string + nodePublishSecretRef: + description: nodePublishSecretRef is a reference + to the secret object containing sensitive information + to pass to the CSI driver to complete the CSI + NodePublishVolume and NodeUnpublishVolume calls. + This field is optional, and may be empty if no + secret is required. If the secret object contains + more than one secret, all secret references are + passed. + 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 + readOnly: + description: readOnly specifies a read-only configuration + for the volume. Defaults to false (read/write). + type: boolean + volumeAttributes: + additionalProperties: + type: string + description: volumeAttributes stores driver-specific + properties that are passed to the CSI driver. + Consult your driver's documentation for supported + values. + type: object + required: + - driver + type: object + downwardAPI: + description: downwardAPI represents downward API about + the pod that should populate this volume + properties: + defaultMode: + description: 'Optional: mode bits to use on created + files by default. Must be a Optional: mode bits + used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or + a decimal value between 0 and 511. YAML accepts + both octal and decimal values, JSON requires decimal + values for mode bits. Defaults to 0644. Directories + within the path are not affected by this setting. + This might be in conflict with other options that + affect the file mode, like fsGroup, and the result + can be other mode bits set.' + format: int32 + type: integer + items: + description: Items is a list of downward API volume + file + items: + description: DownwardAPIVolumeFile represents + information to create the file containing the + pod field + properties: + fieldRef: + description: 'Required: Selects a field of + the pod: only annotations, labels, name + and namespace are supported.' + properties: + apiVersion: + description: Version of the schema the + FieldPath is written in terms of, defaults + to "v1". + type: string + fieldPath: + description: Path of the field to select + in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + mode: + description: 'Optional: mode bits used to + set permissions on this file, must be an + octal value between 0000 and 0777 or a decimal + value between 0 and 511. YAML accepts both + octal and decimal values, JSON requires + decimal values for mode bits. If not specified, + the volume defaultMode will be used. This + might be in conflict with other options + that affect the file mode, like fsGroup, + and the result can be other mode bits set.' + format: int32 + type: integer + path: + description: 'Required: Path is the relative + path name of the file to be created. Must + not be absolute or contain the ''..'' path. + Must be utf-8 encoded. The first item of + the relative path must not start with ''..''' + type: string + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, requests.cpu and requests.memory) + are currently supported.' + properties: + containerName: + description: 'Container name: required + for volumes, optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format + of the exposed resources, defaults to + "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + required: + - path + type: object + type: array + type: object + emptyDir: + description: 'emptyDir represents a temporary directory + that shares a pod''s lifetime. More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir' + properties: + medium: + description: 'medium represents what type of storage + medium should back this directory. The default + is "" which means to use the node''s default medium. + Must be an empty string (default) or Memory. More + info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir' + type: string + sizeLimit: + anyOf: + - type: integer + - type: string + description: 'sizeLimit is the total amount of local + storage required for this EmptyDir volume. The + size limit is also applicable for memory medium. + The maximum usage on memory medium EmptyDir would + be the minimum value between the SizeLimit specified + here and the sum of memory limits of all containers + in a pod. The default is nil which means that + the limit is undefined. More info: http://kubernetes.io/docs/user-guide/volumes#emptydir' + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + ephemeral: + description: "ephemeral represents a volume that is + handled by a cluster storage driver. The volume's + lifecycle is tied to the pod that defines it - it + will be created before the pod starts, and deleted + when the pod is removed. \n Use this if: a) the volume + is only needed while the pod runs, b) features of + normal volumes like restoring from snapshot or capacity + tracking are needed, c) the storage driver is specified + through a storage class, and d) the storage driver + supports dynamic volume provisioning through a PersistentVolumeClaim + (see EphemeralVolumeSource for more information on + the connection between this volume type and PersistentVolumeClaim). + \n Use PersistentVolumeClaim or one of the vendor-specific + APIs for volumes that persist for longer than the + lifecycle of an individual pod. \n Use CSI for light-weight + local ephemeral volumes if the CSI driver is meant + to be used that way - see the documentation of the + driver for more information. \n A pod can use both + types of ephemeral volumes and persistent volumes + at the same time." + properties: + volumeClaimTemplate: + description: "Will be used to create a stand-alone + PVC to provision the volume. The pod in which + this EphemeralVolumeSource is embedded will be + the owner of the PVC, i.e. the PVC will be deleted + together with the pod. The name of the PVC will + be `-` where `` + is the name from the `PodSpec.Volumes` array entry. + Pod validation will reject the pod if the concatenated + name is not valid for a PVC (for example, too + long). \n An existing PVC with that name that + is not owned by the pod will *not* be used for + the pod to avoid using an unrelated volume by + mistake. Starting the pod is then blocked until + the unrelated PVC is removed. If such a pre-created + PVC is meant to be used by the pod, the PVC has + to updated with an owner reference to the pod + once the pod exists. Normally this should not + be necessary, but it may be useful when manually + reconstructing a broken cluster. \n This field + is read-only and no changes will be made by Kubernetes + to the PVC after it has been created. \n Required, + must not be nil." + properties: + metadata: + description: May contain labels and annotations + that will be copied into the PVC when creating + it. No other fields are allowed and will be + rejected during validation. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: The specification for the PersistentVolumeClaim. + The entire content is copied unchanged into + the PVC that gets created from this template. + The same fields as in a PersistentVolumeClaim + are also valid here. + properties: + accessModes: + description: 'accessModes contains the desired + access modes the volume should have. More + info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1' + items: + type: string + type: array + dataSource: + description: 'dataSource field can be used + to specify either: * An existing VolumeSnapshot + object (snapshot.storage.k8s.io/VolumeSnapshot) + * An existing PVC (PersistentVolumeClaim) + If the provisioner or an external controller + can support the specified data source, + it will create a new volume based on the + contents of the specified data source. + When the AnyVolumeDataSource feature gate + is enabled, dataSource contents will be + copied to dataSourceRef, and dataSourceRef + contents will be copied to dataSource + when dataSourceRef.namespace is not specified. + If the namespace is specified, then dataSourceRef + will not be copied to dataSource.' + properties: + apiGroup: + description: APIGroup is the group for + the resource being referenced. If + APIGroup is not specified, the specified + Kind must be in the core API group. + For any other third-party types, APIGroup + is required. + type: string + kind: + description: Kind is the type of resource + being referenced + type: string + name: + description: Name is the name of resource + being referenced + type: string + required: + - kind + - name + type: object + x-kubernetes-map-type: atomic + dataSourceRef: + description: 'dataSourceRef specifies the + object from which to populate the volume + with data, if a non-empty volume is desired. + This may be any object from a non-empty + API group (non core object) or a PersistentVolumeClaim + object. When this field is specified, + volume binding will only succeed if the + type of the specified object matches some + installed volume populator or dynamic + provisioner. This field will replace the + functionality of the dataSource field + and as such if both fields are non-empty, + they must have the same value. For backwards + compatibility, when namespace isn''t specified + in dataSourceRef, both fields (dataSource + and dataSourceRef) will be set to the + same value automatically if one of them + is empty and the other is non-empty. When + namespace is specified in dataSourceRef, + dataSource isn''t set to the same value + and must be empty. There are three important + differences between dataSource and dataSourceRef: + * While dataSource only allows two specific + types of objects, dataSourceRef allows + any non-core object, as well as PersistentVolumeClaim + objects. * While dataSource ignores disallowed + values (dropping them), dataSourceRef + preserves all values, and generates an + error if a disallowed value is specified. + * While dataSource only allows local objects, + dataSourceRef allows objects in any namespaces. + (Beta) Using this field requires the AnyVolumeDataSource + feature gate to be enabled. (Alpha) Using + the namespace field of dataSourceRef requires + the CrossNamespaceVolumeDataSource feature + gate to be enabled.' + properties: + apiGroup: + description: APIGroup is the group for + the resource being referenced. If + APIGroup is not specified, the specified + Kind must be in the core API group. + For any other third-party types, APIGroup + is required. + type: string + kind: + description: Kind is the type of resource + being referenced + type: string + name: + description: Name is the name of resource + being referenced + type: string + namespace: + description: Namespace is the namespace + of resource being referenced Note + that when a namespace is specified, + a gateway.networking.k8s.io/ReferenceGrant + object is required in the referent + namespace to allow that namespace's + owner to accept the reference. See + the ReferenceGrant documentation for + details. (Alpha) This field requires + the CrossNamespaceVolumeDataSource + feature gate to be enabled. + type: string + required: + - kind + - name + type: object + resources: + description: 'resources represents the minimum + resources the volume should have. If RecoverVolumeExpansionFailure + feature is enabled users are allowed to + specify resource requirements that are + lower than previous value but must still + be higher than capacity recorded in the + status field of the claim. More info: + https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources' + 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." + 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. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + selector: + description: selector is a label query over + volumes to consider for binding. + 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 + storageClassName: + description: 'storageClassName is the name + of the StorageClass required by the claim. + More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1' + type: string + volumeMode: + description: volumeMode defines what type + of volume is required by the claim. Value + of Filesystem is implied when not included + in claim spec. + type: string + volumeName: + description: volumeName is the binding reference + to the PersistentVolume backing this claim. + type: string + type: object + required: + - spec + type: object + type: object + fc: + description: fc represents a Fibre Channel resource + that is attached to a kubelet's host machine and then + exposed to the pod. + properties: + fsType: + description: 'fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. TODO: how + do we prevent errors in the filesystem from compromising + the machine' + type: string + lun: + description: 'lun is Optional: FC target lun number' + format: int32 + type: integer + readOnly: + description: 'readOnly is Optional: Defaults to + false (read/write). ReadOnly here will force the + ReadOnly setting in VolumeMounts.' + type: boolean + targetWWNs: + description: 'targetWWNs is Optional: FC target + worldwide names (WWNs)' + items: + type: string + type: array + wwids: + description: 'wwids Optional: FC volume world wide + identifiers (wwids) Either wwids or combination + of targetWWNs and lun must be set, but not both + simultaneously.' + items: + type: string + type: array + type: object + flexVolume: + description: flexVolume represents a generic volume + resource that is provisioned/attached using an exec + based plugin. + properties: + driver: + description: driver is the name of the driver to + use for this volume. + type: string + fsType: + description: fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". The + default filesystem depends on FlexVolume script. + type: string + options: + additionalProperties: + type: string + description: 'options is Optional: this field holds + extra command options if any.' + type: object + readOnly: + description: 'readOnly is Optional: defaults to + false (read/write). ReadOnly here will force the + ReadOnly setting in VolumeMounts.' + type: boolean + secretRef: + description: 'secretRef is Optional: secretRef is + reference to the secret object containing sensitive + information to pass to the plugin scripts. This + may be empty if no secret object is specified. + If the secret object contains more than one secret, + all secrets are passed to the plugin scripts.' + 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 + required: + - driver + type: object + flocker: + description: flocker represents a Flocker volume attached + to a kubelet's host machine. This depends on the Flocker + control service being running + properties: + datasetName: + description: datasetName is Name of the dataset + stored as metadata -> name on the dataset for + Flocker should be considered as deprecated + type: string + datasetUUID: + description: datasetUUID is the UUID of the dataset. + This is unique identifier of a Flocker dataset + type: string + type: object + gcePersistentDisk: + description: 'gcePersistentDisk represents a GCE Disk + resource that is attached to a kubelet''s host machine + and then exposed to the pod. More info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk' + properties: + fsType: + description: 'fsType is filesystem type of the volume + that you want to mount. Tip: Ensure that the filesystem + type is supported by the host operating system. + Examples: "ext4", "xfs", "ntfs". Implicitly inferred + to be "ext4" if unspecified. More info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk + TODO: how do we prevent errors in the filesystem + from compromising the machine' + type: string + partition: + description: 'partition is the partition in the + volume that you want to mount. If omitted, the + default is to mount by volume name. Examples: + For volume /dev/sda1, you specify the partition + as "1". Similarly, the volume partition for /dev/sda + is "0" (or you can leave the property empty). + More info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk' + format: int32 + type: integer + pdName: + description: 'pdName is unique name of the PD resource + in GCE. Used to identify the disk in GCE. More + info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk' + type: string + readOnly: + description: 'readOnly here will force the ReadOnly + setting in VolumeMounts. Defaults to false. More + info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk' + type: boolean + required: + - pdName + type: object + gitRepo: + description: 'gitRepo represents a git repository at + a particular revision. DEPRECATED: GitRepo is deprecated. + To provision a container with a git repo, mount an + EmptyDir into an InitContainer that clones the repo + using git, then mount the EmptyDir into the Pod''s + container.' + properties: + directory: + description: directory is the target directory name. + Must not contain or start with '..'. If '.' is + supplied, the volume directory will be the git + repository. Otherwise, if specified, the volume + will contain the git repository in the subdirectory + with the given name. + type: string + repository: + description: repository is the URL + type: string + revision: + description: revision is the commit hash for the + specified revision. + type: string + required: + - repository + type: object + glusterfs: + description: 'glusterfs represents a Glusterfs mount + on the host that shares a pod''s lifetime. More info: + https://examples.k8s.io/volumes/glusterfs/README.md' + properties: + endpoints: + description: 'endpoints is the endpoint name that + details Glusterfs topology. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod' + type: string + path: + description: 'path is the Glusterfs volume path. + More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod' + type: string + readOnly: + description: 'readOnly here will force the Glusterfs + volume to be mounted with read-only permissions. + Defaults to false. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod' + type: boolean + required: + - endpoints + - path + type: object + hostPath: + description: 'hostPath represents a pre-existing file + or directory on the host machine that is directly + exposed to the container. This is generally used for + system agents or other privileged things that are + allowed to see the host machine. Most containers will + NOT need this. More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath + --- TODO(jonesdl) We need to restrict who can use + host directory mounts and who can/can not mount host + directories as read/write.' + properties: + path: + description: 'path of the directory on the host. + If the path is a symlink, it will follow the link + to the real path. More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath' + type: string + type: + description: 'type for HostPath Volume Defaults + to "" More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath' + type: string + required: + - path + type: object + iscsi: + description: 'iscsi represents an ISCSI Disk resource + that is attached to a kubelet''s host machine and + then exposed to the pod. More info: https://examples.k8s.io/volumes/iscsi/README.md' + properties: + chapAuthDiscovery: + description: chapAuthDiscovery defines whether support + iSCSI Discovery CHAP authentication + type: boolean + chapAuthSession: + description: chapAuthSession defines whether support + iSCSI Session CHAP authentication + type: boolean + fsType: + description: 'fsType is the filesystem type of the + volume that you want to mount. Tip: Ensure that + the filesystem type is supported by the host operating + system. Examples: "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. More info: + https://kubernetes.io/docs/concepts/storage/volumes#iscsi + TODO: how do we prevent errors in the filesystem + from compromising the machine' + type: string + initiatorName: + description: initiatorName is the custom iSCSI Initiator + Name. If initiatorName is specified with iscsiInterface + simultaneously, new iSCSI interface : will be created for the connection. + type: string + iqn: + description: iqn is the target iSCSI Qualified Name. + type: string + iscsiInterface: + description: iscsiInterface is the interface Name + that uses an iSCSI transport. Defaults to 'default' + (tcp). + type: string + lun: + description: lun represents iSCSI Target Lun number. + format: int32 + type: integer + portals: + description: portals is the iSCSI Target Portal + List. The portal is either an IP or ip_addr:port + if the port is other than default (typically TCP + ports 860 and 3260). + items: + type: string + type: array + readOnly: + description: readOnly here will force the ReadOnly + setting in VolumeMounts. Defaults to false. + type: boolean + secretRef: + description: secretRef is the CHAP Secret for iSCSI + target and initiator authentication + 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 + targetPortal: + description: targetPortal is iSCSI Target Portal. + The Portal is either an IP or ip_addr:port if + the port is other than default (typically TCP + ports 860 and 3260). + type: string + required: + - iqn + - lun + - targetPortal + type: object + name: + description: 'name of the volume. Must be a DNS_LABEL + and unique within the pod. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + nfs: + description: 'nfs represents an NFS mount on the host + that shares a pod''s lifetime More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs' + properties: + path: + description: 'path that is exported by the NFS server. + More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs' + type: string + readOnly: + description: 'readOnly here will force the NFS export + to be mounted with read-only permissions. Defaults + to false. More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs' + type: boolean + server: + description: 'server is the hostname or IP address + of the NFS server. More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs' + type: string + required: + - path + - server + type: object + persistentVolumeClaim: + description: 'persistentVolumeClaimVolumeSource represents + a reference to a PersistentVolumeClaim in the same + namespace. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims' + properties: + claimName: + description: 'claimName is the name of a PersistentVolumeClaim + in the same namespace as the pod using this volume. + More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims' + type: string + readOnly: + description: readOnly Will force the ReadOnly setting + in VolumeMounts. Default false. + type: boolean + required: + - claimName + type: object + photonPersistentDisk: + description: photonPersistentDisk represents a PhotonController + persistent disk attached and mounted on kubelets host + machine + properties: + fsType: + description: fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. + type: string + pdID: + description: pdID is the ID that identifies Photon + Controller persistent disk + type: string + required: + - pdID + type: object + portworxVolume: + description: portworxVolume represents a portworx volume + attached and mounted on kubelets host machine + properties: + fsType: + description: fSType represents the filesystem type + to mount Must be a filesystem type supported by + the host operating system. Ex. "ext4", "xfs". + Implicitly inferred to be "ext4" if unspecified. + type: string + readOnly: + description: readOnly defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + volumeID: + description: volumeID uniquely identifies a Portworx + volume + type: string + required: + - volumeID + type: object + projected: + description: projected items for all in one resources + secrets, configmaps, and downward API + properties: + defaultMode: + description: defaultMode are the mode bits used + to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or + a decimal value between 0 and 511. YAML accepts + both octal and decimal values, JSON requires decimal + values for mode bits. Directories within the path + are not affected by this setting. This might be + in conflict with other options that affect the + file mode, like fsGroup, and the result can be + other mode bits set. + format: int32 + type: integer + sources: + description: sources is the list of volume projections + items: + description: Projection that may be projected + along with other supported volume types + properties: + configMap: + description: configMap information about the + configMap data to project + properties: + items: + description: items if unspecified, each + key-value pair in the Data field of + the referenced ConfigMap will be projected + into the volume as a file whose name + is the key and content is the value. + If specified, the listed keys will be + projected into the specified paths, + and unlisted keys will not be present. + If a key is specified which is not present + in the ConfigMap, the volume setup will + error unless it is marked optional. + Paths must be relative and may not contain + the '..' path or start with '..'. + items: + description: Maps a string key to a + path within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: 'mode is Optional: + mode bits used to set permissions + on this file. Must be an octal + value between 0000 and 0777 or + a decimal value between 0 and + 511. YAML accepts both octal and + decimal values, JSON requires + decimal values for mode bits. + If not specified, the volume defaultMode + will be used. This might be in + conflict with other options that + affect the file mode, like fsGroup, + and the result can be other mode + bits set.' + format: int32 + type: integer + path: + description: path is the relative + path of the file to map the key + to. May not be an absolute path. + May not contain the path element + '..'. May not start with the string + '..'. + type: string + required: + - key + - path + type: object + type: array + 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 + optional: + description: optional specify whether + the ConfigMap or its keys must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + downwardAPI: + description: downwardAPI information about + the downwardAPI data to project + properties: + items: + description: Items is a list of DownwardAPIVolume + file + items: + description: DownwardAPIVolumeFile represents + information to create the file containing + the pod field + properties: + fieldRef: + description: 'Required: Selects + a field of the pod: only annotations, + labels, name and namespace are + supported.' + properties: + apiVersion: + description: Version of the + schema the FieldPath is written + in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field + to select in the specified + API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + mode: + description: 'Optional: mode bits + used to set permissions on this + file, must be an octal value between + 0000 and 0777 or a decimal value + between 0 and 511. YAML accepts + both octal and decimal values, + JSON requires decimal values for + mode bits. If not specified, the + volume defaultMode will be used. + This might be in conflict with + other options that affect the + file mode, like fsGroup, and the + result can be other mode bits + set.' + format: int32 + type: integer + path: + description: 'Required: Path is the + relative path name of the file + to be created. Must not be absolute + or contain the ''..'' path. Must + be utf-8 encoded. The first item + of the relative path must not + start with ''..''' + type: string + resourceFieldRef: + description: 'Selects a resource + of the container: only resources + limits and requests (limits.cpu, + limits.memory, requests.cpu and + requests.memory) are currently + supported.' + properties: + containerName: + description: 'Container name: + required for volumes, optional + for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output + format of the exposed resources, + defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource + to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + required: + - path + type: object + type: array + type: object + secret: + description: secret information about the + secret data to project + properties: + items: + description: items if unspecified, each + key-value pair in the Data field of + the referenced Secret will be projected + into the volume as a file whose name + is the key and content is the value. + If specified, the listed keys will be + projected into the specified paths, + and unlisted keys will not be present. + If a key is specified which is not present + in the Secret, the volume setup will + error unless it is marked optional. + Paths must be relative and may not contain + the '..' path or start with '..'. + items: + description: Maps a string key to a + path within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: 'mode is Optional: + mode bits used to set permissions + on this file. Must be an octal + value between 0000 and 0777 or + a decimal value between 0 and + 511. YAML accepts both octal and + decimal values, JSON requires + decimal values for mode bits. + If not specified, the volume defaultMode + will be used. This might be in + conflict with other options that + affect the file mode, like fsGroup, + and the result can be other mode + bits set.' + format: int32 + type: integer + path: + description: path is the relative + path of the file to map the key + to. May not be an absolute path. + May not contain the path element + '..'. May not start with the string + '..'. + type: string + required: + - key + - path + type: object + type: array + 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 + optional: + description: optional field specify whether + the Secret or its key must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + serviceAccountToken: + description: serviceAccountToken is information + about the serviceAccountToken data to project + properties: + audience: + description: audience is the intended + audience of the token. A recipient of + a token must identify itself with an + identifier specified in the audience + of the token, and otherwise should reject + the token. The audience defaults to + the identifier of the apiserver. + type: string + expirationSeconds: + description: expirationSeconds is the + requested duration of validity of the + service account token. As the token + approaches expiration, the kubelet volume + plugin will proactively rotate the service + account token. The kubelet will start + trying to rotate the token if the token + is older than 80 percent of its time + to live or if the token is older than + 24 hours.Defaults to 1 hour and must + be at least 10 minutes. + format: int64 + type: integer + path: + description: path is the path relative + to the mount point of the file to project + the token into. + type: string + required: + - path + type: object + type: object + type: array + type: object + quobyte: + description: quobyte represents a Quobyte mount on the + host that shares a pod's lifetime + properties: + group: + description: group to map volume access to Default + is no group + type: string + readOnly: + description: readOnly here will force the Quobyte + volume to be mounted with read-only permissions. + Defaults to false. + type: boolean + registry: + description: registry represents a single or multiple + Quobyte Registry services specified as a string + as host:port pair (multiple entries are separated + with commas) which acts as the central registry + for volumes + type: string + tenant: + description: tenant owning the given Quobyte volume + in the Backend Used with dynamically provisioned + Quobyte volumes, value is set by the plugin + type: string + user: + description: user to map volume access to Defaults + to serivceaccount user + type: string + volume: + description: volume is a string that references + an already created Quobyte volume by name. + type: string + required: + - registry + - volume + type: object + rbd: + description: 'rbd represents a Rados Block Device mount + on the host that shares a pod''s lifetime. More info: + https://examples.k8s.io/volumes/rbd/README.md' + properties: + fsType: + description: 'fsType is the filesystem type of the + volume that you want to mount. Tip: Ensure that + the filesystem type is supported by the host operating + system. Examples: "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. More info: + https://kubernetes.io/docs/concepts/storage/volumes#rbd + TODO: how do we prevent errors in the filesystem + from compromising the machine' + type: string + image: + description: 'image is the rados image name. More + info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: string + keyring: + description: 'keyring is the path to key ring for + RBDUser. Default is /etc/ceph/keyring. More info: + https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: string + monitors: + description: 'monitors is a collection of Ceph monitors. + More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + items: + type: string + type: array + pool: + description: 'pool is the rados pool name. Default + is rbd. More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: string + readOnly: + description: 'readOnly here will force the ReadOnly + setting in VolumeMounts. Defaults to false. More + info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: boolean + secretRef: + description: 'secretRef is name of the authentication + secret for RBDUser. If provided overrides keyring. + Default is nil. More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + 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 + user: + description: 'user is the rados user name. Default + is admin. More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: string + required: + - image + - monitors + type: object + scaleIO: + description: scaleIO represents a ScaleIO persistent + volume attached and mounted on Kubernetes nodes. + properties: + fsType: + description: fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Default + is "xfs". + type: string + gateway: + description: gateway is the host address of the + ScaleIO API Gateway. + type: string + protectionDomain: + description: protectionDomain is the name of the + ScaleIO Protection Domain for the configured storage. + type: string + readOnly: + description: readOnly Defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + secretRef: + description: secretRef references to the secret + for ScaleIO user and other sensitive information. + If this is not provided, Login operation will + fail. + 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 + sslEnabled: + description: sslEnabled Flag enable/disable SSL + communication with Gateway, default false + type: boolean + storageMode: + description: storageMode indicates whether the storage + for a volume should be ThickProvisioned or ThinProvisioned. + Default is ThinProvisioned. + type: string + storagePool: + description: storagePool is the ScaleIO Storage + Pool associated with the protection domain. + type: string + system: + description: system is the name of the storage system + as configured in ScaleIO. + type: string + volumeName: + description: volumeName is the name of a volume + already created in the ScaleIO system that is + associated with this volume source. + type: string + required: + - gateway + - secretRef + - system + type: object + secret: + description: 'secret represents a secret that should + populate this volume. More info: https://kubernetes.io/docs/concepts/storage/volumes#secret' + properties: + defaultMode: + description: 'defaultMode is Optional: mode bits + used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or + a decimal value between 0 and 511. YAML accepts + both octal and decimal values, JSON requires decimal + values for mode bits. Defaults to 0644. Directories + within the path are not affected by this setting. + This might be in conflict with other options that + affect the file mode, like fsGroup, and the result + can be other mode bits set.' + format: int32 + type: integer + items: + description: items If unspecified, each key-value + pair in the Data field of the referenced Secret + will be projected into the volume as a file whose + name is the key and content is the value. If specified, + the listed keys will be projected into the specified + paths, and unlisted keys will not be present. + If a key is specified which is not present in + the Secret, the volume setup will error unless + it is marked optional. Paths must be relative + and may not contain the '..' path or start with + '..'. + items: + description: Maps a string key to a path within + a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: 'mode is Optional: mode bits + used to set permissions on this file. Must + be an octal value between 0000 and 0777 + or a decimal value between 0 and 511. YAML + accepts both octal and decimal values, JSON + requires decimal values for mode bits. If + not specified, the volume defaultMode will + be used. This might be in conflict with + other options that affect the file mode, + like fsGroup, and the result can be other + mode bits set.' + format: int32 + type: integer + path: + description: path is the relative path of + the file to map the key to. May not be an + absolute path. May not contain the path + element '..'. May not start with the string + '..'. + type: string + required: + - key + - path + type: object + type: array + optional: + description: optional field specify whether the + Secret or its keys must be defined + type: boolean + secretName: + description: 'secretName is the name of the secret + in the pod''s namespace to use. More info: https://kubernetes.io/docs/concepts/storage/volumes#secret' + type: string + type: object + storageos: + description: storageOS represents a StorageOS volume + attached and mounted on Kubernetes nodes. + properties: + fsType: + description: fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. + type: string + readOnly: + description: readOnly defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + secretRef: + description: secretRef specifies the secret to use + for obtaining the StorageOS API credentials. If + not specified, default values will be attempted. + 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 + volumeName: + description: volumeName is the human-readable name + of the StorageOS volume. Volume names are only + unique within a namespace. + type: string + volumeNamespace: + description: volumeNamespace specifies the scope + of the volume within StorageOS. If no namespace + is specified then the Pod's namespace will be + used. This allows the Kubernetes name scoping + to be mirrored within StorageOS for tighter integration. + Set VolumeName to any name to override the default + behaviour. Set to "default" if you are not using + namespaces within StorageOS. Namespaces that do + not pre-exist within StorageOS will be created. + type: string + type: object + vsphereVolume: + description: vsphereVolume represents a vSphere volume + attached and mounted on kubelets host machine + properties: + fsType: + description: fsType is filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. + type: string + storagePolicyID: + description: storagePolicyID is the storage Policy + Based Management (SPBM) profile ID associated + with the StoragePolicyName. + type: string + storagePolicyName: + description: storagePolicyName is the storage Policy + Based Management (SPBM) profile name. + type: string + volumePath: + description: volumePath is the path that identifies + vSphere volume vmdk + type: string + required: + - volumePath + type: object + required: + - name + type: object + type: array + required: + - containers + type: object + type: object + revisionHistoryLimit: + description: RevisionHistoryLimit is the number of revisions to retain + to allow rollback in the underlying StatefulSet. + format: int32 + type: integer + secureSettings: + description: SecureSettings is a list of references to Kubernetes + Secrets containing sensitive configuration options for the Logstash. + Secrets data can be then referenced in the Logstash config using + the Secret's keys or as specified in `Entries` field of each SecureSetting. + items: + description: SecretSource defines a data source based on a Kubernetes + Secret. + properties: + entries: + description: Entries define how to project each key-value pair + in the secret to filesystem paths. If not defined, all keys + will be projected to similarly named paths in the filesystem. + If defined, only the specified keys will be projected to the + corresponding paths. + items: + description: KeyToPath defines how to map a key in a Secret + object to a filesystem path. + properties: + key: + description: Key is the key contained in the secret. + type: string + path: + description: Path is the relative file path to map the + key to. Path must not be an absolute file path and must + not contain any ".." components. + type: string + required: + - key + type: object + type: array + secretName: + description: SecretName is the name of the secret. + type: string + required: + - secretName + type: object + type: array + serviceAccountName: + description: ServiceAccountName is used to check access from the current + resource to Elasticsearch resource in a different namespace. Can + only be used if ECK is enforcing RBAC on references. + type: string + version: + description: Version of the Logstash. + type: string + required: + - version + type: object + status: + description: LogstashStatus defines the observed state of Logstash + properties: + availableNodes: + format: int32 + type: integer + expectedNodes: + format: int32 + type: integer + observedGeneration: + description: ObservedGeneration is the most recent generation observed + for this Logstash instance. It corresponds to the metadata generation, + which is updated on mutation by the API Server. If the generation + observed in status diverges from the generation in metadata, the + Logstash controller has not yet processed the changes contained + in the Logstash specification. + format: int64 + type: integer + version: + description: 'Version of the stack resource currently running. During + version upgrades, multiple versions may run in parallel: this value + specifies the lowest version currently running.' + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/crds/v1/patches/kustomization.yaml b/config/crds/v1/patches/kustomization.yaml index f8dfffb0f8..60556c047d 100644 --- a/config/crds/v1/patches/kustomization.yaml +++ b/config/crds/v1/patches/kustomization.yaml @@ -70,4 +70,12 @@ patchesJson6902: kind: CustomResourceDefinition name: elasticmapsservers.maps.k8s.elastic.co path: maps-patches.yaml + # custom patches for Beat + - target: + group: apiextensions.k8s.io + version: v1 + kind: CustomResourceDefinition + name: logstashes.logstash.k8s.elastic.co + path: logstash-patches.yaml + diff --git a/config/crds/v1/patches/logstash-patches.yaml b/config/crds/v1/patches/logstash-patches.yaml new file mode 100644 index 0000000000..ce8f164770 --- /dev/null +++ b/config/crds/v1/patches/logstash-patches.yaml @@ -0,0 +1,7 @@ +# Using `kubectl apply` stores the complete CRD file as an annotation, +# which may be too big for the annotations size limit. +# One way to mitigate this problem is to remove the (huge) podTemplate properties from the CRD. +# It also avoids the problem of having any k8s-version specific field in the Pod schema, +# that would maybe not match the user's k8s version. +- op: remove + path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/podTemplate/properties diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml new file mode 100644 index 0000000000..530891e91a --- /dev/null +++ b/config/samples/logstash/logstash.yaml @@ -0,0 +1,27 @@ +apiVersion: elasticsearch.k8s.elastic.co/v1 +kind: Elasticsearch +metadata: + name: elasticsearch-sample +spec: + version: 8.6.1 + nodeSets: + - name: default + count: 1 + config: + node.store.allow_mmap: false +--- +apiVersion: logstash.k8s.elastic.co/v1alpha1 +kind: Logstash +metadata: + name: logstash-sample +spec: + count: 3 + version: 8.6.1 + config: + log.level: info + api.http.host: "0.0.0.0" + queue.type: memory + podTemplate: + spec: + containers: + - name: logstash diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 2bb647a6db..1870792dd2 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -203,6 +203,28 @@ webhooks: resources: - kibanas sideEffects: None +- admissionReviewVersions: + - v1 + - v1beta1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /validate-logstash-k8s-elastic-co-v1alpha1-logstash + failurePolicy: Ignore + matchPolicy: Exact + name: elastic-logstash-validation-v1alpha1.k8s.elastic.co + rules: + - apiGroups: + - logstash.k8s.elastic.co + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - logstashs + sideEffects: None - admissionReviewVersions: - v1alpha1 clientConfig: diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index ed9ff0e618..b9fab1fb80 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9093,6 +9093,602 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + labels: + app.kubernetes.io/instance: '{{ .Release.Name }}' + app.kubernetes.io/managed-by: '{{ .Release.Service }}' + app.kubernetes.io/name: '{{ include "eck-operator-crds.name" . }}' + app.kubernetes.io/version: '{{ .Chart.AppVersion }}' + helm.sh/chart: '{{ include "eck-operator-crds.chart" . }}' + name: logstashes.logstash.k8s.elastic.co +spec: + group: logstash.k8s.elastic.co + names: + categories: + - elastic + kind: Logstash + listKind: LogstashList + plural: logstashes + shortNames: + - ls + singular: logstash + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Available nodes + jsonPath: .status.availableNodes + name: available + type: integer + - description: Expected nodes + jsonPath: .status.expectedNodes + name: expected + type: integer + - jsonPath: .metadata.creationTimestamp + name: age + type: date + - description: Logstash version + jsonPath: .status.version + name: version + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Logstash is the Schema for the logstashes 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: LogstashSpec defines the desired state of Logstash + properties: + config: + description: Config holds the Logstash configuration. At most one + of [`Config`, `ConfigRef`] can be specified. + type: object + x-kubernetes-preserve-unknown-fields: true + configRef: + description: ConfigRef contains a reference to an existing Kubernetes + Secret holding the Logstash configuration. Logstash settings must + be specified as yaml, under a single "logstash.yml" entry. At most + one of [`Config`, `ConfigRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + count: + format: int32 + type: integer + http: + description: HTTP holds the HTTP layer configuration for the Agent + in Fleet mode with Fleet Server enabled. + properties: + service: + description: Service defines the template for the associated Kubernetes + Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. The + name and namespace provided here are managed by ECK and + will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may be + set to "false" if the cluster load-balancer does not + rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests will + be respected, regardless of this field. This field may + only be set for services with type LoadBalancer and + will be cleared if the type is changed to any other + type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is specified + manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This field + may not be changed through updates unless the type field + is also being changed to ExternalName (which requires + this field to be blank) or the type field is being changed + from ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + "None", empty string (""), or a valid IP address. Setting + this to "None" makes a "headless service" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range (as + per system configuration), and is not in use, it will + be allocated to the service; otherwise creation of the + service will fail. This field may not be changed through + updates unless the type field is also being changed + to ExternalName (which requires this field to be empty) + or the type field is being changed from ExternalName + (in which case this field may optionally be specified, + as describe above). Valid values are \"None\", empty + string (\"\"), or a valid IP address. Setting this + to \"None\" makes a \"headless service\" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. If this field is not + specified, it will be initialized from the clusterIP + field. If this field is specified, clients must ensure + that clusterIPs[0] and clusterIP have the same value. + \n This field may hold a maximum of two entries (dual-stack + IPs, in either order). These IPs must correspond to + the values of the ipFamilies field. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy field. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes system. + items: + type: string + type: array + externalName: + description: externalName is the external reference that + discovery mechanisms will return as an alias for this + service (e.g. a DNS CNAME record). No proxying will + be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires `type` + to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of the + Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that assumes + that external load balancers will take care of balancing + the service traffic between nodes, and so each node + will deliver traffic only to the node-local endpoints + of the service, without masquerading the client source + IP. (Traffic mistakenly sent to a node with no endpoints + will be dropped.) The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + Note that traffic sent to an External IP or LoadBalancer + IP from within the cluster will always get "Cluster" + semantics, but clients sending to a NodePort from within + the cluster may need to take traffic policy into account + when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External systems + (e.g. load-balancers) can use this port to determine + if a given node holds endpoints for this service or + not. If this field is specified when creating a Service + which does not need it, creation will fail. This field + will be wiped when updating a Service to no longer need + it (e.g. changing type). This field cannot be updated + once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods only + want to talk to endpoints of the service on the same + node as the pod, dropping the traffic if there are no + local endpoints. The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the cluster, + and ipFamilyPolicy allows it, it will be used; otherwise + creation of the service will fail. This field is conditionally + mutable: it allows for adding or removing a secondary + IP family, but it does not allow changing the primary + IP family of the Service. Valid values are \"IPv4\" + and \"IPv6\". This field only applies to Services of + types ClusterIP, NodePort, and LoadBalancer, and does + apply to \"headless\" services. This field will be wiped + when updating a Service to type ExternalName. \n This + field may hold a maximum of two entries (dual-stack + families, in either order). These families must correspond + to the values of the clusterIPs field, if specified. + Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is no + value provided, then this field will be set to SingleStack. + Services can be "SingleStack" (a single IP family), + "PreferDualStack" (two IP families on dual-stack configured + clusters or a single IP family on single-stack clusters), + or "RequireDualStack" (two IP families on dual-stack + configured clusters, otherwise fail). The ipFamilies + and clusterIPs fields depend on the value of this field. + This field will be wiped when updating a service to + type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set when + the Service type is 'LoadBalancer'. If not set, the + default load balancer implementation is used, today + this is typically done through the cloud provider integration, + but should apply for any default implementation. If + set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated to + a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load balancer + is created. This field will be ignored if the cloud-provider + does not support the feature. Deprecated: This field + was under-specified and its meaning varies across implementations, + and it cannot support dual-stack. As of Kubernetes v1.24, + users are encouraged to use implementation-specific + annotations when available. This field may be removed + in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified client + IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by this + service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this port. + This field follows standard Kubernetes label syntax. + Un-prefixed names are reserved for IANA standard + service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the service. + This must be a DNS_LABEL. All ports within a ServiceSpec + must have unique names. When considering the endpoints + for a Service, this must match the 'name' field + in the EndpointPort. Optional if only one ServicePort + is defined on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or LoadBalancer. Usually + assigned by the system. If a value is specified, + in-range, and not in use it will be used, otherwise + the operation will fail. If not specified, a + port will be allocated if this Service requires + one. If this field is specified when creating + a Service which does not need it, creation will + fail. This field will be wiped when updating a + Service to no longer need it (e.g. changing type + from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by this + service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number must + be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + If this is a string, it will be looked up as a + named port in the target Pod''s container ports. + If this is not specified, the value of the ''port'' + field is used (an identity map). This field is + ignored for services with clusterIP=None, and + should be omitted or set equal to the ''port'' + field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that any + agent which deals with endpoints for this Service should + disregard any indications of ready/not-ready. The primary + use case for setting this field is for a StatefulSet's + Headless Service to propagate SRV DNS records for its + Pods for the purpose of peer discovery. The Kubernetes + controllers that generate Endpoints and EndpointSlice + resources for Services interpret this to mean that all + endpoints are considered "ready" even if the Pods themselves + are not. Agents which consume only Kubernetes generated + endpoints through the Endpoints or EndpointSlice resources + can safely assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. More + info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based session + affinity. Must be ClientIP or None. Defaults to None. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The value + must be >0 && <=86400(for 1 day) if ServiceAffinity + == "ClientIP". Default value is 10800(for 3 + hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates + a cluster-internal IP address for load-balancing to + endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints rather + than a virtual IP. "NodePort" builds on ClusterIP and + allocates a port on every node which routes to the same + endpoints as the clusterIP. "LoadBalancer" builds on + NodePort and creates an external load-balancer (if supported + in the current cloud) which routes to the same endpoints + as the clusterIP. "ExternalName" aliases this service + to the specified externalName. Several other fields + do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes secret + that contains the certificate and private key for enabling + TLS. The referenced secret should contain the following: + \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: + The certificate (or a chain). - `tls.key`: The private key + to the first certificate in the certificate chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + image: + description: Image is the Logstash Docker image to deploy. Version + and Type have to match the Logstash in the image. + type: string + podTemplate: + description: PodTemplate provides customisation options for the Logstash + pods. + type: object + revisionHistoryLimit: + description: RevisionHistoryLimit is the number of revisions to retain + to allow rollback in the underlying StatefulSet. + format: int32 + type: integer + secureSettings: + description: SecureSettings is a list of references to Kubernetes + Secrets containing sensitive configuration options for the Logstash. + Secrets data can be then referenced in the Logstash config using + the Secret's keys or as specified in `Entries` field of each SecureSetting. + items: + description: SecretSource defines a data source based on a Kubernetes + Secret. + properties: + entries: + description: Entries define how to project each key-value pair + in the secret to filesystem paths. If not defined, all keys + will be projected to similarly named paths in the filesystem. + If defined, only the specified keys will be projected to the + corresponding paths. + items: + description: KeyToPath defines how to map a key in a Secret + object to a filesystem path. + properties: + key: + description: Key is the key contained in the secret. + type: string + path: + description: Path is the relative file path to map the + key to. Path must not be an absolute file path and must + not contain any ".." components. + type: string + required: + - key + type: object + type: array + secretName: + description: SecretName is the name of the secret. + type: string + required: + - secretName + type: object + type: array + serviceAccountName: + description: ServiceAccountName is used to check access from the current + resource to Elasticsearch resource in a different namespace. Can + only be used if ECK is enforcing RBAC on references. + type: string + version: + description: Version of the Logstash. + type: string + required: + - version + type: object + status: + description: LogstashStatus defines the observed state of Logstash + properties: + availableNodes: + format: int32 + type: integer + expectedNodes: + format: int32 + type: integer + observedGeneration: + description: ObservedGeneration is the most recent generation observed + for this Logstash instance. It corresponds to the metadata generation, + which is updated on mutation by the API Server. If the generation + observed in status diverges from the generation in metadata, the + Logstash controller has not yet processed the changes contained + in the Logstash specification. + format: int64 + type: integer + version: + description: 'Version of the stack resource currently running. During + version upgrades, multiple versions may run in parallel: this value + specifies the lowest version currently running.' + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.11.3 diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 04cdc02ee7..a06cf4cb7f 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -26,6 +26,7 @@ endif::[] - xref:{anchor_prefix}-enterprisesearch-k8s-elastic-co-v1beta1[$$enterprisesearch.k8s.elastic.co/v1beta1$$] - xref:{anchor_prefix}-kibana-k8s-elastic-co-v1[$$kibana.k8s.elastic.co/v1$$] - xref:{anchor_prefix}-kibana-k8s-elastic-co-v1beta1[$$kibana.k8s.elastic.co/v1beta1$$] +- xref:{anchor_prefix}-logstash-k8s-elastic-co-v1alpha1[$$logstash.k8s.elastic.co/v1alpha1$$] - xref:{anchor_prefix}-maps-k8s-elastic-co-v1alpha1[$$maps.k8s.elastic.co/v1alpha1$$] - xref:{anchor_prefix}-stackconfigpolicy-k8s-elastic-co-v1alpha1[$$stackconfigpolicy.k8s.elastic.co/v1alpha1$$] @@ -448,6 +449,7 @@ Config represents untyped YAML configuration. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-stackconfigpolicy-v1alpha1-indextemplates[$$IndexTemplates$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-nodeset[$$NodeSet$$] **** @@ -465,6 +467,7 @@ ConfigSource references configuration settings. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] **** @@ -491,6 +494,7 @@ HTTPConfig holds the HTTP layer configuration for resources. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] **** @@ -587,6 +591,7 @@ Monitoring holds references to both the metrics, and logs Elasticsearch clusters - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-elasticsearchspec[$$ElasticsearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] **** [cols="25a,75a", options="header"] @@ -611,6 +616,7 @@ ObjectSelector defines a reference to a Kubernetes object which can be an Elasti - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-logsmonitoring[$$LogsMonitoring$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-metricsmonitoring[$$MetricsMonitoring$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-agent-v1alpha1-output[$$Output$$] @@ -678,6 +684,7 @@ SecretSource defines a data source based on a Kubernetes Secret. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-elasticsearchspec[$$ElasticsearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-stackconfigpolicy-v1alpha1-stackconfigpolicyspec[$$StackConfigPolicySpec$$] **** @@ -1824,6 +1831,124 @@ KibanaSpec holds the specification of a Kibana instance. +[id="{anchor_prefix}-logstash-k8s-elastic-co-v1alpha1"] +== logstash.k8s.elastic.co/v1alpha1 + +Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API group + + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-deploymentspec"] +=== DeploymentSpec + + + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | +| *`replicas`* __integer__ | +| *`strategy`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#deploymentstrategy-v1-apps[$$DeploymentStrategy$$]__ | +|=== + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash"] +=== Logstash + +Logstash is the Schema for the logstashes API + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashlist[$$LogstashList$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`metadata`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#objectmeta-v1-meta[$$ObjectMeta$$]__ | Refer to Kubernetes API documentation for fields of `metadata`. + +| *`spec`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$]__ | +| *`status`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashstatus[$$LogstashStatus$$]__ | +|=== + + + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec"] +=== LogstashSpec + +LogstashSpec defines the desired state of Logstash + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash[$$Logstash$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`version`* __string__ | Version of the Logstash. +| *`elasticsearchRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-objectselector[$$ObjectSelector$$]__ | ElasticsearchRef is a reference to an Elasticsearch cluster running in the same Kubernetes cluster. +| *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. +| *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. +| *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. +| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelineRef`] can be specified. +| *`pipelineRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelineRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipeline must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelineRef`] can be specified. +| *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. +| *`serviceAccountName`* __string__ | ServiceAccountName is used to check access from the current resource to Elasticsearch resource in a different namespace. Can only be used if ECK is enforcing RBAC on references. +| *`deployment`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-deploymentspec[$$DeploymentSpec$$]__ | Deployment specifies the Logstash should be deployed as a Deployment, and allows providing its spec. Cannot be used along with `StatefulSet`. +| *`statefulSet`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-statefulsetspec[$$StatefulSetSpec$$]__ | StatefulSet specifies the Logstash should be deployed as a StatefulSet, and allows providing its spec. Cannot be used along with `Deployment`. +| *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying DaemonSet or Deployment. +| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Agent in Fleet mode with Fleet Server enabled. +| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. See https://www.elastic.co/guide/en/kibana/current/xpack-monitoring.html. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. +|=== + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashstatus"] +=== LogstashStatus + +LogstashStatus defines the observed state of Logstash + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash[$$Logstash$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`version`* __string__ | Version of the stack resource currently running. During version upgrades, multiple versions may run in parallel: this value specifies the lowest version currently running. +| *`expectedNodes`* __integer__ | +| *`availableNodes`* __integer__ | +| *`observedGeneration`* __integer__ | ObservedGeneration is the most recent generation observed for this Logstash instance. It corresponds to the metadata generation, which is updated on mutation by the API Server. If the generation observed in status diverges from the generation in metadata, the Logstash controller has not yet processed the changes contained in the Logstash specification. +|=== + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-statefulsetspec"] +=== StatefulSetSpec + + + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | +| *`replicas`* __integer__ | +| *`volumeClaimTemplates`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#persistentvolumeclaim-v1-core[$$PersistentVolumeClaim$$] array__ | VolumeClaimTemplates is a list of persistent volume claims to be used by each Pod in this NodeSet. Every claim in this list must have a matching volumeMount in one of the containers defined in the PodTemplate. Items defined here take precedence over any default claims added by the operator with the same name. +|=== + + + [id="{anchor_prefix}-maps-k8s-elastic-co-v1alpha1"] == maps.k8s.elastic.co/v1alpha1 diff --git a/hack/upgrade-test-harness/go.mod b/hack/upgrade-test-harness/go.mod index d659bcffff..992aa81d85 100644 --- a/hack/upgrade-test-harness/go.mod +++ b/hack/upgrade-test-harness/go.mod @@ -18,7 +18,6 @@ require ( ) require ( - cloud.google.com/go v0.99.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect diff --git a/hack/upgrade-test-harness/go.sum b/hack/upgrade-test-harness/go.sum index 25f26965c9..a557368861 100644 --- a/hack/upgrade-test-harness/go.sum +++ b/hack/upgrade-test-harness/go.sum @@ -13,20 +13,6 @@ cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKV cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= -cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= -cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= -cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= -cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= -cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= -cloud.google.com/go v0.83.0/go.mod h1:Z7MJUsANfY0pYPdw0lbnivPx4/vhy/e2FEkSkF7vAVY= -cloud.google.com/go v0.84.0/go.mod h1:RazrYuxIK6Kb7YrzzhPoLmCVzl7Sup4NrbKPg8KHSUM= -cloud.google.com/go v0.87.0/go.mod h1:TpDYlFy7vuLzZMMZ+B6iRiELaY7z/gJPaqbMx6mlWcY= -cloud.google.com/go v0.90.0/go.mod h1:kRX0mNRHe0e2rC6oNakvwQqzyDmg57xJ+SZU1eT2aDQ= -cloud.google.com/go v0.93.3/go.mod h1:8utlLll2EF5XMAV15woO4lSbWQlk8rer9aLOfLh7+YI= -cloud.google.com/go v0.94.1/go.mod h1:qAlAugsXlC+JWO+Bke5vCtc9ONxjQT3drlTTnAplMW4= -cloud.google.com/go v0.97.0/go.mod h1:GF7l59pYBVlXQIBLx3a761cZ41F9bBH3JUlihCt2Udc= -cloud.google.com/go v0.99.0 h1:y/cM2iqGgGi5D5DQZl6D9STN/3dR/Vx5Mp8s752oJTY= -cloud.google.com/go v0.99.0/go.mod h1:w0Xx2nLzqWJPuozYQX+hFfCSI8WioryfRDzkoI/Y2ZA= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= @@ -97,9 +83,7 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= @@ -127,10 +111,8 @@ github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v4.11.0+incompatible h1:glyUF9yIYtMHzn8xaKw5rMhdWcwsYV8dZHIq5567/xs= github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= @@ -190,8 +172,6 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -207,10 +187,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -224,7 +202,6 @@ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= @@ -234,8 +211,6 @@ github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= @@ -243,13 +218,6 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= @@ -258,8 +226,6 @@ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= -github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0eJc8R6ouapiM= github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU= github.com/googleapis/gnostic v0.5.5 h1:9fHAtK0uDfpveeqqo1hkEZJcFvYXAiCN3UutL8F9xHw= github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA= @@ -297,7 +263,6 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= @@ -488,8 +453,6 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0/go.mod h1:2AboqHi0CiIZU0qwhtUfCYD1GeUzvvIXWNkhDt7ZMG4= go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= @@ -545,7 +508,6 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -555,8 +517,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -594,14 +554,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d h1:LO7XpTYMwTqxjLcGWPijK3vRXg1aWdlNOVOHRq45d7c= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -610,16 +564,6 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg= golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -675,29 +619,14 @@ golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -765,18 +694,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= -golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -798,20 +717,6 @@ google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0M google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= -google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= -google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= -google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= -google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= -google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= -google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= -google.golang.org/api v0.51.0/go.mod h1:t4HdrdoNgyN5cbEfm7Lum0lcLDLiise1F8qDKX00sOU= -google.golang.org/api v0.54.0/go.mod h1:7C4bFFOvVDGXjfDTAsgGwDgAxRDeQ4X8NvUedIt6z3k= -google.golang.org/api v0.55.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= -google.golang.org/api v0.56.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= -google.golang.org/api v0.57.0/go.mod h1:dVPlbZyBo2/OjBpmvNdpn2GRm6rPy75jyU7bmhdrMgI= -google.golang.org/api v0.61.0/go.mod h1:xQRti5UdCmoCEqFxcz93fTl338AVqDgyaDRuOZ3hg9I= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -850,35 +755,8 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= -google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= -google.golang.org/genproto v0.0.0-20210713002101-d411969a0d9a/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= -google.golang.org/genproto v0.0.0-20210716133855-ce7ef5c701ea/go.mod h1:AxrInvYm1dci+enl5hChSFPOmmUF1+uAa/UsgNRWd7k= -google.golang.org/genproto v0.0.0-20210728212813-7823e685a01f/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= -google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= -google.golang.org/genproto v0.0.0-20210813162853-db860fec028c/go.mod h1:cFeNkxwySK631ADgubI+/XFU/xp8FD5KIVV4rj8UC5w= -google.golang.org/genproto v0.0.0-20210821163610-241b8fcbd6c8/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -892,20 +770,10 @@ google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKa google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= -google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= -google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= -google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/pkg/apis/common/v1/association.go b/pkg/apis/common/v1/association.go index 721055c273..8bcfaa2f23 100644 --- a/pkg/apis/common/v1/association.go +++ b/pkg/apis/common/v1/association.go @@ -110,6 +110,8 @@ const ( BeatAssociationType = "beat" BeatMonitoringAssociationType = "beat-monitoring" + LogstashMonitoringAssociationType = "ls-monitoring" + AssociationUnknown AssociationStatus = "" AssociationPending AssociationStatus = "Pending" AssociationEstablished AssociationStatus = "Established" diff --git a/pkg/apis/logstash/v1alpha1/doc.go b/pkg/apis/logstash/v1alpha1/doc.go new file mode 100644 index 0000000000..a92dd08678 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/doc.go @@ -0,0 +1,11 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +// Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API group +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=github.com/elastic/cloud-on-k8s/pkg/apis/logstash +// +k8s:defaulter-gen=TypeMeta +// +groupName=logstash.k8s.elastic.co +package v1alpha1 diff --git a/pkg/apis/logstash/v1alpha1/groupversion_info.go b/pkg/apis/logstash/v1alpha1/groupversion_info.go new file mode 100644 index 0000000000..5589c3a240 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/groupversion_info.go @@ -0,0 +1,21 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "logstash.k8s.elastic.co", Version: "v1alpha1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} + + // AddToScheme is required by pkg/client/... + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/pkg/apis/logstash/v1alpha1/labels.go b/pkg/apis/logstash/v1alpha1/labels.go new file mode 100644 index 0000000000..70e5fa8cf5 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/labels.go @@ -0,0 +1,17 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" +) + +// GetIdentityLabels will return the common Elastic assigned labels for Logstash +func (logstash* Logstash) GetIdentityLabels() map[string]string { + return map[string]string{ + commonv1.TypeLabelName: "logstash", + "logstash.k8s.elastic.co/name": logstash.Name, + } +} diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go new file mode 100644 index 0000000000..d948fd2b96 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -0,0 +1,130 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + // Kind is inferred from the struct name using reflection in SchemeBuilder.Register() + // we duplicate it as a constant here for practical purposes. + Kind = "Logstash" +) + +// LogstashSpec defines the desired state of Logstash +type LogstashSpec struct { + // Version of the Logstash. + Version string `json:"version"` + + Count int32 `json:"count,omitempty"` + + // Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. + // +kubebuilder:validation:Optional + Image string `json:"image,omitempty"` + + // Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. + // +kubebuilder:validation:Optional + // +kubebuilder:pruning:PreserveUnknownFields + Config *commonv1.Config `json:"config,omitempty"` + + // ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. + // Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] + // can be specified. + // +kubebuilder:validation:Optional + ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"` + + // PodTemplate provides customisation options for the Logstash pods. + PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` + + // SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. + // Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of + // each SecureSetting. + // +kubebuilder:validation:Optional + SecureSettings []commonv1.SecretSource `json:"secureSettings,omitempty"` + + // ServiceAccountName is used to check access from the current resource to Elasticsearch resource in a different namespace. + // Can only be used if ECK is enforcing RBAC on references. + // +kubebuilder:validation:Optional + ServiceAccountName string `json:"serviceAccountName,omitempty"` + + // RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. + RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` + + // HTTP holds the HTTP layer configuration for the Agent in Fleet mode with Fleet Server enabled. + // +kubebuilder:validation:Optional + HTTP commonv1.HTTPConfig `json:"http,omitempty"` +} + +// LogstashStatus defines the observed state of Logstash +type LogstashStatus struct { + // Version of the stack resource currently running. During version upgrades, multiple versions may run + // in parallel: this value specifies the lowest version currently running. + Version string `json:"version,omitempty"` + + // +kubebuilder:validation:Optional + ExpectedNodes int32 `json:"expectedNodes,omitempty"` + // +kubebuilder:validation:Optional + AvailableNodes int32 `json:"availableNodes,omitempty"` + + // ObservedGeneration is the most recent generation observed for this Logstash instance. + // It corresponds to the metadata generation, which is updated on mutation by the API Server. + // If the generation observed in status diverges from the generation in metadata, the Logstash + // controller has not yet processed the changes contained in the Logstash specification. + ObservedGeneration int64 `json:"observedGeneration,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Logstash is the Schema for the logstashes API +// +k8s:openapi-gen=true +// +kubebuilder:resource:categories=elastic,shortName=ls +// +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="available",type="integer",JSONPath=".status.availableNodes",description="Available nodes" +// +kubebuilder:printcolumn:name="expected",type="integer",JSONPath=".status.expectedNodes",description="Expected nodes" +// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Logstash version" +// +kubebuilder:storageversion +type Logstash struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec LogstashSpec `json:"spec,omitempty"` + Status LogstashStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// LogstashList contains a list of Logstash +type LogstashList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Logstash `json:"items"` +} + + +func (l *Logstash) ServiceAccountName() string { + return l.Spec.ServiceAccountName +} + +func (l *Logstash) SecureSettings() []commonv1.SecretSource { + return l.Spec.SecureSettings +} + +// IsMarkedForDeletion returns true if the Logstash is going to be deleted +func (l *Logstash) IsMarkedForDeletion() bool { + return !l.DeletionTimestamp.IsZero() +} + +// GetObservedGeneration will return the observedGeneration from the Elastic Logstash's status. +func (l *Logstash) GetObservedGeneration() int64 { + return l.Status.ObservedGeneration +} + +func init() { + SchemeBuilder.Register(&Logstash{}, &LogstashList{}) +} diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go new file mode 100644 index 0000000000..84a9692840 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -0,0 +1,36 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + common_name "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/name" +) + +const ( + httpServiceSuffix = "http" + configSuffix = "config" +) + +// Namer is a Namer that is configured with the defaults for resources related to an Agent resource. +var Namer = common_name.NewNamer("ls") + +// ConfigSecretName returns the name of a secret used to storage Logstash configuration data. +func ConfigSecretName(name string) string { + return Namer.Suffix(name, configSuffix) +} + +func ConfigMapName(name string) string { + return Namer.Suffix(name, "configmap") +} + +// Name returns the name of Logstash. +func Name(name string) string { + return Namer.Suffix(name) +} + +// HTTPServiceName returns the name of the HTTP service for a given Logstash name. +func HTTPServiceName(name string) string { + return Namer.Suffix(name, httpServiceSuffix) +} diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go new file mode 100644 index 0000000000..019b482c04 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -0,0 +1,56 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/util/validation/field" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" +) + +var ( + defaultChecks = []func(*Logstash) field.ErrorList{ + checkNoUnknownFields, + checkNameLength, + checkSupportedVersion, + checkSingleConfigSource, + } + + updateChecks = []func(old, curr *Logstash) field.ErrorList{ + checkNoDowngrade, + } +) + +func checkNoUnknownFields(a *Logstash) field.ErrorList { + return commonv1.NoUnknownFields(a, a.ObjectMeta) +} + +func checkNameLength(a *Logstash) field.ErrorList { + return commonv1.CheckNameLength(a) +} + +func checkSupportedVersion(a *Logstash) field.ErrorList { + return commonv1.CheckSupportedStackVersion(a.Spec.Version, version.SupportedLogstashVersions) +} + +func checkNoDowngrade(prev, curr *Logstash) field.ErrorList { + if commonv1.IsConfiguredToAllowDowngrades(curr) { + return nil + } + return commonv1.CheckNoDowngrade(prev.Spec.Version, curr.Spec.Version) +} + +func checkSingleConfigSource(a *Logstash) field.ErrorList { + if a.Spec.Config != nil && a.Spec.ConfigRef != nil { + msg := "Specify at most one of [`config`, `configRef`], not both" + return field.ErrorList{ + field.Forbidden(field.NewPath("spec").Child("config"), msg), + field.Forbidden(field.NewPath("spec").Child("configRef"), msg), + } + } + + return nil +} \ No newline at end of file diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go new file mode 100644 index 0000000000..1f9bed70b4 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -0,0 +1,88 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "errors" + + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" + "sigs.k8s.io/controller-runtime/pkg/webhook" + + ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" +) + +const ( + // webhookPath is the HTTP path for the Elastic Logstash validating webhook. + webhookPath = "/validate-logstash-k8s-elastic-co-v1alpha1-logstash" +) + +var ( + groupKind = schema.GroupKind{Group: SchemeGroupVersion.Group, Kind: Kind} + validationLog = ulog.Log.WithName("logstash-v1alpha1-validation") +) + +// +kubebuilder:webhook:path=/validate-logstash-k8s-elastic-co-v1alpha1-logstash,mutating=false,failurePolicy=ignore,groups=logstash.k8s.elastic.co,resources=logstashs,verbs=create;update,versions=v1alpha1,name=elastic-logstash-validation-v1alpha1.k8s.elastic.co,sideEffects=None,admissionReviewVersions=v1;v1beta1,matchPolicy=Exact + +var _ webhook.Validator = &Logstash{} + +// ValidateCreate is called by the validating webhook to validate the create operation. +// Satisfies the webhook.Validator interface. +func (a *Logstash) ValidateCreate() error { + validationLog.V(1).Info("Validate create", "name", a.Name) + return a.validate(nil) +} + +// ValidateDelete is called by the validating webhook to validate the delete operation. +// Satisfies the webhook.Validator interface. +func (a *Logstash) ValidateDelete() error { + validationLog.V(1).Info("Validate delete", "name", a.Name) + return nil +} + +// ValidateUpdate is called by the validating webhook to validate the update operation. +// Satisfies the webhook.Validator interface. +func (a *Logstash) ValidateUpdate(old runtime.Object) error { + validationLog.V(1).Info("Validate update", "name", a.Name) + oldObj, ok := old.(*Logstash) + if !ok { + return errors.New("cannot cast old object to Logstash type") + } + + return a.validate(oldObj) +} + +// WebhookPath returns the HTTP path used by the validating webhook. +func (a *Logstash) WebhookPath() string { + return webhookPath +} + +func (a *Logstash) validate(old *Logstash) error { + var errors field.ErrorList + if old != nil { + for _, uc := range updateChecks { + if err := uc(old, a); err != nil { + errors = append(errors, err...) + } + } + + if len(errors) > 0 { + return apierrors.NewInvalid(groupKind, a.Name, errors) + } + } + + for _, dc := range defaultChecks { + if err := dc(a); err != nil { + errors = append(errors, err...) + } + } + + if len(errors) > 0 { + return apierrors.NewInvalid(groupKind, a.Name, errors) + } + return nil +} diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 0000000000..cf5c388da8 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,127 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Logstash) DeepCopyInto(out *Logstash) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Logstash. +func (in *Logstash) DeepCopy() *Logstash { + if in == nil { + return nil + } + out := new(Logstash) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Logstash) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashList) DeepCopyInto(out *LogstashList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Logstash, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashList. +func (in *LogstashList) DeepCopy() *LogstashList { + if in == nil { + return nil + } + out := new(LogstashList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *LogstashList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { + *out = *in + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = (*in).DeepCopy() + } + if in.ConfigRef != nil { + in, out := &in.ConfigRef, &out.ConfigRef + *out = new(v1.ConfigSource) + **out = **in + } + in.PodTemplate.DeepCopyInto(&out.PodTemplate) + if in.SecureSettings != nil { + in, out := &in.SecureSettings, &out.SecureSettings + *out = make([]v1.SecretSource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.RevisionHistoryLimit != nil { + in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit + *out = new(int32) + **out = **in + } + in.HTTP.DeepCopyInto(&out.HTTP) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashSpec. +func (in *LogstashSpec) DeepCopy() *LogstashSpec { + if in == nil { + return nil + } + out := new(LogstashSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashStatus) DeepCopyInto(out *LogstashStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashStatus. +func (in *LogstashStatus) DeepCopy() *LogstashStatus { + if in == nil { + return nil + } + out := new(LogstashStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/controller/common/container/container.go b/pkg/controller/common/container/container.go index 1730738122..5056dcc4cc 100644 --- a/pkg/controller/common/container/container.go +++ b/pkg/controller/common/container/container.go @@ -40,6 +40,7 @@ const ( PacketbeatImage Image = "beats/packetbeat" AgentImage Image = "beats/elastic-agent" MapsImage Image = "elastic-maps-service/elastic-maps-server-ubi8" + LogstashImage Image = "logstash/logstash" ) // ImageRepository returns the full container image name by concatenating the current container registry and the image path with the given version. diff --git a/pkg/controller/common/container/defaulter.go b/pkg/controller/common/container/defaulter.go index c007b0be79..0b03d42aa0 100644 --- a/pkg/controller/common/container/defaulter.go +++ b/pkg/controller/common/container/defaulter.go @@ -96,6 +96,13 @@ func (d Defaulter) WithReadinessProbe(readinessProbe *corev1.Probe) Defaulter { return d } +func (d Defaulter) WithLivenessProbe(livenessProbe *corev1.Probe) Defaulter { + if d.base.LivenessProbe == nil { + d.base.LivenessProbe = livenessProbe + } + return d +} + // envExists checks if an env var with the given name already exists in the provided slice. func (d Defaulter) envExists(name string) bool { for _, v := range d.base.Env { diff --git a/pkg/controller/common/defaults/pod_template.go b/pkg/controller/common/defaults/pod_template.go index 81cfea9331..073223a0c0 100644 --- a/pkg/controller/common/defaults/pod_template.go +++ b/pkg/controller/common/defaults/pod_template.go @@ -121,6 +121,12 @@ func (b *PodTemplateBuilder) WithReadinessProbe(readinessProbe corev1.Probe) *Po return b } +// WithLivenessProbe sets up the given liveness probe, unless already provided in the template. +func (b *PodTemplateBuilder) WithLivenessProbe(livenessProbe corev1.Probe) *PodTemplateBuilder { + b.containerDefaulter.WithLivenessProbe(&livenessProbe) + return b +} + // WithAffinity sets a default affinity, unless already provided in the template. // An empty affinity in the spec is not overridden. func (b *PodTemplateBuilder) WithAffinity(affinity *corev1.Affinity) *PodTemplateBuilder { diff --git a/pkg/controller/common/scheme/scheme.go b/pkg/controller/common/scheme/scheme.go index fb51fe2d66..69b4706966 100644 --- a/pkg/controller/common/scheme/scheme.go +++ b/pkg/controller/common/scheme/scheme.go @@ -5,6 +5,7 @@ package scheme import ( + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "sync" "k8s.io/apimachinery/pkg/runtime" @@ -55,6 +56,7 @@ func SetupScheme() { agentv1alpha1.AddToScheme, emsv1alpha1.AddToScheme, policyv1alpha1.AddToScheme, + logstashv1alpha1.AddToScheme, } mustAddSchemeOnce(&addToScheme, schemes) } @@ -72,6 +74,7 @@ func SetupV1beta1Scheme() { entv1beta1.AddToScheme, beatv1beta1.AddToScheme, agentv1alpha1.AddToScheme, + logstashv1alpha1.AddToScheme, } mustAddSchemeOnce(&addToSchemeV1beta1, schemes) } diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index 0b9e379a4f..9258310a74 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,6 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 3, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. diff --git a/pkg/controller/elasticsearch/user/roles.go b/pkg/controller/elasticsearch/user/roles.go index 4688dea3b1..dded5f09ce 100644 --- a/pkg/controller/elasticsearch/user/roles.go +++ b/pkg/controller/elasticsearch/user/roles.go @@ -42,6 +42,8 @@ const ( FleetAdminUserRole = "eck_fleet_admin_user_role" + LogstashUserRole = "eck_logstash_user_role_v80" + // V70 indicates version 7.0 V70 = "v70" @@ -147,6 +149,15 @@ var ( }, }, }, + LogstashUserRole: esclient.Role{ + Cluster: []string{"monitor", "manage_ilm", "manage_ml", "read_ilm", "cluster:admin/ingest/pipeline/get"}, + Indices: []esclient.IndexRole{ + { + Names: []string{"logstash-*"}, + Privileges: []string{"manage", "read", "create_doc", "view_index_metadata", "create_index"}, + }, + }, + }, } ) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go new file mode 100644 index 0000000000..c27b754c25 --- /dev/null +++ b/pkg/controller/logstash/config.go @@ -0,0 +1,123 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" + ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" + "hash" + apierrors "k8s.io/apimachinery/pkg/api/errors" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + +func reconcileConfig(params Params, configHash hash.Hash) *reconciler.Results { + defer tracing.Span(¶ms.Context)() + results := reconciler.NewResult(params.Context) + + cfgBytes, err := buildConfig(params) + if err != nil { + return results.WithError(err) + } + + expected := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: params.Logstash.Namespace, + Name: logstashv1alpha1.ConfigSecretName(params.Logstash.Name), + Labels: labels.AddCredentialsLabel(params.Logstash.GetIdentityLabels()), + }, + Data: map[string][]byte{ + LogstashConfigFileName: cfgBytes, + }, + } + + if _, err = reconciler.ReconcileSecret(params.Context, params.Client, expected, ¶ms.Logstash); err != nil { + return results.WithError(err) + } + + _, _ = configHash.Write(cfgBytes) + + return results +} + +func buildConfig(params Params) ([]byte, error) { + existingCfg, err := getExistingConfig(params.Context, params.Client, params.Logstash) + if err != nil { + return nil, err + } + + userProvidedCfg, err := getUserConfig(params) + if err != nil { + return nil, err + } + + cfg, err := defaultConfig() + if err != nil { + return nil, err + } + + // merge with user settings last so they take precedence + if err = cfg.MergeWith(existingCfg, userProvidedCfg); err != nil { + return nil, err + } + + return cfg.Render() +} + +// getExistingConfig retrieves the canonical config, if one exists +func getExistingConfig(ctx context.Context, client k8s.Client, logstash logstashv1alpha1.Logstash) (*settings.CanonicalConfig, error) { + var secret corev1.Secret + key := types.NamespacedName{ + Namespace: logstash.Namespace, + Name: logstashv1alpha1.ConfigSecretName(logstash.Name), + } + err := client.Get(context.Background(), key, &secret) + if err != nil && apierrors.IsNotFound(err) { + ulog.FromContext(ctx).V(1).Info("Logstash config secret does not exist", "namespace", logstash.Namespace, "name", logstash.Name) + return nil, nil + } else if err != nil { + return nil, err + } + + rawCfg, exists := secret.Data[LogstashConfigFileName] + if !exists { + return nil, nil + } + + cfg, err := settings.ParseConfig(rawCfg) + if err != nil { + return nil, err + } + + return cfg, nil +} + +// getUserConfig extracts the config either from the spec `config` field or from the Secret referenced by spec +// `configRef` field. +func getUserConfig(params Params) (*settings.CanonicalConfig, error) { + if params.Logstash.Spec.Config != nil { + return settings.NewCanonicalConfigFrom(params.Logstash.Spec.Config.Data) + } + return common.ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.ConfigRef, LogstashConfigFileName) +} + +// TODO: remove testing value +func defaultConfig() (*settings.CanonicalConfig, error) { + settingsMap := map[string]interface{}{ + "node.name": "test", + } + + return settings.MustCanonicalConfig(settingsMap), nil +} \ No newline at end of file diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go new file mode 100644 index 0000000000..250473644b --- /dev/null +++ b/pkg/controller/logstash/driver.go @@ -0,0 +1,133 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + "hash/fnv" + + "github.com/go-logr/logr" + corev1 "k8s.io/api/core/v1" + "k8s.io/client-go/tools/record" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" +) + +// Params are a set of parameters used during internal reconciliation of Logstash. +type Params struct { + Context context.Context + + Client k8s.Client + EventRecorder record.EventRecorder + Watches watches.DynamicWatches + + Logstash logstashv1alpha1.Logstash + Status logstashv1alpha1.LogstashStatus + + OperatorParams operator.Parameters +} + +// K8sClient returns the Kubernetes client. +func (p Params) K8sClient() k8s.Client { + return p.Client +} + +// Recorder returns the Kubernetes event recorder. +func (p Params) Recorder() record.EventRecorder { + return p.EventRecorder +} + +// DynamicWatches returns the set of stateful dynamic watches used during reconciliation. +func (p Params) DynamicWatches() watches.DynamicWatches { + return p.Watches +} + +// GetPodTemplate returns the configured pod template for the associated Elastic Logstash. +func (p *Params) GetPodTemplate() corev1.PodTemplateSpec { + return p.Logstash.Spec.PodTemplate +} + +// Logger returns the configured logger for use during reconciliation. +func (p *Params) Logger() logr.Logger { + return log.FromContext(p.Context) +} + +func newStatus(logstash logstashv1alpha1.Logstash) logstashv1alpha1.LogstashStatus { + status := logstash.Status + status.ObservedGeneration = logstash.Generation + return status +} + +func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.LogstashStatus) { + defer tracing.Span(¶ms.Context)() + results := reconciler.NewResult(params.Context) + + svc, err := common.ReconcileService(params.Context, params.Client, newService(params.Logstash), ¶ms.Logstash) + if err != nil { + return results.WithError(err), params.Status + } + + _, results = certificates.Reconciler{ + K8sClient: params.Client, + DynamicWatches: params.Watches, + Owner: ¶ms.Logstash, + TLSOptions: params.Logstash.Spec.HTTP.TLS, + Namer: logstashv1alpha1.Namer, + Labels: params.Logstash.GetIdentityLabels(), + Services: []corev1.Service{*svc}, + GlobalCA: params.OperatorParams.GlobalCA, + CACertRotation: params.OperatorParams.CACertRotation, + CertRotation: params.OperatorParams.CertRotation, + GarbageCollectSecrets: true, + }.ReconcileCAAndHTTPCerts(params.Context) + if results.HasError() { + _, err := results.Aggregate() + k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + return results, params.Status + } + + configHash := fnv.New32a() + + if res := reconcileConfig(params, configHash); res.HasError() { + return results.WithResults(res), params.Status + } + + podTemplate, err := buildPodTemplate(params, configHash) + if err != nil { + return results.WithError(err), params.Status + } + return reconcileStatefulSet(params, podTemplate) +} + +func newService(logstash logstashv1alpha1.Logstash) *corev1.Service { + svc := corev1.Service{ + ObjectMeta: logstash.Spec.HTTP.Service.ObjectMeta, + Spec: logstash.Spec.HTTP.Service.Spec, + } + + svc.ObjectMeta.Namespace = logstash.Namespace + svc.ObjectMeta.Name = logstashv1alpha1.HTTPServiceName(logstash.Name) + + labels := logstash.GetIdentityLabels() + ports := []corev1.ServicePort{ + { + Name: logstash.Spec.HTTP.Protocol(), + Protocol: corev1.ProtocolTCP, + Port: network.HTTPPort, + }, + } + return defaults.SetServiceDefaults(&svc, labels, labels, ports) +} diff --git a/pkg/controller/logstash/init_configuration.go b/pkg/controller/logstash/init_configuration.go new file mode 100644 index 0000000000..a85b118568 --- /dev/null +++ b/pkg/controller/logstash/init_configuration.go @@ -0,0 +1,75 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" +) + +const ( + InitContainerConfigVolumeMountPath = "/mnt/elastic-internal/logstash-config-local" + InitConfigContainerName = "elastic-internal-init-config" + + // InitConfigScript is a small bash script to prepare the logstash configuration directory + InitConfigScript = `#!/usr/bin/env bash +set -eux + +init_config_initialized_flag=` + InitContainerConfigVolumeMountPath + `/elastic-internal-init-config.ok + +if [[ -f "${init_config_initialized_flag}" ]]; then + echo "Logstash configuration already initialized." + exit 0 +fi + +echo "Setup Logstash configuration" + +mount_path=` + InitContainerConfigVolumeMountPath + ` + +for f in /usr/share/logstash/config/*.*; do + filename=$(basename $f) + if [[ ! -f "$mount_path/$filename" ]]; then + cp $f $mount_path + fi +done + +touch "${init_config_initialized_flag}" +echo "Logstash configuration successfully prepared." +` +) + +// initConfigContainer returns an init container that executes a bash script to prepare the logstash config directory. +// The script copy config files from /use/share/logstash/config to /mnt/elastic-internal/logstash-config/ +// TODO may be able to solve env2yaml permission issue with initContainer +func initConfigContainer() corev1.Container { + privileged := false + + return corev1.Container{ + // Image will be inherited from pod template defaults + ImagePullPolicy: corev1.PullIfNotPresent, + Name: InitConfigContainerName, + SecurityContext: &corev1.SecurityContext{ + Privileged: &privileged, + }, + Command: []string{"/usr/bin/env", "bash", "-c", InitConfigScript}, + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: InitContainerConfigVolumeMountPath, + Name: ConfigVolumeName, + }, + }, + Resources: corev1.ResourceRequirements{ + Requests: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("50Mi"), + corev1.ResourceCPU: resource.MustParse("0.1"), + }, + Limits: map[corev1.ResourceName]resource.Quantity{ + // Memory limit should be at least 12582912 when running with CRI-O + corev1.ResourceMemory: resource.MustParse("50Mi"), + corev1.ResourceCPU: resource.MustParse("0.1"), + }, + }, + } +} diff --git a/pkg/controller/logstash/labels.go b/pkg/controller/logstash/labels.go new file mode 100644 index 0000000000..f69c95902b --- /dev/null +++ b/pkg/controller/logstash/labels.go @@ -0,0 +1,16 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +const ( + // TypeLabelValue represents the Logstash type. + TypeLabelValue = "logstash" + + // NameLabelName used to represent an Logstash in k8s resources + NameLabelName = "logstash.k8s.elastic.co/name" + + // NamespaceLabelName used to represent an Logstash in k8s resources + NamespaceLabelName = "logstash.k8s.elastic.co/namespace" +) diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go new file mode 100644 index 0000000000..9660517915 --- /dev/null +++ b/pkg/controller/logstash/logstash_controller.go @@ -0,0 +1,199 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/tools/record" + "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/source" + + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/keystore" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + logconf "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" +) + +const ( + controllerName = "logstash-controller" +) + +// Add creates a new Logstash Controller and adds it to the Manager with default RBAC. +// The Manager will set fields on the Controller and Start it when the Manager is Started. +func Add(mgr manager.Manager, params operator.Parameters) error { + r := newReconciler(mgr, params) + c, err := common.NewController(mgr, controllerName, r, params) + if err != nil { + return err + } + return addWatches(c, r) +} + +// newReconciler returns a new reconcile.Reconciler. +func newReconciler(mgr manager.Manager, params operator.Parameters) *ReconcileLogstash { + client := mgr.GetClient() + return &ReconcileLogstash{ + Client: client, + recorder: mgr.GetEventRecorderFor(controllerName), + dynamicWatches: watches.NewDynamicWatches(), + Parameters: params, + } +} + +// addWatches adds watches for all resources this controller cares about +func addWatches(c controller.Controller, r *ReconcileLogstash) error { + // Watch for changes to Logstash + if err := c.Watch(&source.Kind{Type: &logstashv1alpha1.Logstash{}}, &handler.EnqueueRequestForObject{}); err != nil { + return err + } + + // Watch StatefulSets + if err := c.Watch( + &source.Kind{Type: &appsv1.StatefulSet{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &logstashv1alpha1.Logstash{}, + }, + ); err != nil { + return err + } + + // Watch Pods, to ensure `status.version` is correctly reconciled on any change. + // Watching StatefulSets only may lead to missing some events. + if err := watches.WatchPods(c, NameLabelName); err != nil { + return err + } + + // Watch services + if err := c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &logstashv1alpha1.Logstash{}, + }); err != nil { + return err + } + + // Watch owned and soft-owned secrets + if err := c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &logstashv1alpha1.Logstash{}, + }); err != nil { + return err + } + if err := watches.WatchSoftOwnedSecrets(c, logstashv1alpha1.Kind); err != nil { + return err + } + + // Watch dynamically referenced Secrets + return c.Watch(&source.Kind{Type: &corev1.Secret{}}, r.dynamicWatches.Secrets) +} + +var _ reconcile.Reconciler = &ReconcileLogstash{} + +// ReconcileLogstash reconciles a Logstash object +type ReconcileLogstash struct { + k8s.Client + recorder record.EventRecorder + dynamicWatches watches.DynamicWatches + operator.Parameters + // iteration is the number of times this controller has run its Reconcile method + iteration uint64 +} + +// Reconcile reads that state of the cluster for a Logstash object and makes changes based on the state read +// and what is in the Logstash.Spec +// Automatically generate RBAC rules to allow the Controller to read and write StatefulSets +// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=apps,resources=statefulsets/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=logstash.k8s.elastic.co,resources=logstashes,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=logstash.k8s.elastic.co,resources=logstashes/status,verbs=get;update;patch +func (r *ReconcileLogstash) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { + ctx = common.NewReconciliationContext(ctx, &r.iteration, r.Tracer, controllerName, "logstash_name", request) + defer common.LogReconciliationRun(logconf.FromContext(ctx))() + defer tracing.EndContextTransaction(ctx) + + logstash := &logstashv1alpha1.Logstash{} + if err := r.Client.Get(ctx, request.NamespacedName, logstash); err != nil { + if apierrors.IsNotFound(err) { + return reconcile.Result{}, r.onDelete(ctx, request.NamespacedName) + } + return reconcile.Result{}, tracing.CaptureError(ctx, err) + } + + if common.IsUnmanaged(ctx, logstash) { + logconf.FromContext(ctx).Info("Object is currently not managed by this controller. Skipping reconciliation") + return reconcile.Result{}, nil + } + + if logstash.IsMarkedForDeletion() { + return reconcile.Result{}, nil + } + + results, status := r.doReconcile(ctx, *logstash) + + if err := updateStatus(ctx, *logstash, r.Client, status); err != nil { + if apierrors.IsConflict(err) { + return results.WithResult(reconcile.Result{Requeue: true}).Aggregate() + } + results = results.WithError(err) + } + + result, err := results.Aggregate() + k8s.EmitErrorEvent(r.recorder, err, logstash, events.EventReconciliationError, "Reconciliation error: %v", err) + + return result, err +} + +func (r *ReconcileLogstash) doReconcile(ctx context.Context, logstash logstashv1alpha1.Logstash) (*reconciler.Results, logstashv1alpha1.LogstashStatus) { + defer tracing.Span(&ctx)() + results := reconciler.NewResult(ctx) + status := newStatus(logstash) + + // Run basic validations as a fallback in case webhook is disabled. + if err := r.validate(ctx, logstash); err != nil { + results = results.WithError(err) + return results, status + } + + return internalReconcile(Params{ + Context: ctx, + Client: r.Client, + EventRecorder: r.recorder, + Watches: r.dynamicWatches, + Logstash: logstash, + Status: status, + OperatorParams: r.Parameters, + }) +} + +func (r *ReconcileLogstash) validate(ctx context.Context, logstash logstashv1alpha1.Logstash) error { + defer tracing.Span(&ctx)() + + // Run create validations only as update validations require old object which we don't have here. + if err := logstash.ValidateCreate(); err != nil { + logconf.FromContext(ctx).Error(err, "Validation failed") + k8s.EmitErrorEvent(r.recorder, err, &logstash, events.EventReasonValidation, err.Error()) + return tracing.CaptureError(ctx, err) + } + return nil +} + +func (r *ReconcileLogstash) onDelete(ctx context.Context, obj types.NamespacedName) error { + r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj)) + r.dynamicWatches.Secrets.RemoveHandlerForKey(common.ConfigRefWatchName(obj)) + return reconciler.GarbageCollectSoftOwnedSecrets(ctx, r.Client, obj, logstashv1alpha1.Kind) +} diff --git a/pkg/controller/logstash/network/ports.go b/pkg/controller/logstash/network/ports.go new file mode 100644 index 0000000000..197dae5249 --- /dev/null +++ b/pkg/controller/logstash/network/ports.go @@ -0,0 +1,10 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package network + +const ( + // HTTPPort is the (default) API port used by Logstash + HTTPPort = 9600 +) diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go new file mode 100644 index 0000000000..1cc1c589d5 --- /dev/null +++ b/pkg/controller/logstash/pod.go @@ -0,0 +1,147 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "fmt" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/volume" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/maps" + "hash" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/intstr" + "path" +) + +const ( + ContainerName = "logstash" + + ConfigVolumeName = "config" + ConfigMountPath = "/usr/share/logstash/config" + + LogstashConfigVolumeName = "logstash" + LogstashConfigFileName = "logstash.yml" + + // ConfigHashAnnotationName is an annotation used to store the Logstash config hash. + ConfigHashAnnotationName = "logstash.k8s.elastic.co/config-hash" + + // VersionLabelName is a label used to track the version of a Logstash Pod. + VersionLabelName = "logstash.k8s.elastic.co/version" +) + +var ( + DefaultResources = corev1.ResourceRequirements{ + Limits: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("2Gi"), + corev1.ResourceCPU: resource.MustParse("2000m"), + }, + Requests: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("2Gi"), + corev1.ResourceCPU: resource.MustParse("1000m"), + }, + } +) + +func buildPodTemplate(params Params, configHash hash.Hash32) (corev1.PodTemplateSpec, error) { + defer tracing.Span(¶ms.Context)() + spec := ¶ms.Logstash.Spec + builder := defaults.NewPodTemplateBuilder(params.GetPodTemplate(), ContainerName) + vols := []volume.VolumeLike{ + // volume with logstash configuration file + volume.NewSecretVolume( + logstashv1alpha1.ConfigSecretName(params.Logstash.Name), + LogstashConfigVolumeName, + path.Join(ConfigMountPath, LogstashConfigFileName), + LogstashConfigFileName, + 0644), + } + + labels := maps.Merge(params.Logstash.GetIdentityLabels(), map[string]string{ + VersionLabelName: spec.Version}) + + annotations := map[string]string{ + ConfigHashAnnotationName: fmt.Sprint(configHash.Sum32()), + } + + ports := getDefaultContainerPorts(params.Logstash) + + builder = builder. + WithResources(DefaultResources). + WithLabels(labels). + WithAnnotations(annotations). + WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). + WithAutomountServiceAccountToken(). + WithPorts(ports). + WithReadinessProbe(readinessProbe(false)). + WithLivenessProbe(livenessProbe(false)). + WithVolumeLikes(vols...) + + //TODO integrate with api.ssl.enabled + if params.Logstash.Spec.HTTP.TLS.Enabled() { + httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) + builder. + WithVolumes(httpVol.Volume()). + WithVolumeMounts(httpVol.VolumeMount()) + } + + return builder.PodTemplate, nil +} + + +func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.ContainerPort { + return []corev1.ContainerPort{ + {Name: logstash.Spec.HTTP.Protocol(), ContainerPort: int32(network.HTTPPort), Protocol: corev1.ProtocolTCP}, + } +} + +// readinessProbe is the readiness probe for the Logstash container +func readinessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 30, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} + +// livenessProbe is the liveness probe for the Logstash container +func livenessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 60, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go new file mode 100644 index 0000000000..edc31631bb --- /dev/null +++ b/pkg/controller/logstash/reconcile.go @@ -0,0 +1,90 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/sset" + "reflect" + + corev1 "k8s.io/api/core/v1" + "k8s.io/client-go/kubernetes/scheme" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + + "github.com/pkg/errors" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + + +func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*reconciler.Results, logstashv1alpha1.LogstashStatus){ + defer tracing.Span(¶ms.Context)() + results := reconciler.NewResult(params.Context) + + s, _ := sset.New(sset.Params{ + Name: logstashv1alpha1.Name(params.Logstash.Name), + Namespace: params.Logstash.Namespace, + ServiceName: logstashv1alpha1.HTTPServiceName(params.Logstash.Name), + Selector: params.Logstash.GetIdentityLabels(), + Labels: params.Logstash.GetIdentityLabels(), + PodTemplateSpec: podTemplate, + Replicas: params.Logstash.Spec.Count, + RevisionHistoryLimit: params.Logstash.Spec.RevisionHistoryLimit, + }) + if err := controllerutil.SetControllerReference(¶ms.Logstash, &s, scheme.Scheme); err != nil { + return results.WithError(err), params.Status + } + + reconciled, err := sset.Reconcile(params.Context, params.Client, s, ¶ms.Logstash) + if err != nil { + return results.WithError(err), params.Status + } + + var status logstashv1alpha1.LogstashStatus + if status, err = calculateStatus(¶ms, reconciled.Status.ReadyReplicas, reconciled.Status.Replicas); err != nil { + err = errors.Wrap(err, "while calculating status") + } + + return results.WithError(err), status +} + +// ReconciliationParams are the parameters used during an Elastic Logstash's reconciliation. +type ReconciliationParams struct { + ctx context.Context + client k8s.Client + logstash logstashv1alpha1.Logstash + podTemplate corev1.PodTemplateSpec +} + +// calculateStatus will calculate a new status from the state of the pods within the k8s cluster +// and will return any error encountered. +func calculateStatus(params *Params, ready, desired int32) (logstashv1alpha1.LogstashStatus, error) { + logstash := params.Logstash + status := params.Status + + pods, err := k8s.PodsMatchingLabels(params.Client, logstash.Namespace, map[string]string{NameLabelName: logstash.Name}) + if err != nil { + return status, err + } + + status.Version = common.LowestVersionFromPods(params.Context, status.Version, pods, VersionLabelName) + status.AvailableNodes = ready + status.ExpectedNodes = desired + return status, nil +} + +// updateStatus will update the Elastic Logstash's status within the k8s cluster, using the given Elastic Logstash and status. +func updateStatus(ctx context.Context, logstash logstashv1alpha1.Logstash, client client.Client, status logstashv1alpha1.LogstashStatus) error { + if reflect.DeepEqual(logstash.Status, status) { + return nil + } + logstash.Status = status + return common.UpdateStatus(ctx, client, &logstash) +} diff --git a/pkg/controller/logstash/sset/sset.go b/pkg/controller/logstash/sset/sset.go new file mode 100644 index 0000000000..935ec1ed34 --- /dev/null +++ b/pkg/controller/logstash/sset/sset.go @@ -0,0 +1,93 @@ +package sset + +import ( + "context" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" + + appsv1 "k8s.io/api/apps/v1" + + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/hash" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/maps" +) + +type Params struct { + Name string + Namespace string + ServiceName string + Selector map[string]string + Labels map[string]string + PodTemplateSpec corev1.PodTemplateSpec + Replicas int32 + RevisionHistoryLimit *int32 +} + +func New(params Params) (appsv1.StatefulSet, error) { + + sset := appsv1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: params.Name, + Namespace: params.Namespace, + Labels: params.Labels, + }, + Spec: appsv1.StatefulSetSpec{ + UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ + Type: appsv1.RollingUpdateStatefulSetStrategyType, + }, + // we don't care much about pods creation ordering, and manage deletion ordering ourselves, + // so we're fine with the StatefulSet controller spawning all pods in parallel + PodManagementPolicy: appsv1.ParallelPodManagement, + RevisionHistoryLimit: params.RevisionHistoryLimit, + // build a headless service per StatefulSet, matching the StatefulSet labels + ServiceName: params.ServiceName, + Selector: &metav1.LabelSelector{ + MatchLabels: params.Selector, + }, + + Replicas: ¶ms.Replicas, + Template: params.PodTemplateSpec, + }, + } + + // store a hash of the sset resource in its labels for comparison purposes + sset.Labels = hash.SetTemplateHashLabel(sset.Labels, sset.Spec) + + return sset, nil +} + +// Reconcile creates or updates the expected StatefulSet. +func Reconcile(ctx context.Context, c k8s.Client, expected appsv1.StatefulSet, owner client.Object) (appsv1.StatefulSet, error) { + var reconciled appsv1.StatefulSet + + err := reconciler.ReconcileResource(reconciler.Params{ + Context: ctx, + Client: c, + Owner: owner, + Expected: &expected, + Reconciled: &reconciled, + NeedsUpdate: func() bool { + // expected labels or annotations not there + return !maps.IsSubset(expected.Labels, reconciled.Labels) || + !maps.IsSubset(expected.Annotations, reconciled.Annotations) || + // different spec + !EqualTemplateHashLabels(expected, reconciled) + }, + UpdateReconciled: func() { + // override annotations and labels with expected ones + // don't remove additional values in reconciled that may have been defaulted or + // manually set by the user on the existing resource + reconciled.Labels = maps.Merge(reconciled.Labels, expected.Labels) + reconciled.Annotations = maps.Merge(reconciled.Annotations, expected.Annotations) + reconciled.Spec = expected.Spec + }, + }) + return reconciled, err +} + +// EqualTemplateHashLabels reports whether actual and expected StatefulSets have the same template hash label value. +func EqualTemplateHashLabels(expected, actual appsv1.StatefulSet) bool { + return expected.Labels[hash.TemplateHashLabelName] == actual.Labels[hash.TemplateHashLabelName] +} From 11f0f793529f4026c0ea0baed4a2b7b366c49a24 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Fri, 10 Feb 2023 14:19:12 -0500 Subject: [PATCH 002/160] Comment out certs for HTTPS for now --- config/crds/v1/all-crds.yaml | 4 +- .../logstash.k8s.elastic.co_logstashes.yaml | 4 +- .../eck-operator-crds/templates/all-crds.yaml | 4 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 13 +++--- .../v1alpha1/zz_generated.deepcopy.go | 12 +++--- pkg/controller/logstash/driver.go | 43 ++++++++++--------- pkg/controller/logstash/pod.go | 14 +++--- pkg/controller/logstash/sset/sset.go | 1 - 8 files changed, 48 insertions(+), 47 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index ab495fab43..d6a285a6dc 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9118,8 +9118,8 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Agent - in Fleet mode with Fleet Server enabled. + description: HTTP holds the HTTP layer configuration for the Logstash + Metrics API properties: service: description: Service defines the template for the associated Kubernetes diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 861b378eb4..1d86f803e1 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -74,8 +74,8 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Agent - in Fleet mode with Fleet Server enabled. + description: HTTP holds the HTTP layer configuration for the Logstash + Metrics API properties: service: description: Service defines the template for the associated Kubernetes diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index b9fab1fb80..347de6c534 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9172,8 +9172,8 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Agent - in Fleet mode with Fleet Server enabled. + description: HTTP holds the HTTP layer configuration for the Logstash + Metrics API properties: service: description: Service defines the template for the associated Kubernetes diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index d948fd2b96..239f0348cc 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -38,9 +38,16 @@ type LogstashSpec struct { // +kubebuilder:validation:Optional ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"` + // HTTP holds the HTTP layer configuration for the Logstash Metrics API + // +kubebuilder:validation:Optional + HTTP commonv1.HTTPConfig `json:"http,omitempty"` + // PodTemplate provides customisation options for the Logstash pods. PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` + // RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. + RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` + // SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. // Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of // each SecureSetting. @@ -52,12 +59,6 @@ type LogstashSpec struct { // +kubebuilder:validation:Optional ServiceAccountName string `json:"serviceAccountName,omitempty"` - // RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. - RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` - - // HTTP holds the HTTP layer configuration for the Agent in Fleet mode with Fleet Server enabled. - // +kubebuilder:validation:Optional - HTTP commonv1.HTTPConfig `json:"http,omitempty"` } // LogstashStatus defines the observed state of Logstash diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index cf5c388da8..42ca5a613e 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -85,7 +85,13 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { *out = new(v1.ConfigSource) **out = **in } + in.HTTP.DeepCopyInto(&out.HTTP) in.PodTemplate.DeepCopyInto(&out.PodTemplate) + if in.RevisionHistoryLimit != nil { + in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit + *out = new(int32) + **out = **in + } if in.SecureSettings != nil { in, out := &in.SecureSettings, &out.SecureSettings *out = make([]v1.SecretSource, len(*in)) @@ -93,12 +99,6 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.RevisionHistoryLimit != nil { - in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit - *out = new(int32) - **out = **in - } - in.HTTP.DeepCopyInto(&out.HTTP) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashSpec. diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 250473644b..b0270bff24 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -7,9 +7,9 @@ package logstash import ( "context" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" "hash/fnv" "github.com/go-logr/logr" @@ -75,29 +75,30 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log defer tracing.Span(¶ms.Context)() results := reconciler.NewResult(params.Context) - svc, err := common.ReconcileService(params.Context, params.Client, newService(params.Logstash), ¶ms.Logstash) + _, err := common.ReconcileService(params.Context, params.Client, newService(params.Logstash), ¶ms.Logstash) if err != nil { return results.WithError(err), params.Status } - _, results = certificates.Reconciler{ - K8sClient: params.Client, - DynamicWatches: params.Watches, - Owner: ¶ms.Logstash, - TLSOptions: params.Logstash.Spec.HTTP.TLS, - Namer: logstashv1alpha1.Namer, - Labels: params.Logstash.GetIdentityLabels(), - Services: []corev1.Service{*svc}, - GlobalCA: params.OperatorParams.GlobalCA, - CACertRotation: params.OperatorParams.CACertRotation, - CertRotation: params.OperatorParams.CertRotation, - GarbageCollectSecrets: true, - }.ReconcileCAAndHTTPCerts(params.Context) - if results.HasError() { - _, err := results.Aggregate() - k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) - return results, params.Status - } + //_, results = certificates.Reconciler{ + // K8sClient: params.Client, + // DynamicWatches: params.Watches, + // Owner: ¶ms.Logstash, + // TLSOptions: params.Logstash.Spec.HTTP.TLS, + // Namer: logstashv1alpha1.Namer, + // Labels: params.Logstash.GetIdentityLabels(), + // Services: []corev1.Service{*svc}, + // GlobalCA: params.OperatorParams.GlobalCA, + // CACertRotation: params.OperatorParams.CACertRotation, + // CertRotation: params.OperatorParams.CertRotation, + // GarbageCollectSecrets: true, + //}.ReconcileCAAndHTTPCerts(params.Context) + // + //if results.HasError() { + // _, err := results.Aggregate() + // k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + // return results, params.Status + //} configHash := fnv.New32a() diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 1cc1c589d5..aba2483c7d 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -7,7 +7,7 @@ package logstash import ( "fmt" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" @@ -85,12 +85,12 @@ func buildPodTemplate(params Params, configHash hash.Hash32) (corev1.PodTemplate WithVolumeLikes(vols...) //TODO integrate with api.ssl.enabled - if params.Logstash.Spec.HTTP.TLS.Enabled() { - httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) - builder. - WithVolumes(httpVol.Volume()). - WithVolumeMounts(httpVol.VolumeMount()) - } + //if params.Logstash.Spec.HTTP.TLS.Enabled() { + // httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) + // builder. + // WithVolumes(httpVol.Volume()). + // WithVolumeMounts(httpVol.VolumeMount()) + //} return builder.PodTemplate, nil } diff --git a/pkg/controller/logstash/sset/sset.go b/pkg/controller/logstash/sset/sset.go index 935ec1ed34..650ad14f8a 100644 --- a/pkg/controller/logstash/sset/sset.go +++ b/pkg/controller/logstash/sset/sset.go @@ -26,7 +26,6 @@ type Params struct { } func New(params Params) (appsv1.StatefulSet, error) { - sset := appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ Name: params.Name, From 7414098b73425cf4cf664cb2320de832d44d16ab Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Fri, 10 Feb 2023 17:25:35 -0500 Subject: [PATCH 003/160] Fix up linter issus --- cmd/manager/main.go | 5 +- pkg/apis/logstash/v1alpha1/labels.go | 6 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 11 ++- pkg/controller/common/scheme/scheme.go | 3 +- pkg/controller/elasticsearch/user/roles.go | 11 --- pkg/controller/logstash/config.go | 14 ++-- pkg/controller/logstash/driver.go | 17 ++--- pkg/controller/logstash/init_configuration.go | 75 ------------------- .../logstash/logstash_controller.go | 3 +- pkg/controller/logstash/pod.go | 22 +++--- pkg/controller/logstash/reconcile.go | 14 +--- pkg/controller/logstash/sset/sset.go | 9 ++- 12 files changed, 52 insertions(+), 138 deletions(-) delete mode 100644 pkg/controller/logstash/init_configuration.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 16cf2c55cb..fa6cc484a8 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -8,8 +8,6 @@ import ( "context" "errors" "fmt" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "net/http" "net/http/pprof" "os" @@ -18,6 +16,9 @@ import ( "strings" "time" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + "github.com/go-logr/logr" "github.com/spf13/cobra" "github.com/spf13/viper" diff --git a/pkg/apis/logstash/v1alpha1/labels.go b/pkg/apis/logstash/v1alpha1/labels.go index 70e5fa8cf5..9d4a22f515 100644 --- a/pkg/apis/logstash/v1alpha1/labels.go +++ b/pkg/apis/logstash/v1alpha1/labels.go @@ -9,9 +9,9 @@ import ( ) // GetIdentityLabels will return the common Elastic assigned labels for Logstash -func (logstash* Logstash) GetIdentityLabels() map[string]string { +func (logstash *Logstash) GetIdentityLabels() map[string]string { return map[string]string{ - commonv1.TypeLabelName: "logstash", - "logstash.k8s.elastic.co/name": logstash.Name, + commonv1.TypeLabelName: "logstash", + "logstash.k8s.elastic.co/name": logstash.Name, } } diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 239f0348cc..47c12f4a87 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -5,9 +5,10 @@ package v1alpha1 import ( - commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) const ( @@ -21,7 +22,7 @@ type LogstashSpec struct { // Version of the Logstash. Version string `json:"version"` - Count int32 `json:"count,omitempty"` + Count int32 `json:"count,omitempty"` // Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. // +kubebuilder:validation:Optional @@ -58,7 +59,6 @@ type LogstashSpec struct { // Can only be used if ECK is enforcing RBAC on references. // +kubebuilder:validation:Optional ServiceAccountName string `json:"serviceAccountName,omitempty"` - } // LogstashStatus defines the observed state of Logstash @@ -94,8 +94,8 @@ type Logstash struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec LogstashSpec `json:"spec,omitempty"` - Status LogstashStatus `json:"status,omitempty"` + Spec LogstashSpec `json:"spec,omitempty"` + Status LogstashStatus `json:"status,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -107,7 +107,6 @@ type LogstashList struct { Items []Logstash `json:"items"` } - func (l *Logstash) ServiceAccountName() string { return l.Spec.ServiceAccountName } diff --git a/pkg/controller/common/scheme/scheme.go b/pkg/controller/common/scheme/scheme.go index 69b4706966..51ce53cdd3 100644 --- a/pkg/controller/common/scheme/scheme.go +++ b/pkg/controller/common/scheme/scheme.go @@ -5,9 +5,10 @@ package scheme import ( - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "sync" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" diff --git a/pkg/controller/elasticsearch/user/roles.go b/pkg/controller/elasticsearch/user/roles.go index dded5f09ce..4688dea3b1 100644 --- a/pkg/controller/elasticsearch/user/roles.go +++ b/pkg/controller/elasticsearch/user/roles.go @@ -42,8 +42,6 @@ const ( FleetAdminUserRole = "eck_fleet_admin_user_role" - LogstashUserRole = "eck_logstash_user_role_v80" - // V70 indicates version 7.0 V70 = "v70" @@ -149,15 +147,6 @@ var ( }, }, }, - LogstashUserRole: esclient.Role{ - Cluster: []string{"monitor", "manage_ilm", "manage_ml", "read_ilm", "cluster:admin/ingest/pipeline/get"}, - Indices: []esclient.IndexRole{ - { - Names: []string{"logstash-*"}, - Privileges: []string{"manage", "read", "create_doc", "view_index_metadata", "create_index"}, - }, - }, - }, } ) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index c27b754c25..6c00a6eeee 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -6,11 +6,13 @@ package logstash import ( "context" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" - ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" "hash" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" + ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -63,13 +65,13 @@ func buildConfig(params Params) ([]byte, error) { return nil, err } - cfg, err := defaultConfig() + cfg := defaultConfig() if err != nil { return nil, err } // merge with user settings last so they take precedence - if err = cfg.MergeWith(existingCfg, userProvidedCfg); err != nil { + if err := cfg.MergeWith(existingCfg, userProvidedCfg); err != nil { return nil, err } @@ -114,10 +116,10 @@ func getUserConfig(params Params) (*settings.CanonicalConfig, error) { } // TODO: remove testing value -func defaultConfig() (*settings.CanonicalConfig, error) { +func defaultConfig() *settings.CanonicalConfig { settingsMap := map[string]interface{}{ "node.name": "test", } - return settings.MustCanonicalConfig(settingsMap), nil + return settings.MustCanonicalConfig(settingsMap) } \ No newline at end of file diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index b0270bff24..54372a4701 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -6,10 +6,12 @@ package logstash import ( "context" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" "hash/fnv" "github.com/go-logr/logr" @@ -80,7 +82,7 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log return results.WithError(err), params.Status } - //_, results = certificates.Reconciler{ + // _, results = certificates.Reconciler{ // K8sClient: params.Client, // DynamicWatches: params.Watches, // Owner: ¶ms.Logstash, @@ -92,9 +94,9 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log // CACertRotation: params.OperatorParams.CACertRotation, // CertRotation: params.OperatorParams.CertRotation, // GarbageCollectSecrets: true, - //}.ReconcileCAAndHTTPCerts(params.Context) + // }.ReconcileCAAndHTTPCerts(params.Context) // - //if results.HasError() { + // if results.HasError() { // _, err := results.Aggregate() // k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) // return results, params.Status @@ -106,10 +108,7 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log return results.WithResults(res), params.Status } - podTemplate, err := buildPodTemplate(params, configHash) - if err != nil { - return results.WithError(err), params.Status - } + podTemplate := buildPodTemplate(params, configHash) return reconcileStatefulSet(params, podTemplate) } diff --git a/pkg/controller/logstash/init_configuration.go b/pkg/controller/logstash/init_configuration.go deleted file mode 100644 index a85b118568..0000000000 --- a/pkg/controller/logstash/init_configuration.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" -) - -const ( - InitContainerConfigVolumeMountPath = "/mnt/elastic-internal/logstash-config-local" - InitConfigContainerName = "elastic-internal-init-config" - - // InitConfigScript is a small bash script to prepare the logstash configuration directory - InitConfigScript = `#!/usr/bin/env bash -set -eux - -init_config_initialized_flag=` + InitContainerConfigVolumeMountPath + `/elastic-internal-init-config.ok - -if [[ -f "${init_config_initialized_flag}" ]]; then - echo "Logstash configuration already initialized." - exit 0 -fi - -echo "Setup Logstash configuration" - -mount_path=` + InitContainerConfigVolumeMountPath + ` - -for f in /usr/share/logstash/config/*.*; do - filename=$(basename $f) - if [[ ! -f "$mount_path/$filename" ]]; then - cp $f $mount_path - fi -done - -touch "${init_config_initialized_flag}" -echo "Logstash configuration successfully prepared." -` -) - -// initConfigContainer returns an init container that executes a bash script to prepare the logstash config directory. -// The script copy config files from /use/share/logstash/config to /mnt/elastic-internal/logstash-config/ -// TODO may be able to solve env2yaml permission issue with initContainer -func initConfigContainer() corev1.Container { - privileged := false - - return corev1.Container{ - // Image will be inherited from pod template defaults - ImagePullPolicy: corev1.PullIfNotPresent, - Name: InitConfigContainerName, - SecurityContext: &corev1.SecurityContext{ - Privileged: &privileged, - }, - Command: []string{"/usr/bin/env", "bash", "-c", InitConfigScript}, - VolumeMounts: []corev1.VolumeMount{ - { - MountPath: InitContainerConfigVolumeMountPath, - Name: ConfigVolumeName, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: map[corev1.ResourceName]resource.Quantity{ - corev1.ResourceMemory: resource.MustParse("50Mi"), - corev1.ResourceCPU: resource.MustParse("0.1"), - }, - Limits: map[corev1.ResourceName]resource.Quantity{ - // Memory limit should be at least 12582912 when running with CRI-O - corev1.ResourceMemory: resource.MustParse("50Mi"), - corev1.ResourceCPU: resource.MustParse("0.1"), - }, - }, - } -} diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go index 9660517915..5c0c6816b0 100644 --- a/pkg/controller/logstash/logstash_controller.go +++ b/pkg/controller/logstash/logstash_controller.go @@ -6,6 +6,7 @@ package logstash import ( "context" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" appsv1 "k8s.io/api/apps/v1" @@ -20,8 +21,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/source" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/keystore" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/keystore" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index aba2483c7d..958923b9b7 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -6,19 +6,20 @@ package logstash import ( "fmt" + "hash" + "path" + + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/intstr" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/maps" - "hash" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/apimachinery/pkg/util/intstr" - "path" ) const ( @@ -50,7 +51,7 @@ var ( } ) -func buildPodTemplate(params Params, configHash hash.Hash32) (corev1.PodTemplateSpec, error) { +func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateSpec { defer tracing.Span(¶ms.Context)() spec := ¶ms.Logstash.Spec builder := defaults.NewPodTemplateBuilder(params.GetPodTemplate(), ContainerName) @@ -84,18 +85,17 @@ func buildPodTemplate(params Params, configHash hash.Hash32) (corev1.PodTemplate WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) - //TODO integrate with api.ssl.enabled - //if params.Logstash.Spec.HTTP.TLS.Enabled() { + // TODO integrate with api.ssl.enabled + // if params.Logstash.Spec.HTTP.TLS.Enabled() { // httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) // builder. // WithVolumes(httpVol.Volume()). // WithVolumeMounts(httpVol.VolumeMount()) //} - return builder.PodTemplate, nil + return builder.PodTemplate } - func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.ContainerPort { return []corev1.ContainerPort{ {Name: logstash.Spec.HTTP.Protocol(), ContainerPort: int32(network.HTTPPort), Protocol: corev1.ProtocolTCP}, diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go index edc31631bb..c74149a1dd 100644 --- a/pkg/controller/logstash/reconcile.go +++ b/pkg/controller/logstash/reconcile.go @@ -6,9 +6,10 @@ package logstash import ( "context" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/sset" "reflect" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/sset" + corev1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client" @@ -23,8 +24,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) - -func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*reconciler.Results, logstashv1alpha1.LogstashStatus){ +func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*reconciler.Results, logstashv1alpha1.LogstashStatus) { defer tracing.Span(¶ms.Context)() results := reconciler.NewResult(params.Context) @@ -55,14 +55,6 @@ func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (* return results.WithError(err), status } -// ReconciliationParams are the parameters used during an Elastic Logstash's reconciliation. -type ReconciliationParams struct { - ctx context.Context - client k8s.Client - logstash logstashv1alpha1.Logstash - podTemplate corev1.PodTemplateSpec -} - // calculateStatus will calculate a new status from the state of the pods within the k8s cluster // and will return any error encountered. func calculateStatus(params *Params, ready, desired int32) (logstashv1alpha1.LogstashStatus, error) { diff --git a/pkg/controller/logstash/sset/sset.go b/pkg/controller/logstash/sset/sset.go index 650ad14f8a..39bc56e26d 100644 --- a/pkg/controller/logstash/sset/sset.go +++ b/pkg/controller/logstash/sset/sset.go @@ -1,7 +1,12 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + package sset import ( "context" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -46,8 +51,8 @@ func New(params Params) (appsv1.StatefulSet, error) { MatchLabels: params.Selector, }, - Replicas: ¶ms.Replicas, - Template: params.PodTemplateSpec, + Replicas: ¶ms.Replicas, + Template: params.PodTemplateSpec, }, } From 2304fa35a92d0fcd7c1fc8b10e643386f03ee41f Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Fri, 10 Feb 2023 17:52:55 -0500 Subject: [PATCH 004/160] Generate API docs ` --- docs/reference/api-docs.asciidoc | 52 ++--------------------- pkg/apis/logstash/v1alpha1/validations.go | 2 +- pkg/controller/logstash/config.go | 2 +- pkg/controller/logstash/pod.go | 6 +-- 4 files changed, 9 insertions(+), 53 deletions(-) diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index a06cf4cb7f..c1a58e4930 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -591,7 +591,6 @@ Monitoring holds references to both the metrics, and logs Elasticsearch clusters - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-elasticsearchspec[$$ElasticsearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] **** [cols="25a,75a", options="header"] @@ -616,7 +615,6 @@ ObjectSelector defines a reference to a Kubernetes object which can be an Elasti - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-logsmonitoring[$$LogsMonitoring$$] -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-metricsmonitoring[$$MetricsMonitoring$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-agent-v1alpha1-output[$$Output$$] @@ -1838,25 +1836,6 @@ Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API g -[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-deploymentspec"] -=== DeploymentSpec - - - -.Appears In: -**** -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] -**** - -[cols="25a,75a", options="header"] -|=== -| Field | Description -| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | -| *`replicas`* __integer__ | -| *`strategy`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#deploymentstrategy-v1-apps[$$DeploymentStrategy$$]__ | -|=== - - [id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash"] === Logstash @@ -1893,19 +1872,15 @@ LogstashSpec defines the desired state of Logstash |=== | Field | Description | *`version`* __string__ | Version of the Logstash. -| *`elasticsearchRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-objectselector[$$ObjectSelector$$]__ | ElasticsearchRef is a reference to an Elasticsearch cluster running in the same Kubernetes cluster. +| *`count`* __integer__ | | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. -| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelineRef`] can be specified. -| *`pipelineRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelineRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipeline must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelineRef`] can be specified. +| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API +| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. +| *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. | *`serviceAccountName`* __string__ | ServiceAccountName is used to check access from the current resource to Elasticsearch resource in a different namespace. Can only be used if ECK is enforcing RBAC on references. -| *`deployment`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-deploymentspec[$$DeploymentSpec$$]__ | Deployment specifies the Logstash should be deployed as a Deployment, and allows providing its spec. Cannot be used along with `StatefulSet`. -| *`statefulSet`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-statefulsetspec[$$StatefulSetSpec$$]__ | StatefulSet specifies the Logstash should be deployed as a StatefulSet, and allows providing its spec. Cannot be used along with `Deployment`. -| *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying DaemonSet or Deployment. -| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Agent in Fleet mode with Fleet Server enabled. -| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. See https://www.elastic.co/guide/en/kibana/current/xpack-monitoring.html. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. |=== @@ -1929,25 +1904,6 @@ LogstashStatus defines the observed state of Logstash |=== -[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-statefulsetspec"] -=== StatefulSetSpec - - - -.Appears In: -**** -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] -**** - -[cols="25a,75a", options="header"] -|=== -| Field | Description -| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | -| *`replicas`* __integer__ | -| *`volumeClaimTemplates`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#persistentvolumeclaim-v1-core[$$PersistentVolumeClaim$$] array__ | VolumeClaimTemplates is a list of persistent volume claims to be used by each Pod in this NodeSet. Every claim in this list must have a matching volumeMount in one of the containers defined in the PodTemplate. Items defined here take precedence over any default claims added by the operator with the same name. -|=== - - [id="{anchor_prefix}-maps-k8s-elastic-co-v1alpha1"] == maps.k8s.elastic.co/v1alpha1 diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go index 019b482c04..1f70d2783a 100644 --- a/pkg/apis/logstash/v1alpha1/validations.go +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -53,4 +53,4 @@ func checkSingleConfigSource(a *Logstash) field.ErrorList { } return nil -} \ No newline at end of file +} diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index 6c00a6eeee..4a3fc0ed63 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -122,4 +122,4 @@ func defaultConfig() *settings.CanonicalConfig { } return settings.MustCanonicalConfig(settingsMap) -} \ No newline at end of file +} diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 958923b9b7..f6a4af0146 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -85,13 +85,13 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) - // TODO integrate with api.ssl.enabled - // if params.Logstash.Spec.HTTP.TLS.Enabled() { + // TODO integrate with api.ssl.enabled + // if params.Logstash.Spec.HTTP.TLS.Enabled() { // httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) // builder. // WithVolumes(httpVol.Volume()). // WithVolumeMounts(httpVol.VolumeMount()) - //} + // } return builder.PodTemplate } From 9459a70e6f5de272f426bbf4054356b7c6cd59f1 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 13 Feb 2023 10:20:59 -0500 Subject: [PATCH 005/160] First set of unit tests Rudimentary tests for validation and naming --- pkg/apis/logstash/v1alpha1/name_test.go | 105 ++++++++++++++++++ .../logstash/v1alpha1/validations_test.go | 47 ++++++++ 2 files changed, 152 insertions(+) create mode 100644 pkg/apis/logstash/v1alpha1/name_test.go create mode 100644 pkg/apis/logstash/v1alpha1/validations_test.go diff --git a/pkg/apis/logstash/v1alpha1/name_test.go b/pkg/apis/logstash/v1alpha1/name_test.go new file mode 100644 index 0000000000..38f3983d02 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/name_test.go @@ -0,0 +1,105 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "testing" +) + +func TestHTTPService(t *testing.T) { + type args struct { + logstashName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "sample", + args: args{logstashName: "sample"}, + want: "sample-ls-http", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := HTTPServiceName(tt.args.logstashName); got != tt.want { + t.Errorf("HTTPService() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestConfigSecretName(t *testing.T) { + type args struct { + logstashName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "sample", + args: args{logstashName: "sample"}, + want: "sample-ls-config", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ConfigSecretName(tt.args.logstashName); got != tt.want { + t.Errorf("ConfigSecret() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestLogstashName(t *testing.T) { + type args struct { + logstashName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "sample", + args: args{logstashName: "sample"}, + want: "sample-ls", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Name(tt.args.logstashName); got != tt.want { + t.Errorf("Logstash Name() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestConfigMapName(t *testing.T) { + type args struct { + logstashName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "sample", + args: args{logstashName: "sample"}, + want: "sample-ls-configmap", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ConfigMapName(tt.args.logstashName); got != tt.want { + t.Errorf("ConfigMap() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go new file mode 100644 index 0000000000..8cede16dcf --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -0,0 +1,47 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "testing" + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestCheckNameLength(t *testing.T) { + testCases := []struct { + name string + logstashName string + wantErr bool + wantErrMsg string + }{ + { + name: "valid configuration", + logstashName: "test-logstash", + wantErr: false, + }, + { + name: "long Logstash name", + logstashName: "extremely-long-winded-and-unnecessary-name-for-logstash", + wantErr: true, + wantErrMsg: "name exceeds maximum allowed length", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + ls := Logstash{ + ObjectMeta: metav1.ObjectMeta{ + Name: tc.logstashName, + Namespace: "test", + }, + Spec: LogstashSpec{}, + } + + errList := checkNameLength(&ls) + assert.Equal(t, tc.wantErr, len(errList) > 0) + }) + } +} From 285c7bf1f255d2aea0eae6bee57070218fa14559 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 13 Feb 2023 12:13:59 -0500 Subject: [PATCH 006/160] Fix goimports --- .../logstash/v1alpha1/validations_test.go | 23 ++++++++++--------- .../v1alpha1/zz_generated.deepcopy.go | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 8cede16dcf..0fb20a4036 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -6,27 +6,28 @@ package v1alpha1 import ( "testing" + "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestCheckNameLength(t *testing.T) { testCases := []struct { - name string - logstashName string - wantErr bool - wantErrMsg string + name string + logstashName string + wantErr bool + wantErrMsg string }{ { - name: "valid configuration", - logstashName: "test-logstash", - wantErr: false, + name: "valid configuration", + logstashName: "test-logstash", + wantErr: false, }, { - name: "long Logstash name", - logstashName: "extremely-long-winded-and-unnecessary-name-for-logstash", - wantErr: true, - wantErrMsg: "name exceeds maximum allowed length", + name: "long Logstash name", + logstashName: "extremely-long-winded-and-unnecessary-name-for-logstash", + wantErr: true, + wantErrMsg: "name exceeds maximum allowed length", }, } diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index 42ca5a613e..cb78272400 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -10,8 +10,9 @@ package v1alpha1 import ( - "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "k8s.io/apimachinery/pkg/runtime" + + v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. From d6e7ef21e873f574c89bb1dea846b2eb7424c351 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 13 Feb 2023 14:09:49 -0500 Subject: [PATCH 007/160] Add version check --- .../logstash/v1alpha1/validations_test.go | 137 ++++++++++++++++++ pkg/controller/common/version/version.go | 2 +- 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 0fb20a4036..4b9f1ebe91 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -9,6 +9,9 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/validation/field" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) func TestCheckNameLength(t *testing.T) { @@ -46,3 +49,137 @@ func TestCheckNameLength(t *testing.T) { }) } } + +func TestCheckNoUnknownFields(t *testing.T) { + type args struct { + prev *Logstash + curr *Logstash + } + tests := []struct { + name string + args args + want field.ErrorList + }{ + { + name: "No downgrade", + args: args{ + prev: &Logstash{Spec: LogstashSpec{Version: "7.17.0"}}, + curr: &Logstash{Spec: LogstashSpec{Version: "8.6.1"}}, + }, + want: nil, + }, + { + name: "Downgrade NOK", + args: args{ + prev: &Logstash{Spec: LogstashSpec{Version: "8.6.1"}}, + curr: &Logstash{Spec: LogstashSpec{Version: "8.5.0"}}, + }, + want: field.ErrorList{&field.Error{Type: field.ErrorTypeForbidden, Field: "spec.version", BadValue: "", Detail: "Version downgrades are not supported"}}, + }, + { + name: "Downgrade with override OK", + args: args{ + prev: &Logstash{Spec: LogstashSpec{Version: "8.6.1"}}, + curr: &Logstash{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{ + commonv1.DisableDowngradeValidationAnnotation: "true", + }}, Spec: LogstashSpec{Version: "8.5.0"}}, + }, + want: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, checkNoDowngrade(tt.args.prev, tt.args.curr), "checkNoDowngrade(%v, %v)", tt.args.prev, tt.args.curr) + }) + } +} + +func Test_checkSingleConfigSource(t *testing.T) { + tests := []struct { + name string + logstash Logstash + wantErr bool + }{ + { + name: "configRef absent, config present", + logstash: Logstash{ + Spec: LogstashSpec{ + Config: &commonv1.Config{}, + }, + }, + wantErr: false, + }, + { + name: "config absent, configRef present", + logstash: Logstash{ + Spec: LogstashSpec{ + ConfigRef: &commonv1.ConfigSource{}, + }, + }, + wantErr: false, + }, + { + name: "neither present", + logstash: Logstash{ + Spec: LogstashSpec{}, + }, + wantErr: false, + }, + { + name: "both present", + logstash: Logstash{ + Spec: LogstashSpec{ + Config: &commonv1.Config{}, + ConfigRef: &commonv1.ConfigSource{}, + }, + }, + wantErr: true, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + got := checkSingleConfigSource(&tc.logstash) + assert.Equal(t, tc.wantErr, len(got) > 0) + }) + } +} + +func Test_checkSupportedVersion(t *testing.T) { + for _, tt := range []struct { + name string + version string + wantErr bool + }{ + { + name: "below min supported", + version: "8.5.0", + wantErr: true, + }, + { + name: "above max supported", + version: "9.0.0", + wantErr: true, + }, + { + name: "above min supported", + version: "8.7.1", + wantErr: false, + }, + { + name: "at min supported", + version: "8.7.0", + wantErr: false, + }, + } { + t.Run(tt.name, func(t *testing.T) { + a := Logstash{ + Spec: LogstashSpec{ + Version: tt.version, + }, + } + got := checkSupportedVersion(&a) + assert.Equal(t, tt.wantErr, len(got) > 0) + }) + } +} diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index 9258310a74..d359f18371 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,7 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} - SupportedLogstashVersions = MinMaxVersion{Min: From(8, 3, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 7, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. From 8016b7b414be3bd098d4e8371d3465e866d6f95b Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Tue, 14 Feb 2023 18:39:30 -0500 Subject: [PATCH 008/160] Add e2e tests --- config/crds/v1/all-crds.yaml | 4 + .../logstash.k8s.elastic.co_logstashes.yaml | 4 + .../eck-operator-crds/templates/all-crds.yaml | 4 + pkg/apis/logstash/v1alpha1/logstash_types.go | 1 + .../logstash/v1alpha1/validations_test.go | 5 - .../v1alpha1/zz_generated.deepcopy.go | 3 +- pkg/controller/common/version/version.go | 2 +- pkg/controller/logstash/pod.go | 4 +- test/e2e/logstash/logstash_test.go | 36 ++++ test/e2e/test/k8s_client.go | 14 ++ test/e2e/test/logstash/builder.go | 146 +++++++++++++++++ test/e2e/test/logstash/checks.go | 64 ++++++++ test/e2e/test/logstash/steps.go | 155 ++++++++++++++++++ 13 files changed, 432 insertions(+), 10 deletions(-) create mode 100644 test/e2e/logstash/logstash_test.go create mode 100644 test/e2e/test/logstash/builder.go create mode 100644 test/e2e/test/logstash/checks.go create mode 100644 test/e2e/test/logstash/steps.go diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index d6a285a6dc..968393ef3d 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9631,6 +9631,10 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 1d86f803e1..b652b0ed80 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -7994,4 +7994,8 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 347de6c534..24afce4ccd 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9685,6 +9685,10 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 47c12f4a87..c0e97542fd 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -89,6 +89,7 @@ type LogstashStatus struct { // +kubebuilder:printcolumn:name="expected",type="integer",JSONPath=".status.expectedNodes",description="Expected nodes" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Logstash version" +// +kubebuilder:subresource:scale:specpath=.spec.count,statuspath=.status.count,selectorpath=.status.selector // +kubebuilder:storageversion type Logstash struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 4b9f1ebe91..08cd574aa4 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -166,11 +166,6 @@ func Test_checkSupportedVersion(t *testing.T) { version: "8.7.1", wantErr: false, }, - { - name: "at min supported", - version: "8.7.0", - wantErr: false, - }, } { t.Run(tt.name, func(t *testing.T) { a := Logstash{ diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index cb78272400..42ca5a613e 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -10,9 +10,8 @@ package v1alpha1 import ( + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "k8s.io/apimachinery/pkg/runtime" - - v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index d359f18371..0959920647 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,7 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} - SupportedLogstashVersions = MinMaxVersion{Min: From(8, 7, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 6, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index f6a4af0146..d6c139b83a 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -81,8 +81,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - WithReadinessProbe(readinessProbe(false)). - WithLivenessProbe(livenessProbe(false)). + //WithReadinessProbe(readinessProbe(false)). + //WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go new file mode 100644 index 0000000000..d994ad81e2 --- /dev/null +++ b/test/e2e/logstash/logstash_test.go @@ -0,0 +1,36 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +//go:build logstash || e2e + +package logstash + +import ( + "testing" + + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" +) + +func TestSingleLogstash(t *testing.T) { + name := "test-single-logstash" + logstashBuilder := logstash.NewBuilder(name). + WithNodeCount(1) + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + +func TestLogstashServerVersionUpgradeToLatest8x(t *testing.T) { + srcVersion, dstVersion := test.GetUpgradePathTo8x(test.Ctx().ElasticStackVersion) + + name := "test-ls-version-upgrade-8x" + + logstash := logstash.NewBuilder(name). + WithNodeCount(2). + WithVersion(srcVersion). + WithRestrictedSecurityContext() + + logstashUpgraded := logstash.WithVersion(dstVersion).WithMutatedFrom(&logstash) + + test.RunMutations(t, []test.Builder{logstash}, []test.Builder{logstashUpgraded}) +} diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index 8989fc2e82..f3b4d13ddf 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -33,6 +33,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/agent" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/apmserver" beatcommon "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/common" @@ -42,6 +43,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/kibana" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/maps" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) @@ -92,6 +94,9 @@ func CreateClient() (k8s.Client, error) { if err := agentv1alpha1.AddToScheme(scheme.Scheme); err != nil { return nil, err } + if err := logstashv1alpha1.AddToScheme(scheme.Scheme); err != nil { + return nil, err + } client, err := k8sclient.New(cfg, k8sclient.Options{Scheme: scheme.Scheme}) if err != nil { return nil, err @@ -431,6 +436,15 @@ func AgentPodListOptions(agentNamespace, agentName string) []k8sclient.ListOptio return []k8sclient.ListOption{ns, matchLabels} } +func LogstashPodListOptions(logstashNamespace, logstashName string) []k8sclient.ListOption { + ns := k8sclient.InNamespace(logstashNamespace) + matchLabels := k8sclient.MatchingLabels(map[string]string{ + commonv1.TypeLabelName: logstash.TypeLabelValue, + logstash.NameLabelName: logstashName, + }) + return []k8sclient.ListOption{ns, matchLabels} +} + func BeatPodListOptions(beatNamespace, beatName, beatType string) []k8sclient.ListOption { ns := k8sclient.InNamespace(beatNamespace) matchLabels := k8sclient.MatchingLabels(map[string]string{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go new file mode 100644 index 0000000000..8b08b9119d --- /dev/null +++ b/test/e2e/test/logstash/builder.go @@ -0,0 +1,146 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + +type Builder struct { + Logstash v1alpha1.Logstash + MutatedFrom *Builder +} + +func NewBuilder(name string) Builder { + return newBuilder(name, rand.String(4)) +} + +func NewBuilderWithoutSuffix(name string) Builder { + return newBuilder(name, "") +} + +func newBuilder(name, randSuffix string) Builder { + meta := metav1.ObjectMeta{ + Name: name, + Namespace: test.Ctx().ManagedNamespace(0), + } + def := test.Ctx().ImageDefinitionFor(v1alpha1.Kind) + return Builder{ + Logstash: v1alpha1.Logstash{ + ObjectMeta: meta, + Spec: v1alpha1.LogstashSpec{ + Count: 1, + Version: def.Version, + }, + }, + }. + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) +} + +func (b Builder) WithImage(image string) Builder { + b.Logstash.Spec.Image = image + return b +} + +func (b Builder) WithSuffix(suffix string) Builder { + if suffix != "" { + b.Logstash.ObjectMeta.Name = b.Logstash.ObjectMeta.Name + "-" + suffix + } + return b +} + +func (b Builder) WithLabel(key, value string) Builder { + if b.Logstash.Labels == nil { + b.Logstash.Labels = make(map[string]string) + } + b.Logstash.Labels[key] = value + + return b +} + +// WithRestrictedSecurityContext helps to enforce a restricted security context on the objects. +func (b Builder) WithRestrictedSecurityContext() Builder { + b.Logstash.Spec.PodTemplate.Spec.SecurityContext = test.DefaultSecurityContext() + return b +} + +func (b Builder) WithNamespace(namespace string) Builder { + b.Logstash.ObjectMeta.Namespace = namespace + return b +} + +func (b Builder) WithVersion(version string) Builder { + b.Logstash.Spec.Version = version + return b +} + +func (b Builder) WithNodeCount(count int) Builder { + b.Logstash.Spec.Count = int32(count) + return b +} + +// WithPodLabel sets the label in the pod template. All invocations can be removed when +// https://github.com/elastic/cloud-on-k8s/issues/2652 is implemented. +func (b Builder) WithPodLabel(key, value string) Builder { + labels := b.Logstash.Spec.PodTemplate.Labels + if labels == nil { + labels = make(map[string]string) + } + labels[key] = value + b.Logstash.Spec.PodTemplate.Labels = labels + return b +} + +func (b Builder) WithMutatedFrom(mutatedFrom *Builder) Builder { + b.MutatedFrom = mutatedFrom + return b +} + +func (b Builder) NSN() types.NamespacedName { + return k8s.ExtractNamespacedName(&b.Logstash) +} + +func (b Builder) Kind() string { + return v1alpha1.Kind +} + +func (b Builder) Spec() interface{} { + return b.Logstash.Spec +} + +func (b Builder) Count() int32 { + return b.Logstash.Spec.Count +} + +func (b Builder) ServiceName() string { + return b.Logstash.Name + "-ls-http" +} + +func (b Builder) ListOptions() []client.ListOption { + return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) +} + + +func (b Builder) SkipTest() bool { + supportedVersions := version.SupportedLogstashVersions + + ver := version.MustParse(b.Logstash.Spec.Version) + return supportedVersions.WithinRange(ver) != nil +} + +var _ test.Builder = Builder{} +var _ test.Subject = Builder{} diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go new file mode 100644 index 0000000000..2e50f486d2 --- /dev/null +++ b/test/e2e/test/logstash/checks.go @@ -0,0 +1,64 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + + +// CheckSecrets checks that expected secrets have been created. +func CheckSecrets(b Builder, k *test.K8sClient) test.Step { + return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { + logstashName := b.Logstash.Name + // hardcode all secret names and keys to catch any breaking change + expected := []test.ExpectedSecret{ + { + Name: logstashName + "-ls-config", + Keys: []string{"logstash.yml"}, + Labels: map[string]string{ + "eck.k8s.elastic.co/credentials": "true", + "logstash.k8s.elastic.co/name": logstashName, + }, + }, + } + return expected + }) +} + +func CheckStatus(b Builder, k *test.K8sClient) test.Step { + return test.Step{ + Name: "Logstash status should have the correct status", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { + return err + } + + logstash.Status.ObservedGeneration = 0 + + expected := logstashv1alpha1.LogstashStatus{ + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, + Version: b.Logstash.Spec.Version, + } + if logstash.Status != expected { + return fmt.Errorf("expected status %+v but got %+v", expected, logstash.Status) + } + return nil + }), + } +} + +func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { + println(test.Ctx().TestTimeout) + // TODO: Add stack checks + return test.StepList{} +} diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go new file mode 100644 index 0000000000..2c66762429 --- /dev/null +++ b/test/e2e/test/logstash/steps.go @@ -0,0 +1,155 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + //"k8s.io/apimachinery/pkg/types" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/generation" +) + +func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { + return []test.Step{ + { + Name: "K8S should be accessible", + Test: test.Eventually(func() error { + pods := corev1.PodList{} + return k.Client.List(context.Background(), &pods) + }), + }, + { + Name: "Label test pods", + Test: test.Eventually(func() error { + return test.LabelTestPods( + k.Client, + test.Ctx(), + run.TestNameLabel, + b.Logstash.Labels[run.TestNameLabel]) + }), + Skip: func() bool { + return test.Ctx().Local + }, + }, + { + Name: "Logstash CRDs should exist", + Test: test.Eventually(func() error { + crd := &logstashv1alpha1.LogstashList{} + return k.Client.List(context.Background(), crd) + }), + }, + { + Name: "Remove Logstash if it already exists", + Test: test.Eventually(func() error { + err := k.Client.Delete(context.Background(), &b.Logstash) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + // wait for pods to disappear + return k.CheckPodCount(0, test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name)...) + }), + }, + } +} + +func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Submitting the Logstash resource should succeed", + Test: test.Eventually(func() error { + return k.CreateOrUpdate(&b.Logstash) + }), + }, + { + Name: "Logstash should be created", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + return k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash) + }), + }, + } +} + +func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + CheckSecrets(b, k), + CheckStatus(b, k), + checks.CheckServices(b, k), + checks.CheckServicesEndpoints(b, k), + checks.CheckPods(b, k), + } +} + +func (b Builder) UpgradeTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Updating the Logstash spec succeed", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { + return err + } + logstash.Spec = b.Logstash.Spec + return k.Client.Update(context.Background(), &logstash) + }), + }} +} + +func (b Builder) MutationTestSteps(k *test.K8sClient) test.StepList { + var entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation int64 + isMutated := b.MutatedFrom != nil + + return test.StepList{ + generation.RetrieveGenerationsStep(&b.Logstash, k, &entSearchGenerationBeforeMutation, &entSearchObservedGenerationBeforeMutation), + }.WithSteps(test.AnnotatePodsWithBuilderHash(b, b.MutatedFrom, k)). + WithSteps(b.UpgradeTestSteps(k)). + WithSteps(b.CheckK8sTestSteps(k)). + WithSteps(b.CheckStackTestSteps(k)). + WithStep(generation.CompareObjectGenerationsStep(&b.Logstash, k, isMutated, entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation)) +} + +func (b Builder) DeletionTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Deleting Logstash should return no error", + Test: test.Eventually(func() error { + err := k.Client.Delete(context.Background(), &b.Logstash) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + return nil + }), + }, + { + Name: "Logstash should not be there anymore", + Test: test.Eventually(func() error { + objCopy := k8s.DeepCopyObject(&b.Logstash) + err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), objCopy) + if err != nil && apierrors.IsNotFound(err) { + return nil + } + return fmt.Errorf("expected 404 not found API error here. got: %w", err) + }), + }, + { + Name: "Logstash pods should eventually be removed", + Test: test.Eventually(func() error { + return k.CheckPodCount(0, b.ListOptions()...) + }), + }, + } +} From 6eabf4c0796a4d54c12882a850744ff464300ea5 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Tue, 14 Feb 2023 18:50:49 -0500 Subject: [PATCH 009/160] Temporarily take out probes --- pkg/controller/common/container/defaulter.go | 7 -- .../common/defaults/pod_template.go | 6 -- pkg/controller/logstash/pod.go | 93 ++++++++++--------- test/e2e/test/logstash/builder.go | 13 ++- test/e2e/test/logstash/checks.go | 7 +- test/e2e/test/logstash/steps.go | 11 ++- 6 files changed, 62 insertions(+), 75 deletions(-) diff --git a/pkg/controller/common/container/defaulter.go b/pkg/controller/common/container/defaulter.go index 0b03d42aa0..c007b0be79 100644 --- a/pkg/controller/common/container/defaulter.go +++ b/pkg/controller/common/container/defaulter.go @@ -96,13 +96,6 @@ func (d Defaulter) WithReadinessProbe(readinessProbe *corev1.Probe) Defaulter { return d } -func (d Defaulter) WithLivenessProbe(livenessProbe *corev1.Probe) Defaulter { - if d.base.LivenessProbe == nil { - d.base.LivenessProbe = livenessProbe - } - return d -} - // envExists checks if an env var with the given name already exists in the provided slice. func (d Defaulter) envExists(name string) bool { for _, v := range d.base.Env { diff --git a/pkg/controller/common/defaults/pod_template.go b/pkg/controller/common/defaults/pod_template.go index 073223a0c0..81cfea9331 100644 --- a/pkg/controller/common/defaults/pod_template.go +++ b/pkg/controller/common/defaults/pod_template.go @@ -121,12 +121,6 @@ func (b *PodTemplateBuilder) WithReadinessProbe(readinessProbe corev1.Probe) *Po return b } -// WithLivenessProbe sets up the given liveness probe, unless already provided in the template. -func (b *PodTemplateBuilder) WithLivenessProbe(livenessProbe corev1.Probe) *PodTemplateBuilder { - b.containerDefaulter.WithLivenessProbe(&livenessProbe) - return b -} - // WithAffinity sets a default affinity, unless already provided in the template. // An empty affinity in the spec is not overridden. func (b *PodTemplateBuilder) WithAffinity(affinity *corev1.Affinity) *PodTemplateBuilder { diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index d6c139b83a..281757d135 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -11,7 +11,8 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/apimachinery/pkg/util/intstr" + + // "k8s.io/apimachinery/pkg/util/intstr" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" @@ -81,8 +82,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - //WithReadinessProbe(readinessProbe(false)). - //WithLivenessProbe(livenessProbe(false)). + // WithReadinessProbe(readinessProbe(false)). + // WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled @@ -102,46 +103,46 @@ func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.Conta } } -// readinessProbe is the readiness probe for the Logstash container -func readinessProbe(useTLS bool) corev1.Probe { - scheme := corev1.URISchemeHTTP - if useTLS { - scheme = corev1.URISchemeHTTPS - } - return corev1.Probe{ - FailureThreshold: 3, - InitialDelaySeconds: 30, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Port: intstr.FromInt(network.HTTPPort), - Path: "/", - Scheme: scheme, - }, - }, - } -} - -// livenessProbe is the liveness probe for the Logstash container -func livenessProbe(useTLS bool) corev1.Probe { - scheme := corev1.URISchemeHTTP - if useTLS { - scheme = corev1.URISchemeHTTPS - } - return corev1.Probe{ - FailureThreshold: 3, - InitialDelaySeconds: 60, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Port: intstr.FromInt(network.HTTPPort), - Path: "/", - Scheme: scheme, - }, - }, - } -} +//// readinessProbe is the readiness probe for the Logstash container +// func readinessProbe(useTLS bool) corev1.Probe { +// scheme := corev1.URISchemeHTTP +// if useTLS { +// scheme = corev1.URISchemeHTTPS +// } +// return corev1.Probe{ +// FailureThreshold: 3, +// InitialDelaySeconds: 30, +// PeriodSeconds: 10, +// SuccessThreshold: 1, +// TimeoutSeconds: 5, +// ProbeHandler: corev1.ProbeHandler{ +// HTTPGet: &corev1.HTTPGetAction{ +// Port: intstr.FromInt(network.HTTPPort), +// Path: "/", +// Scheme: scheme, +// }, +// }, +// } +//} +// +//// livenessProbe is the liveness probe for the Logstash container +// func livenessProbe(useTLS bool) corev1.Probe { +// scheme := corev1.URISchemeHTTP +// if useTLS { +// scheme = corev1.URISchemeHTTPS +// } +// return corev1.Probe{ +// FailureThreshold: 3, +// InitialDelaySeconds: 60, +// PeriodSeconds: 10, +// SuccessThreshold: 1, +// TimeoutSeconds: 5, +// ProbeHandler: corev1.ProbeHandler{ +// HTTPGet: &corev1.HTTPGetAction{ +// Port: intstr.FromInt(network.HTTPPort), +// Path: "/", +// Scheme: scheme, +// }, +// }, +// } +//} diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 8b08b9119d..8ae6cd1678 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -18,7 +18,7 @@ import ( ) type Builder struct { - Logstash v1alpha1.Logstash + Logstash v1alpha1.Logstash MutatedFrom *Builder } @@ -40,15 +40,15 @@ func newBuilder(name, randSuffix string) Builder { Logstash: v1alpha1.Logstash{ ObjectMeta: meta, Spec: v1alpha1.LogstashSpec{ - Count: 1, + Count: 1, Version: def.Version, }, }, }. - WithImage(def.Image). - WithSuffix(randSuffix). - WithLabel(run.TestNameLabel, name). - WithPodLabel(run.TestNameLabel, name) + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) } func (b Builder) WithImage(image string) Builder { @@ -134,7 +134,6 @@ func (b Builder) ListOptions() []client.ListOption { return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) } - func (b Builder) SkipTest() bool { supportedVersions := version.SupportedLogstashVersions diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 2e50f486d2..6c8ed2d188 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -13,7 +13,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) - // CheckSecrets checks that expected secrets have been created. func CheckSecrets(b Builder, k *test.K8sClient) test.Step { return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { @@ -25,7 +24,7 @@ func CheckSecrets(b Builder, k *test.K8sClient) test.Step { Keys: []string{"logstash.yml"}, Labels: map[string]string{ "eck.k8s.elastic.co/credentials": "true", - "logstash.k8s.elastic.co/name": logstashName, + "logstash.k8s.elastic.co/name": logstashName, }, }, } @@ -45,8 +44,8 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { logstash.Status.ObservedGeneration = 0 expected := logstashv1alpha1.LogstashStatus{ - ExpectedNodes: b.Logstash.Spec.Count, - AvailableNodes: b.Logstash.Spec.Count, + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, Version: b.Logstash.Spec.Version, } if logstash.Status != expected { diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index 2c66762429..44f2a5f4e0 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -10,12 +10,13 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - //"k8s.io/apimachinery/pkg/types" + + // "k8s.io/apimachinery/pkg/types" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + // mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -52,7 +53,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { return k.Client.List(context.Background(), crd) }), }, - { + { Name: "Remove Logstash if it already exists", Test: test.Eventually(func() error { err := k.Client.Delete(context.Background(), &b.Logstash) From d4908b72314d9fd026f75be492674c3cd6407604 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 15:20:43 -0500 Subject: [PATCH 010/160] Revert "Temporarily take out probes" This reverts commit 6eabf4c0796a4d54c12882a850744ff464300ea5. --- pkg/controller/common/container/defaulter.go | 7 ++ .../common/defaults/pod_template.go | 6 ++ pkg/controller/logstash/pod.go | 93 +++++++++---------- test/e2e/test/logstash/builder.go | 13 +-- test/e2e/test/logstash/checks.go | 7 +- test/e2e/test/logstash/steps.go | 11 +-- 6 files changed, 75 insertions(+), 62 deletions(-) diff --git a/pkg/controller/common/container/defaulter.go b/pkg/controller/common/container/defaulter.go index c007b0be79..0b03d42aa0 100644 --- a/pkg/controller/common/container/defaulter.go +++ b/pkg/controller/common/container/defaulter.go @@ -96,6 +96,13 @@ func (d Defaulter) WithReadinessProbe(readinessProbe *corev1.Probe) Defaulter { return d } +func (d Defaulter) WithLivenessProbe(livenessProbe *corev1.Probe) Defaulter { + if d.base.LivenessProbe == nil { + d.base.LivenessProbe = livenessProbe + } + return d +} + // envExists checks if an env var with the given name already exists in the provided slice. func (d Defaulter) envExists(name string) bool { for _, v := range d.base.Env { diff --git a/pkg/controller/common/defaults/pod_template.go b/pkg/controller/common/defaults/pod_template.go index 81cfea9331..073223a0c0 100644 --- a/pkg/controller/common/defaults/pod_template.go +++ b/pkg/controller/common/defaults/pod_template.go @@ -121,6 +121,12 @@ func (b *PodTemplateBuilder) WithReadinessProbe(readinessProbe corev1.Probe) *Po return b } +// WithLivenessProbe sets up the given liveness probe, unless already provided in the template. +func (b *PodTemplateBuilder) WithLivenessProbe(livenessProbe corev1.Probe) *PodTemplateBuilder { + b.containerDefaulter.WithLivenessProbe(&livenessProbe) + return b +} + // WithAffinity sets a default affinity, unless already provided in the template. // An empty affinity in the spec is not overridden. func (b *PodTemplateBuilder) WithAffinity(affinity *corev1.Affinity) *PodTemplateBuilder { diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 281757d135..d6c139b83a 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -11,8 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - - // "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/apimachinery/pkg/util/intstr" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" @@ -82,8 +81,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - // WithReadinessProbe(readinessProbe(false)). - // WithLivenessProbe(livenessProbe(false)). + //WithReadinessProbe(readinessProbe(false)). + //WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled @@ -103,46 +102,46 @@ func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.Conta } } -//// readinessProbe is the readiness probe for the Logstash container -// func readinessProbe(useTLS bool) corev1.Probe { -// scheme := corev1.URISchemeHTTP -// if useTLS { -// scheme = corev1.URISchemeHTTPS -// } -// return corev1.Probe{ -// FailureThreshold: 3, -// InitialDelaySeconds: 30, -// PeriodSeconds: 10, -// SuccessThreshold: 1, -// TimeoutSeconds: 5, -// ProbeHandler: corev1.ProbeHandler{ -// HTTPGet: &corev1.HTTPGetAction{ -// Port: intstr.FromInt(network.HTTPPort), -// Path: "/", -// Scheme: scheme, -// }, -// }, -// } -//} -// -//// livenessProbe is the liveness probe for the Logstash container -// func livenessProbe(useTLS bool) corev1.Probe { -// scheme := corev1.URISchemeHTTP -// if useTLS { -// scheme = corev1.URISchemeHTTPS -// } -// return corev1.Probe{ -// FailureThreshold: 3, -// InitialDelaySeconds: 60, -// PeriodSeconds: 10, -// SuccessThreshold: 1, -// TimeoutSeconds: 5, -// ProbeHandler: corev1.ProbeHandler{ -// HTTPGet: &corev1.HTTPGetAction{ -// Port: intstr.FromInt(network.HTTPPort), -// Path: "/", -// Scheme: scheme, -// }, -// }, -// } -//} +// readinessProbe is the readiness probe for the Logstash container +func readinessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 30, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} + +// livenessProbe is the liveness probe for the Logstash container +func livenessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 60, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 8ae6cd1678..8b08b9119d 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -18,7 +18,7 @@ import ( ) type Builder struct { - Logstash v1alpha1.Logstash + Logstash v1alpha1.Logstash MutatedFrom *Builder } @@ -40,15 +40,15 @@ func newBuilder(name, randSuffix string) Builder { Logstash: v1alpha1.Logstash{ ObjectMeta: meta, Spec: v1alpha1.LogstashSpec{ - Count: 1, + Count: 1, Version: def.Version, }, }, }. - WithImage(def.Image). - WithSuffix(randSuffix). - WithLabel(run.TestNameLabel, name). - WithPodLabel(run.TestNameLabel, name) + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) } func (b Builder) WithImage(image string) Builder { @@ -134,6 +134,7 @@ func (b Builder) ListOptions() []client.ListOption { return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) } + func (b Builder) SkipTest() bool { supportedVersions := version.SupportedLogstashVersions diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 6c8ed2d188..2e50f486d2 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -13,6 +13,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) + // CheckSecrets checks that expected secrets have been created. func CheckSecrets(b Builder, k *test.K8sClient) test.Step { return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { @@ -24,7 +25,7 @@ func CheckSecrets(b Builder, k *test.K8sClient) test.Step { Keys: []string{"logstash.yml"}, Labels: map[string]string{ "eck.k8s.elastic.co/credentials": "true", - "logstash.k8s.elastic.co/name": logstashName, + "logstash.k8s.elastic.co/name": logstashName, }, }, } @@ -44,8 +45,8 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { logstash.Status.ObservedGeneration = 0 expected := logstashv1alpha1.LogstashStatus{ - ExpectedNodes: b.Logstash.Spec.Count, - AvailableNodes: b.Logstash.Spec.Count, + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, Version: b.Logstash.Spec.Version, } if logstash.Status != expected { diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index 44f2a5f4e0..2c66762429 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -10,13 +10,12 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - - // "k8s.io/apimachinery/pkg/types" + //"k8s.io/apimachinery/pkg/types" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - // mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -53,7 +52,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { return k.Client.List(context.Background(), crd) }), }, - { + { Name: "Remove Logstash if it already exists", Test: test.Eventually(func() error { err := k.Client.Delete(context.Background(), &b.Logstash) From b5c775e58b7075f17b89e7f1a6388afb084269db Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 15:20:55 -0500 Subject: [PATCH 011/160] Revert "Add e2e tests" This reverts commit 8016b7b414be3bd098d4e8371d3465e866d6f95b. Remving e2e tests to get e2e tests prior to logstash working --- config/crds/v1/all-crds.yaml | 4 - .../logstash.k8s.elastic.co_logstashes.yaml | 4 - .../eck-operator-crds/templates/all-crds.yaml | 4 - pkg/apis/logstash/v1alpha1/logstash_types.go | 1 - .../logstash/v1alpha1/validations_test.go | 5 + .../v1alpha1/zz_generated.deepcopy.go | 3 +- pkg/controller/common/version/version.go | 2 +- pkg/controller/logstash/pod.go | 4 +- test/e2e/logstash/logstash_test.go | 36 ---- test/e2e/test/k8s_client.go | 14 -- test/e2e/test/logstash/builder.go | 146 ----------------- test/e2e/test/logstash/checks.go | 64 -------- test/e2e/test/logstash/steps.go | 155 ------------------ 13 files changed, 10 insertions(+), 432 deletions(-) delete mode 100644 test/e2e/logstash/logstash_test.go delete mode 100644 test/e2e/test/logstash/builder.go delete mode 100644 test/e2e/test/logstash/checks.go delete mode 100644 test/e2e/test/logstash/steps.go diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 968393ef3d..d6a285a6dc 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9631,10 +9631,6 @@ spec: served: true storage: true subresources: - scale: - labelSelectorPath: .status.selector - specReplicasPath: .spec.count - statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index b652b0ed80..1d86f803e1 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -7994,8 +7994,4 @@ spec: served: true storage: true subresources: - scale: - labelSelectorPath: .status.selector - specReplicasPath: .spec.count - statusReplicasPath: .status.count status: {} diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 24afce4ccd..347de6c534 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9685,10 +9685,6 @@ spec: served: true storage: true subresources: - scale: - labelSelectorPath: .status.selector - specReplicasPath: .spec.count - statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index c0e97542fd..47c12f4a87 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -89,7 +89,6 @@ type LogstashStatus struct { // +kubebuilder:printcolumn:name="expected",type="integer",JSONPath=".status.expectedNodes",description="Expected nodes" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Logstash version" -// +kubebuilder:subresource:scale:specpath=.spec.count,statuspath=.status.count,selectorpath=.status.selector // +kubebuilder:storageversion type Logstash struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 08cd574aa4..4b9f1ebe91 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -166,6 +166,11 @@ func Test_checkSupportedVersion(t *testing.T) { version: "8.7.1", wantErr: false, }, + { + name: "at min supported", + version: "8.7.0", + wantErr: false, + }, } { t.Run(tt.name, func(t *testing.T) { a := Logstash{ diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index 42ca5a613e..cb78272400 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -10,8 +10,9 @@ package v1alpha1 import ( - "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "k8s.io/apimachinery/pkg/runtime" + + v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index 0959920647..d359f18371 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,7 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} - SupportedLogstashVersions = MinMaxVersion{Min: From(8, 6, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 7, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index d6c139b83a..f6a4af0146 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -81,8 +81,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - //WithReadinessProbe(readinessProbe(false)). - //WithLivenessProbe(livenessProbe(false)). + WithReadinessProbe(readinessProbe(false)). + WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go deleted file mode 100644 index d994ad81e2..0000000000 --- a/test/e2e/logstash/logstash_test.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -//go:build logstash || e2e - -package logstash - -import ( - "testing" - - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" -) - -func TestSingleLogstash(t *testing.T) { - name := "test-single-logstash" - logstashBuilder := logstash.NewBuilder(name). - WithNodeCount(1) - test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) -} - -func TestLogstashServerVersionUpgradeToLatest8x(t *testing.T) { - srcVersion, dstVersion := test.GetUpgradePathTo8x(test.Ctx().ElasticStackVersion) - - name := "test-ls-version-upgrade-8x" - - logstash := logstash.NewBuilder(name). - WithNodeCount(2). - WithVersion(srcVersion). - WithRestrictedSecurityContext() - - logstashUpgraded := logstash.WithVersion(dstVersion).WithMutatedFrom(&logstash) - - test.RunMutations(t, []test.Builder{logstash}, []test.Builder{logstashUpgraded}) -} diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index f3b4d13ddf..8989fc2e82 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -33,7 +33,6 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/agent" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/apmserver" beatcommon "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/common" @@ -43,7 +42,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/kibana" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/maps" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) @@ -94,9 +92,6 @@ func CreateClient() (k8s.Client, error) { if err := agentv1alpha1.AddToScheme(scheme.Scheme); err != nil { return nil, err } - if err := logstashv1alpha1.AddToScheme(scheme.Scheme); err != nil { - return nil, err - } client, err := k8sclient.New(cfg, k8sclient.Options{Scheme: scheme.Scheme}) if err != nil { return nil, err @@ -436,15 +431,6 @@ func AgentPodListOptions(agentNamespace, agentName string) []k8sclient.ListOptio return []k8sclient.ListOption{ns, matchLabels} } -func LogstashPodListOptions(logstashNamespace, logstashName string) []k8sclient.ListOption { - ns := k8sclient.InNamespace(logstashNamespace) - matchLabels := k8sclient.MatchingLabels(map[string]string{ - commonv1.TypeLabelName: logstash.TypeLabelValue, - logstash.NameLabelName: logstashName, - }) - return []k8sclient.ListOption{ns, matchLabels} -} - func BeatPodListOptions(beatNamespace, beatName, beatType string) []k8sclient.ListOption { ns := k8sclient.InNamespace(beatNamespace) matchLabels := k8sclient.MatchingLabels(map[string]string{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go deleted file mode 100644 index 8b08b9119d..0000000000 --- a/test/e2e/test/logstash/builder.go +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/rand" - "sigs.k8s.io/controller-runtime/pkg/client" - - "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" -) - -type Builder struct { - Logstash v1alpha1.Logstash - MutatedFrom *Builder -} - -func NewBuilder(name string) Builder { - return newBuilder(name, rand.String(4)) -} - -func NewBuilderWithoutSuffix(name string) Builder { - return newBuilder(name, "") -} - -func newBuilder(name, randSuffix string) Builder { - meta := metav1.ObjectMeta{ - Name: name, - Namespace: test.Ctx().ManagedNamespace(0), - } - def := test.Ctx().ImageDefinitionFor(v1alpha1.Kind) - return Builder{ - Logstash: v1alpha1.Logstash{ - ObjectMeta: meta, - Spec: v1alpha1.LogstashSpec{ - Count: 1, - Version: def.Version, - }, - }, - }. - WithImage(def.Image). - WithSuffix(randSuffix). - WithLabel(run.TestNameLabel, name). - WithPodLabel(run.TestNameLabel, name) -} - -func (b Builder) WithImage(image string) Builder { - b.Logstash.Spec.Image = image - return b -} - -func (b Builder) WithSuffix(suffix string) Builder { - if suffix != "" { - b.Logstash.ObjectMeta.Name = b.Logstash.ObjectMeta.Name + "-" + suffix - } - return b -} - -func (b Builder) WithLabel(key, value string) Builder { - if b.Logstash.Labels == nil { - b.Logstash.Labels = make(map[string]string) - } - b.Logstash.Labels[key] = value - - return b -} - -// WithRestrictedSecurityContext helps to enforce a restricted security context on the objects. -func (b Builder) WithRestrictedSecurityContext() Builder { - b.Logstash.Spec.PodTemplate.Spec.SecurityContext = test.DefaultSecurityContext() - return b -} - -func (b Builder) WithNamespace(namespace string) Builder { - b.Logstash.ObjectMeta.Namespace = namespace - return b -} - -func (b Builder) WithVersion(version string) Builder { - b.Logstash.Spec.Version = version - return b -} - -func (b Builder) WithNodeCount(count int) Builder { - b.Logstash.Spec.Count = int32(count) - return b -} - -// WithPodLabel sets the label in the pod template. All invocations can be removed when -// https://github.com/elastic/cloud-on-k8s/issues/2652 is implemented. -func (b Builder) WithPodLabel(key, value string) Builder { - labels := b.Logstash.Spec.PodTemplate.Labels - if labels == nil { - labels = make(map[string]string) - } - labels[key] = value - b.Logstash.Spec.PodTemplate.Labels = labels - return b -} - -func (b Builder) WithMutatedFrom(mutatedFrom *Builder) Builder { - b.MutatedFrom = mutatedFrom - return b -} - -func (b Builder) NSN() types.NamespacedName { - return k8s.ExtractNamespacedName(&b.Logstash) -} - -func (b Builder) Kind() string { - return v1alpha1.Kind -} - -func (b Builder) Spec() interface{} { - return b.Logstash.Spec -} - -func (b Builder) Count() int32 { - return b.Logstash.Spec.Count -} - -func (b Builder) ServiceName() string { - return b.Logstash.Name + "-ls-http" -} - -func (b Builder) ListOptions() []client.ListOption { - return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) -} - - -func (b Builder) SkipTest() bool { - supportedVersions := version.SupportedLogstashVersions - - ver := version.MustParse(b.Logstash.Spec.Version) - return supportedVersions.WithinRange(ver) != nil -} - -var _ test.Builder = Builder{} -var _ test.Subject = Builder{} diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go deleted file mode 100644 index 2e50f486d2..0000000000 --- a/test/e2e/test/logstash/checks.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - "context" - "fmt" - - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" -) - - -// CheckSecrets checks that expected secrets have been created. -func CheckSecrets(b Builder, k *test.K8sClient) test.Step { - return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { - logstashName := b.Logstash.Name - // hardcode all secret names and keys to catch any breaking change - expected := []test.ExpectedSecret{ - { - Name: logstashName + "-ls-config", - Keys: []string{"logstash.yml"}, - Labels: map[string]string{ - "eck.k8s.elastic.co/credentials": "true", - "logstash.k8s.elastic.co/name": logstashName, - }, - }, - } - return expected - }) -} - -func CheckStatus(b Builder, k *test.K8sClient) test.Step { - return test.Step{ - Name: "Logstash status should have the correct status", - Test: test.Eventually(func() error { - var logstash logstashv1alpha1.Logstash - if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { - return err - } - - logstash.Status.ObservedGeneration = 0 - - expected := logstashv1alpha1.LogstashStatus{ - ExpectedNodes: b.Logstash.Spec.Count, - AvailableNodes: b.Logstash.Spec.Count, - Version: b.Logstash.Spec.Version, - } - if logstash.Status != expected { - return fmt.Errorf("expected status %+v but got %+v", expected, logstash.Status) - } - return nil - }), - } -} - -func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { - println(test.Ctx().TestTimeout) - // TODO: Add stack checks - return test.StepList{} -} diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go deleted file mode 100644 index 2c66762429..0000000000 --- a/test/e2e/test/logstash/steps.go +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - "context" - "fmt" - - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - //"k8s.io/apimachinery/pkg/types" - - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/generation" -) - -func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { - return []test.Step{ - { - Name: "K8S should be accessible", - Test: test.Eventually(func() error { - pods := corev1.PodList{} - return k.Client.List(context.Background(), &pods) - }), - }, - { - Name: "Label test pods", - Test: test.Eventually(func() error { - return test.LabelTestPods( - k.Client, - test.Ctx(), - run.TestNameLabel, - b.Logstash.Labels[run.TestNameLabel]) - }), - Skip: func() bool { - return test.Ctx().Local - }, - }, - { - Name: "Logstash CRDs should exist", - Test: test.Eventually(func() error { - crd := &logstashv1alpha1.LogstashList{} - return k.Client.List(context.Background(), crd) - }), - }, - { - Name: "Remove Logstash if it already exists", - Test: test.Eventually(func() error { - err := k.Client.Delete(context.Background(), &b.Logstash) - if err != nil && !apierrors.IsNotFound(err) { - return err - } - // wait for pods to disappear - return k.CheckPodCount(0, test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name)...) - }), - }, - } -} - -func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { - return test.StepList{ - { - Name: "Submitting the Logstash resource should succeed", - Test: test.Eventually(func() error { - return k.CreateOrUpdate(&b.Logstash) - }), - }, - { - Name: "Logstash should be created", - Test: test.Eventually(func() error { - var logstash logstashv1alpha1.Logstash - return k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash) - }), - }, - } -} - -func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { - return test.StepList{ - CheckSecrets(b, k), - CheckStatus(b, k), - checks.CheckServices(b, k), - checks.CheckServicesEndpoints(b, k), - checks.CheckPods(b, k), - } -} - -func (b Builder) UpgradeTestSteps(k *test.K8sClient) test.StepList { - return test.StepList{ - { - Name: "Updating the Logstash spec succeed", - Test: test.Eventually(func() error { - var logstash logstashv1alpha1.Logstash - if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { - return err - } - logstash.Spec = b.Logstash.Spec - return k.Client.Update(context.Background(), &logstash) - }), - }} -} - -func (b Builder) MutationTestSteps(k *test.K8sClient) test.StepList { - var entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation int64 - isMutated := b.MutatedFrom != nil - - return test.StepList{ - generation.RetrieveGenerationsStep(&b.Logstash, k, &entSearchGenerationBeforeMutation, &entSearchObservedGenerationBeforeMutation), - }.WithSteps(test.AnnotatePodsWithBuilderHash(b, b.MutatedFrom, k)). - WithSteps(b.UpgradeTestSteps(k)). - WithSteps(b.CheckK8sTestSteps(k)). - WithSteps(b.CheckStackTestSteps(k)). - WithStep(generation.CompareObjectGenerationsStep(&b.Logstash, k, isMutated, entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation)) -} - -func (b Builder) DeletionTestSteps(k *test.K8sClient) test.StepList { - return test.StepList{ - { - Name: "Deleting Logstash should return no error", - Test: test.Eventually(func() error { - err := k.Client.Delete(context.Background(), &b.Logstash) - if err != nil && !apierrors.IsNotFound(err) { - return err - } - return nil - }), - }, - { - Name: "Logstash should not be there anymore", - Test: test.Eventually(func() error { - objCopy := k8s.DeepCopyObject(&b.Logstash) - err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), objCopy) - if err != nil && apierrors.IsNotFound(err) { - return nil - } - return fmt.Errorf("expected 404 not found API error here. got: %w", err) - }), - }, - { - Name: "Logstash pods should eventually be removed", - Test: test.Eventually(func() error { - return k.CheckPodCount(0, b.ListOptions()...) - }), - }, - } -} From 33371ada4f43e1578d3676960cb5b14e6ae513d2 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 16:02:10 -0500 Subject: [PATCH 012/160] Fix linter --- pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index cb78272400..42ca5a613e 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -10,9 +10,8 @@ package v1alpha1 import ( + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "k8s.io/apimachinery/pkg/runtime" - - v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. From 8e6e707523a4bd5be64e88896a0be6be32ecccaa Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 16:19:36 -0500 Subject: [PATCH 013/160] Add logstash config details --- config/e2e/rbac.yaml | 13 +++++++++++++ deploy/eck-operator/templates/cluster-roles.yaml | 6 ++++++ hack/operatorhub/config.yaml | 3 +++ test/e2e/test/elasticsearch/checks_k8s.go | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config/e2e/rbac.yaml b/config/e2e/rbac.yaml index d309317c88..00f86dea81 100644 --- a/config/e2e/rbac.yaml +++ b/config/e2e/rbac.yaml @@ -296,6 +296,19 @@ rules: - update - patch - delete + - apiGroups : + - logstash.k8s.elastic.co + resources: + - logstashes + - logstashes/status + verbs: + - get + - list + - watch + - create + - update + - patch + - delete - apiGroups: - storage.k8s.io resources: diff --git a/deploy/eck-operator/templates/cluster-roles.yaml b/deploy/eck-operator/templates/cluster-roles.yaml index c6fa56cf71..1b623f37fe 100644 --- a/deploy/eck-operator/templates/cluster-roles.yaml +++ b/deploy/eck-operator/templates/cluster-roles.yaml @@ -50,6 +50,9 @@ rules: - apiGroups: ["stackconfigpolicy.k8s.elastic.co"] resources: ["stackconfigpolicies"] verbs: ["get", "list", "watch"] + - apiGroups: ["logstash.k8s.elastic.co"] + resources: ["logstashes"] + verbs: ["get", "list", "watch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole @@ -87,4 +90,7 @@ rules: - apiGroups: ["stackconfigpolicy.k8s.elastic.co"] resources: ["stackconfigpolicies"] verbs: ["create", "delete", "deletecollection", "patch", "update"] + - apiGroups: ["logstash.k8s.elastic.co"] + resources: ["logstashes"] + verbs: ["create", "delete", "deletecollection", "patch", "update"] {{- end -}} diff --git a/hack/operatorhub/config.yaml b/hack/operatorhub/config.yaml index e93f8514d4..2a2da9062c 100644 --- a/hack/operatorhub/config.yaml +++ b/hack/operatorhub/config.yaml @@ -29,6 +29,9 @@ crds: - name: stackconfigpolicies.stackconfigpolicy.k8s.elastic.co displayName: Elastic Stack Config Policy description: Elastic Stack Config Policy + - name: logstashes.stackconfigpolicy.k8s.elastic.co + displayName: Logstash + description: Logstash instance packages: - outputPath: community-operators packageName: elastic-cloud-eck diff --git a/test/e2e/test/elasticsearch/checks_k8s.go b/test/e2e/test/elasticsearch/checks_k8s.go index b0cc7b114b..b6bbdede91 100644 --- a/test/e2e/test/elasticsearch/checks_k8s.go +++ b/test/e2e/test/elasticsearch/checks_k8s.go @@ -35,7 +35,7 @@ const ( // but it occasionally takes longer for various reasons (long Pod creation time, long volume binding, etc.). // We use a longer timeout here to not be impacted too much by those external factors, and only fail // if things seem to be stuck. - RollingUpgradeTimeout = 30 * time.Minute + RollingUpgradeTimeout = 10 * time.Minute ) func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { From 4afe0dee779d3f1a89f83d934f4c67d0dc3e80c3 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 18:12:18 -0500 Subject: [PATCH 014/160] Fix up typos --- config/webhook/manifests.yaml | 2 +- deploy/eck-operator/templates/_helpers.tpl | 13 +++++++++++++ pkg/apis/common/v1/association.go | 2 -- pkg/apis/logstash/v1alpha1/webhook.go | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 1870792dd2..b2a9dbc85d 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -223,7 +223,7 @@ webhooks: - CREATE - UPDATE resources: - - logstashs + - logstashes sideEffects: None - admissionReviewVersions: - v1alpha1 diff --git a/deploy/eck-operator/templates/_helpers.tpl b/deploy/eck-operator/templates/_helpers.tpl index 424dd0be1f..8c421f7b55 100644 --- a/deploy/eck-operator/templates/_helpers.tpl +++ b/deploy/eck-operator/templates/_helpers.tpl @@ -310,6 +310,19 @@ updating docs/operating-eck/eck-permissions.asciidoc file. - create - update - patch +- apiGroups: + - logstash.k8s.elastic.co + resources: + - logstashes + - logstashes/status + - logstashes/finalizers # needed for ownerReferences with blockOwnerDeletion on OCP + verbs: + - get + - list + - watch + - create + - update + - patch {{- end -}} {{/* diff --git a/pkg/apis/common/v1/association.go b/pkg/apis/common/v1/association.go index 8bcfaa2f23..721055c273 100644 --- a/pkg/apis/common/v1/association.go +++ b/pkg/apis/common/v1/association.go @@ -110,8 +110,6 @@ const ( BeatAssociationType = "beat" BeatMonitoringAssociationType = "beat-monitoring" - LogstashMonitoringAssociationType = "ls-monitoring" - AssociationUnknown AssociationStatus = "" AssociationPending AssociationStatus = "Pending" AssociationEstablished AssociationStatus = "Established" diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go index 1f9bed70b4..76b564678d 100644 --- a/pkg/apis/logstash/v1alpha1/webhook.go +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -26,7 +26,7 @@ var ( validationLog = ulog.Log.WithName("logstash-v1alpha1-validation") ) -// +kubebuilder:webhook:path=/validate-logstash-k8s-elastic-co-v1alpha1-logstash,mutating=false,failurePolicy=ignore,groups=logstash.k8s.elastic.co,resources=logstashs,verbs=create;update,versions=v1alpha1,name=elastic-logstash-validation-v1alpha1.k8s.elastic.co,sideEffects=None,admissionReviewVersions=v1;v1beta1,matchPolicy=Exact +// +kubebuilder:webhook:path=/validate-logstash-k8s-elastic-co-v1alpha1-logstash,mutating=false,failurePolicy=ignore,groups=logstash.k8s.elastic.co,resources=logstashes,verbs=create;update,versions=v1alpha1,name=elastic-logstash-validation-v1alpha1.k8s.elastic.co,sideEffects=None,admissionReviewVersions=v1;v1beta1,matchPolicy=Exact var _ webhook.Validator = &Logstash{} From 5f9040f7dd27ca2b3c1a2d313daeeb84040f4c17 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 18:36:23 -0500 Subject: [PATCH 015/160] Revert "Revert "Add e2e tests"" This reverts commit b5c775e58b7075f17b89e7f1a6388afb084269db. And re-adds the e2e tests --- config/crds/v1/all-crds.yaml | 4 + .../logstash.k8s.elastic.co_logstashes.yaml | 4 + .../eck-operator-crds/templates/all-crds.yaml | 4 + pkg/apis/logstash/v1alpha1/logstash_types.go | 1 + .../logstash/v1alpha1/validations_test.go | 5 - pkg/controller/common/version/version.go | 2 +- pkg/controller/logstash/pod.go | 4 +- test/e2e/logstash/logstash_test.go | 36 ++++ test/e2e/test/k8s_client.go | 14 ++ test/e2e/test/logstash/builder.go | 146 +++++++++++++++++ test/e2e/test/logstash/checks.go | 64 ++++++++ test/e2e/test/logstash/steps.go | 155 ++++++++++++++++++ 12 files changed, 431 insertions(+), 8 deletions(-) create mode 100644 test/e2e/logstash/logstash_test.go create mode 100644 test/e2e/test/logstash/builder.go create mode 100644 test/e2e/test/logstash/checks.go create mode 100644 test/e2e/test/logstash/steps.go diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index d6a285a6dc..968393ef3d 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9631,6 +9631,10 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 1d86f803e1..b652b0ed80 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -7994,4 +7994,8 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 347de6c534..24afce4ccd 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9685,6 +9685,10 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 47c12f4a87..c0e97542fd 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -89,6 +89,7 @@ type LogstashStatus struct { // +kubebuilder:printcolumn:name="expected",type="integer",JSONPath=".status.expectedNodes",description="Expected nodes" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Logstash version" +// +kubebuilder:subresource:scale:specpath=.spec.count,statuspath=.status.count,selectorpath=.status.selector // +kubebuilder:storageversion type Logstash struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 4b9f1ebe91..08cd574aa4 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -166,11 +166,6 @@ func Test_checkSupportedVersion(t *testing.T) { version: "8.7.1", wantErr: false, }, - { - name: "at min supported", - version: "8.7.0", - wantErr: false, - }, } { t.Run(tt.name, func(t *testing.T) { a := Logstash{ diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index d359f18371..0959920647 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,7 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} - SupportedLogstashVersions = MinMaxVersion{Min: From(8, 7, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 6, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index f6a4af0146..d6c139b83a 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -81,8 +81,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - WithReadinessProbe(readinessProbe(false)). - WithLivenessProbe(livenessProbe(false)). + //WithReadinessProbe(readinessProbe(false)). + //WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go new file mode 100644 index 0000000000..d994ad81e2 --- /dev/null +++ b/test/e2e/logstash/logstash_test.go @@ -0,0 +1,36 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +//go:build logstash || e2e + +package logstash + +import ( + "testing" + + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" +) + +func TestSingleLogstash(t *testing.T) { + name := "test-single-logstash" + logstashBuilder := logstash.NewBuilder(name). + WithNodeCount(1) + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + +func TestLogstashServerVersionUpgradeToLatest8x(t *testing.T) { + srcVersion, dstVersion := test.GetUpgradePathTo8x(test.Ctx().ElasticStackVersion) + + name := "test-ls-version-upgrade-8x" + + logstash := logstash.NewBuilder(name). + WithNodeCount(2). + WithVersion(srcVersion). + WithRestrictedSecurityContext() + + logstashUpgraded := logstash.WithVersion(dstVersion).WithMutatedFrom(&logstash) + + test.RunMutations(t, []test.Builder{logstash}, []test.Builder{logstashUpgraded}) +} diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index 8989fc2e82..f3b4d13ddf 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -33,6 +33,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/agent" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/apmserver" beatcommon "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/common" @@ -42,6 +43,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/kibana" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/maps" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) @@ -92,6 +94,9 @@ func CreateClient() (k8s.Client, error) { if err := agentv1alpha1.AddToScheme(scheme.Scheme); err != nil { return nil, err } + if err := logstashv1alpha1.AddToScheme(scheme.Scheme); err != nil { + return nil, err + } client, err := k8sclient.New(cfg, k8sclient.Options{Scheme: scheme.Scheme}) if err != nil { return nil, err @@ -431,6 +436,15 @@ func AgentPodListOptions(agentNamespace, agentName string) []k8sclient.ListOptio return []k8sclient.ListOption{ns, matchLabels} } +func LogstashPodListOptions(logstashNamespace, logstashName string) []k8sclient.ListOption { + ns := k8sclient.InNamespace(logstashNamespace) + matchLabels := k8sclient.MatchingLabels(map[string]string{ + commonv1.TypeLabelName: logstash.TypeLabelValue, + logstash.NameLabelName: logstashName, + }) + return []k8sclient.ListOption{ns, matchLabels} +} + func BeatPodListOptions(beatNamespace, beatName, beatType string) []k8sclient.ListOption { ns := k8sclient.InNamespace(beatNamespace) matchLabels := k8sclient.MatchingLabels(map[string]string{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go new file mode 100644 index 0000000000..8b08b9119d --- /dev/null +++ b/test/e2e/test/logstash/builder.go @@ -0,0 +1,146 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + +type Builder struct { + Logstash v1alpha1.Logstash + MutatedFrom *Builder +} + +func NewBuilder(name string) Builder { + return newBuilder(name, rand.String(4)) +} + +func NewBuilderWithoutSuffix(name string) Builder { + return newBuilder(name, "") +} + +func newBuilder(name, randSuffix string) Builder { + meta := metav1.ObjectMeta{ + Name: name, + Namespace: test.Ctx().ManagedNamespace(0), + } + def := test.Ctx().ImageDefinitionFor(v1alpha1.Kind) + return Builder{ + Logstash: v1alpha1.Logstash{ + ObjectMeta: meta, + Spec: v1alpha1.LogstashSpec{ + Count: 1, + Version: def.Version, + }, + }, + }. + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) +} + +func (b Builder) WithImage(image string) Builder { + b.Logstash.Spec.Image = image + return b +} + +func (b Builder) WithSuffix(suffix string) Builder { + if suffix != "" { + b.Logstash.ObjectMeta.Name = b.Logstash.ObjectMeta.Name + "-" + suffix + } + return b +} + +func (b Builder) WithLabel(key, value string) Builder { + if b.Logstash.Labels == nil { + b.Logstash.Labels = make(map[string]string) + } + b.Logstash.Labels[key] = value + + return b +} + +// WithRestrictedSecurityContext helps to enforce a restricted security context on the objects. +func (b Builder) WithRestrictedSecurityContext() Builder { + b.Logstash.Spec.PodTemplate.Spec.SecurityContext = test.DefaultSecurityContext() + return b +} + +func (b Builder) WithNamespace(namespace string) Builder { + b.Logstash.ObjectMeta.Namespace = namespace + return b +} + +func (b Builder) WithVersion(version string) Builder { + b.Logstash.Spec.Version = version + return b +} + +func (b Builder) WithNodeCount(count int) Builder { + b.Logstash.Spec.Count = int32(count) + return b +} + +// WithPodLabel sets the label in the pod template. All invocations can be removed when +// https://github.com/elastic/cloud-on-k8s/issues/2652 is implemented. +func (b Builder) WithPodLabel(key, value string) Builder { + labels := b.Logstash.Spec.PodTemplate.Labels + if labels == nil { + labels = make(map[string]string) + } + labels[key] = value + b.Logstash.Spec.PodTemplate.Labels = labels + return b +} + +func (b Builder) WithMutatedFrom(mutatedFrom *Builder) Builder { + b.MutatedFrom = mutatedFrom + return b +} + +func (b Builder) NSN() types.NamespacedName { + return k8s.ExtractNamespacedName(&b.Logstash) +} + +func (b Builder) Kind() string { + return v1alpha1.Kind +} + +func (b Builder) Spec() interface{} { + return b.Logstash.Spec +} + +func (b Builder) Count() int32 { + return b.Logstash.Spec.Count +} + +func (b Builder) ServiceName() string { + return b.Logstash.Name + "-ls-http" +} + +func (b Builder) ListOptions() []client.ListOption { + return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) +} + + +func (b Builder) SkipTest() bool { + supportedVersions := version.SupportedLogstashVersions + + ver := version.MustParse(b.Logstash.Spec.Version) + return supportedVersions.WithinRange(ver) != nil +} + +var _ test.Builder = Builder{} +var _ test.Subject = Builder{} diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go new file mode 100644 index 0000000000..2e50f486d2 --- /dev/null +++ b/test/e2e/test/logstash/checks.go @@ -0,0 +1,64 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + + +// CheckSecrets checks that expected secrets have been created. +func CheckSecrets(b Builder, k *test.K8sClient) test.Step { + return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { + logstashName := b.Logstash.Name + // hardcode all secret names and keys to catch any breaking change + expected := []test.ExpectedSecret{ + { + Name: logstashName + "-ls-config", + Keys: []string{"logstash.yml"}, + Labels: map[string]string{ + "eck.k8s.elastic.co/credentials": "true", + "logstash.k8s.elastic.co/name": logstashName, + }, + }, + } + return expected + }) +} + +func CheckStatus(b Builder, k *test.K8sClient) test.Step { + return test.Step{ + Name: "Logstash status should have the correct status", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { + return err + } + + logstash.Status.ObservedGeneration = 0 + + expected := logstashv1alpha1.LogstashStatus{ + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, + Version: b.Logstash.Spec.Version, + } + if logstash.Status != expected { + return fmt.Errorf("expected status %+v but got %+v", expected, logstash.Status) + } + return nil + }), + } +} + +func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { + println(test.Ctx().TestTimeout) + // TODO: Add stack checks + return test.StepList{} +} diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go new file mode 100644 index 0000000000..2c66762429 --- /dev/null +++ b/test/e2e/test/logstash/steps.go @@ -0,0 +1,155 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + //"k8s.io/apimachinery/pkg/types" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/generation" +) + +func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { + return []test.Step{ + { + Name: "K8S should be accessible", + Test: test.Eventually(func() error { + pods := corev1.PodList{} + return k.Client.List(context.Background(), &pods) + }), + }, + { + Name: "Label test pods", + Test: test.Eventually(func() error { + return test.LabelTestPods( + k.Client, + test.Ctx(), + run.TestNameLabel, + b.Logstash.Labels[run.TestNameLabel]) + }), + Skip: func() bool { + return test.Ctx().Local + }, + }, + { + Name: "Logstash CRDs should exist", + Test: test.Eventually(func() error { + crd := &logstashv1alpha1.LogstashList{} + return k.Client.List(context.Background(), crd) + }), + }, + { + Name: "Remove Logstash if it already exists", + Test: test.Eventually(func() error { + err := k.Client.Delete(context.Background(), &b.Logstash) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + // wait for pods to disappear + return k.CheckPodCount(0, test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name)...) + }), + }, + } +} + +func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Submitting the Logstash resource should succeed", + Test: test.Eventually(func() error { + return k.CreateOrUpdate(&b.Logstash) + }), + }, + { + Name: "Logstash should be created", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + return k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash) + }), + }, + } +} + +func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + CheckSecrets(b, k), + CheckStatus(b, k), + checks.CheckServices(b, k), + checks.CheckServicesEndpoints(b, k), + checks.CheckPods(b, k), + } +} + +func (b Builder) UpgradeTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Updating the Logstash spec succeed", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { + return err + } + logstash.Spec = b.Logstash.Spec + return k.Client.Update(context.Background(), &logstash) + }), + }} +} + +func (b Builder) MutationTestSteps(k *test.K8sClient) test.StepList { + var entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation int64 + isMutated := b.MutatedFrom != nil + + return test.StepList{ + generation.RetrieveGenerationsStep(&b.Logstash, k, &entSearchGenerationBeforeMutation, &entSearchObservedGenerationBeforeMutation), + }.WithSteps(test.AnnotatePodsWithBuilderHash(b, b.MutatedFrom, k)). + WithSteps(b.UpgradeTestSteps(k)). + WithSteps(b.CheckK8sTestSteps(k)). + WithSteps(b.CheckStackTestSteps(k)). + WithStep(generation.CompareObjectGenerationsStep(&b.Logstash, k, isMutated, entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation)) +} + +func (b Builder) DeletionTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Deleting Logstash should return no error", + Test: test.Eventually(func() error { + err := k.Client.Delete(context.Background(), &b.Logstash) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + return nil + }), + }, + { + Name: "Logstash should not be there anymore", + Test: test.Eventually(func() error { + objCopy := k8s.DeepCopyObject(&b.Logstash) + err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), objCopy) + if err != nil && apierrors.IsNotFound(err) { + return nil + } + return fmt.Errorf("expected 404 not found API error here. got: %w", err) + }), + }, + { + Name: "Logstash pods should eventually be removed", + Test: test.Eventually(func() error { + return k.CheckPodCount(0, b.ListOptions()...) + }), + }, + } +} From 803b9abf69efa02f1f56300f00e52c36355f179f Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 18:36:56 -0500 Subject: [PATCH 016/160] Revert "Revert "Temporarily take out probes"" This reverts commit d4908b72314d9fd026f75be492674c3cd6407604. --- pkg/controller/common/container/defaulter.go | 7 -- .../common/defaults/pod_template.go | 6 -- pkg/controller/logstash/pod.go | 93 ++++++++++--------- test/e2e/test/logstash/builder.go | 13 ++- test/e2e/test/logstash/checks.go | 7 +- test/e2e/test/logstash/steps.go | 11 ++- 6 files changed, 62 insertions(+), 75 deletions(-) diff --git a/pkg/controller/common/container/defaulter.go b/pkg/controller/common/container/defaulter.go index 0b03d42aa0..c007b0be79 100644 --- a/pkg/controller/common/container/defaulter.go +++ b/pkg/controller/common/container/defaulter.go @@ -96,13 +96,6 @@ func (d Defaulter) WithReadinessProbe(readinessProbe *corev1.Probe) Defaulter { return d } -func (d Defaulter) WithLivenessProbe(livenessProbe *corev1.Probe) Defaulter { - if d.base.LivenessProbe == nil { - d.base.LivenessProbe = livenessProbe - } - return d -} - // envExists checks if an env var with the given name already exists in the provided slice. func (d Defaulter) envExists(name string) bool { for _, v := range d.base.Env { diff --git a/pkg/controller/common/defaults/pod_template.go b/pkg/controller/common/defaults/pod_template.go index 073223a0c0..81cfea9331 100644 --- a/pkg/controller/common/defaults/pod_template.go +++ b/pkg/controller/common/defaults/pod_template.go @@ -121,12 +121,6 @@ func (b *PodTemplateBuilder) WithReadinessProbe(readinessProbe corev1.Probe) *Po return b } -// WithLivenessProbe sets up the given liveness probe, unless already provided in the template. -func (b *PodTemplateBuilder) WithLivenessProbe(livenessProbe corev1.Probe) *PodTemplateBuilder { - b.containerDefaulter.WithLivenessProbe(&livenessProbe) - return b -} - // WithAffinity sets a default affinity, unless already provided in the template. // An empty affinity in the spec is not overridden. func (b *PodTemplateBuilder) WithAffinity(affinity *corev1.Affinity) *PodTemplateBuilder { diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index d6c139b83a..281757d135 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -11,7 +11,8 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/apimachinery/pkg/util/intstr" + + // "k8s.io/apimachinery/pkg/util/intstr" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" @@ -81,8 +82,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - //WithReadinessProbe(readinessProbe(false)). - //WithLivenessProbe(livenessProbe(false)). + // WithReadinessProbe(readinessProbe(false)). + // WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled @@ -102,46 +103,46 @@ func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.Conta } } -// readinessProbe is the readiness probe for the Logstash container -func readinessProbe(useTLS bool) corev1.Probe { - scheme := corev1.URISchemeHTTP - if useTLS { - scheme = corev1.URISchemeHTTPS - } - return corev1.Probe{ - FailureThreshold: 3, - InitialDelaySeconds: 30, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Port: intstr.FromInt(network.HTTPPort), - Path: "/", - Scheme: scheme, - }, - }, - } -} - -// livenessProbe is the liveness probe for the Logstash container -func livenessProbe(useTLS bool) corev1.Probe { - scheme := corev1.URISchemeHTTP - if useTLS { - scheme = corev1.URISchemeHTTPS - } - return corev1.Probe{ - FailureThreshold: 3, - InitialDelaySeconds: 60, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Port: intstr.FromInt(network.HTTPPort), - Path: "/", - Scheme: scheme, - }, - }, - } -} +//// readinessProbe is the readiness probe for the Logstash container +// func readinessProbe(useTLS bool) corev1.Probe { +// scheme := corev1.URISchemeHTTP +// if useTLS { +// scheme = corev1.URISchemeHTTPS +// } +// return corev1.Probe{ +// FailureThreshold: 3, +// InitialDelaySeconds: 30, +// PeriodSeconds: 10, +// SuccessThreshold: 1, +// TimeoutSeconds: 5, +// ProbeHandler: corev1.ProbeHandler{ +// HTTPGet: &corev1.HTTPGetAction{ +// Port: intstr.FromInt(network.HTTPPort), +// Path: "/", +// Scheme: scheme, +// }, +// }, +// } +//} +// +//// livenessProbe is the liveness probe for the Logstash container +// func livenessProbe(useTLS bool) corev1.Probe { +// scheme := corev1.URISchemeHTTP +// if useTLS { +// scheme = corev1.URISchemeHTTPS +// } +// return corev1.Probe{ +// FailureThreshold: 3, +// InitialDelaySeconds: 60, +// PeriodSeconds: 10, +// SuccessThreshold: 1, +// TimeoutSeconds: 5, +// ProbeHandler: corev1.ProbeHandler{ +// HTTPGet: &corev1.HTTPGetAction{ +// Port: intstr.FromInt(network.HTTPPort), +// Path: "/", +// Scheme: scheme, +// }, +// }, +// } +//} diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 8b08b9119d..8ae6cd1678 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -18,7 +18,7 @@ import ( ) type Builder struct { - Logstash v1alpha1.Logstash + Logstash v1alpha1.Logstash MutatedFrom *Builder } @@ -40,15 +40,15 @@ func newBuilder(name, randSuffix string) Builder { Logstash: v1alpha1.Logstash{ ObjectMeta: meta, Spec: v1alpha1.LogstashSpec{ - Count: 1, + Count: 1, Version: def.Version, }, }, }. - WithImage(def.Image). - WithSuffix(randSuffix). - WithLabel(run.TestNameLabel, name). - WithPodLabel(run.TestNameLabel, name) + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) } func (b Builder) WithImage(image string) Builder { @@ -134,7 +134,6 @@ func (b Builder) ListOptions() []client.ListOption { return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) } - func (b Builder) SkipTest() bool { supportedVersions := version.SupportedLogstashVersions diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 2e50f486d2..6c8ed2d188 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -13,7 +13,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) - // CheckSecrets checks that expected secrets have been created. func CheckSecrets(b Builder, k *test.K8sClient) test.Step { return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { @@ -25,7 +24,7 @@ func CheckSecrets(b Builder, k *test.K8sClient) test.Step { Keys: []string{"logstash.yml"}, Labels: map[string]string{ "eck.k8s.elastic.co/credentials": "true", - "logstash.k8s.elastic.co/name": logstashName, + "logstash.k8s.elastic.co/name": logstashName, }, }, } @@ -45,8 +44,8 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { logstash.Status.ObservedGeneration = 0 expected := logstashv1alpha1.LogstashStatus{ - ExpectedNodes: b.Logstash.Spec.Count, - AvailableNodes: b.Logstash.Spec.Count, + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, Version: b.Logstash.Spec.Version, } if logstash.Status != expected { diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index 2c66762429..44f2a5f4e0 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -10,12 +10,13 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - //"k8s.io/apimachinery/pkg/types" + + // "k8s.io/apimachinery/pkg/types" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + // mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -52,7 +53,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { return k.Client.List(context.Background(), crd) }), }, - { + { Name: "Remove Logstash if it already exists", Test: test.Eventually(func() error { err := k.Client.Delete(context.Background(), &b.Logstash) From 0d79bc987fe158feacb38b2568424768d55ae98d Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 09:22:19 -0500 Subject: [PATCH 017/160] Tidying up --- config/samples/logstash/logstash.yaml | 2 +- hack/operatorhub/config.yaml | 2 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 3 +++ pkg/controller/logstash/driver.go | 20 -------------------- test/e2e/test/elasticsearch/checks_k8s.go | 2 +- 5 files changed, 6 insertions(+), 23 deletions(-) diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml index 530891e91a..e6283a9568 100644 --- a/config/samples/logstash/logstash.yaml +++ b/config/samples/logstash/logstash.yaml @@ -6,7 +6,7 @@ spec: version: 8.6.1 nodeSets: - name: default - count: 1 + count: 3 config: node.store.allow_mmap: false --- diff --git a/hack/operatorhub/config.yaml b/hack/operatorhub/config.yaml index 2a2da9062c..ef285e34f0 100644 --- a/hack/operatorhub/config.yaml +++ b/hack/operatorhub/config.yaml @@ -29,7 +29,7 @@ crds: - name: stackconfigpolicies.stackconfigpolicy.k8s.elastic.co displayName: Elastic Stack Config Policy description: Elastic Stack Config Policy - - name: logstashes.stackconfigpolicy.k8s.elastic.co + - name: logstashes.logstash.k8s.elastic.co displayName: Logstash description: Logstash instance packages: diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index c0e97542fd..0d10621327 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -40,6 +40,9 @@ type LogstashSpec struct { ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"` // HTTP holds the HTTP layer configuration for the Logstash Metrics API + // TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks + // a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to + // be opened up for other services: beats, TCP, UDP, etc, inputs // +kubebuilder:validation:Optional HTTP commonv1.HTTPConfig `json:"http,omitempty"` diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 54372a4701..4be3660336 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -82,26 +82,6 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log return results.WithError(err), params.Status } - // _, results = certificates.Reconciler{ - // K8sClient: params.Client, - // DynamicWatches: params.Watches, - // Owner: ¶ms.Logstash, - // TLSOptions: params.Logstash.Spec.HTTP.TLS, - // Namer: logstashv1alpha1.Namer, - // Labels: params.Logstash.GetIdentityLabels(), - // Services: []corev1.Service{*svc}, - // GlobalCA: params.OperatorParams.GlobalCA, - // CACertRotation: params.OperatorParams.CACertRotation, - // CertRotation: params.OperatorParams.CertRotation, - // GarbageCollectSecrets: true, - // }.ReconcileCAAndHTTPCerts(params.Context) - // - // if results.HasError() { - // _, err := results.Aggregate() - // k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) - // return results, params.Status - //} - configHash := fnv.New32a() if res := reconcileConfig(params, configHash); res.HasError() { diff --git a/test/e2e/test/elasticsearch/checks_k8s.go b/test/e2e/test/elasticsearch/checks_k8s.go index b6bbdede91..b0cc7b114b 100644 --- a/test/e2e/test/elasticsearch/checks_k8s.go +++ b/test/e2e/test/elasticsearch/checks_k8s.go @@ -35,7 +35,7 @@ const ( // but it occasionally takes longer for various reasons (long Pod creation time, long volume binding, etc.). // We use a longer timeout here to not be impacted too much by those external factors, and only fail // if things seem to be stuck. - RollingUpgradeTimeout = 10 * time.Minute + RollingUpgradeTimeout = 30 * time.Minute ) func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { From 4e73a41c3ab5adfc4fde29c8bfefef676e889c06 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 11:43:27 -0500 Subject: [PATCH 018/160] Add Logstash to sample and stack tests --- config/crds/v1/all-crds.yaml | 8 +++++-- .../logstash.k8s.elastic.co_logstashes.yaml | 8 +++++-- .../eck-operator-crds/templates/all-crds.yaml | 8 +++++-- .../logstash/v1alpha1/groupversion_info.go | 6 ++--- pkg/apis/logstash/v1alpha1/webhook.go | 2 +- test/e2e/logstash/logstash_test.go | 7 ++++++ test/e2e/samples_test.go | 7 ++++++ test/e2e/stack_test.go | 24 +++++++++++++++---- test/e2e/test/helper/yaml.go | 16 ++++++++++++- 9 files changed, 71 insertions(+), 15 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 968393ef3d..4c8e3d228d 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9118,8 +9118,12 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Logstash - Metrics API + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' properties: service: description: Service defines the template for the associated Kubernetes diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index b652b0ed80..099a90ce2c 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -74,8 +74,12 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Logstash - Metrics API + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' properties: service: description: Service defines the template for the associated Kubernetes diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 24afce4ccd..b926b6c0de 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9172,8 +9172,12 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Logstash - Metrics API + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' properties: service: description: Service defines the template for the associated Kubernetes diff --git a/pkg/apis/logstash/v1alpha1/groupversion_info.go b/pkg/apis/logstash/v1alpha1/groupversion_info.go index 5589c3a240..72425bd52a 100644 --- a/pkg/apis/logstash/v1alpha1/groupversion_info.go +++ b/pkg/apis/logstash/v1alpha1/groupversion_info.go @@ -10,11 +10,11 @@ import ( ) var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "logstash.k8s.elastic.co", Version: "v1alpha1"} + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "logstash.k8s.elastic.co", Version: "v1alpha1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} // AddToScheme is required by pkg/client/... AddToScheme = SchemeBuilder.AddToScheme diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go index 76b564678d..ab9f69de37 100644 --- a/pkg/apis/logstash/v1alpha1/webhook.go +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -22,7 +22,7 @@ const ( ) var ( - groupKind = schema.GroupKind{Group: SchemeGroupVersion.Group, Kind: Kind} + groupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: Kind} validationLog = ulog.Log.WithName("logstash-v1alpha1-validation") ) diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go index d994ad81e2..96c8cd93ce 100644 --- a/test/e2e/logstash/logstash_test.go +++ b/test/e2e/logstash/logstash_test.go @@ -20,6 +20,13 @@ func TestSingleLogstash(t *testing.T) { test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) } +func TestMultipleLogstashes(t *testing.T) { + name := "test-multiple-logstashes" + logstashBuilder := logstash.NewBuilder(name). + WithNodeCount(3) + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + func TestLogstashServerVersionUpgradeToLatest8x(t *testing.T) { srcVersion, dstVersion := test.GetUpgradePathTo8x(test.Ctx().ElasticStackVersion) diff --git a/test/e2e/samples_test.go b/test/e2e/samples_test.go index 058208bf25..c0ee2a3bdb 100644 --- a/test/e2e/samples_test.go +++ b/test/e2e/samples_test.go @@ -23,6 +23,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/helper" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/kibana" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" ) func TestSamples(t *testing.T) { @@ -81,6 +82,12 @@ func createBuilders(t *testing.T, decoder *helper.YAMLDecoder, sampleFile, testN WithRestrictedSecurityContext(). WithLabel(run.TestNameLabel, fullTestName). WithPodLabel(run.TestNameLabel, fullTestName) + case logstash.Builder: + return b.WithNamespace(namespace). + WithSuffix(suffix). + WithRestrictedSecurityContext(). + WithLabel(run.TestNameLabel, fullTestName). + WithPodLabel(run.TestNameLabel, fullTestName) default: return b } diff --git a/test/e2e/stack_test.go b/test/e2e/stack_test.go index c2e739b0c4..69faa4948a 100644 --- a/test/e2e/stack_test.go +++ b/test/e2e/stack_test.go @@ -19,6 +19,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/filebeat" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" @@ -28,6 +29,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/beat" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/enterprisesearch" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/kibana" ) @@ -72,6 +74,9 @@ func TestVersionUpgradeOrdering(t *testing.T) { WithElasticsearchRef(esRef). WithRestrictedSecurityContext() entUpdated := ent.WithVersion(updatedVersion) + logstash := logstash.NewBuilder("ls"). + WithVersion(initialVersion) // pre 8.x doesn't require any config, but we change the version after calling + logstashUpdated := logstash.WithVersion(updatedVersion) fb := beat.NewBuilder("fb"). WithType(filebeat.Type). WithRoles(beat.AutodiscoverClusterRoleName). @@ -81,8 +86,8 @@ func TestVersionUpgradeOrdering(t *testing.T) { fb = beat.ApplyYamls(t, fb, beattests.E2EFilebeatConfig, beattests.E2EFilebeatPodTemplate) fbUpdated := fb.WithVersion(updatedVersion) - initialBuilders := []test.Builder{es, kb, apm, ent, fb} - updatedBuilders := []test.Builder{esUpdated, kbUpdated, apmUpdated, entUpdated, fbUpdated} + initialBuilders := []test.Builder{es, kb, apm, ent, fb, logstash} + updatedBuilders := []test.Builder{esUpdated, kbUpdated, apmUpdated, entUpdated, fbUpdated, logstashUpdated} versionUpgrade := func(k *test.K8sClient) test.StepList { steps := test.StepList{} @@ -101,6 +106,7 @@ func TestVersionUpgradeOrdering(t *testing.T) { ApmServer: ref(k8s.ExtractNamespacedName(&apm.ApmServer)), EnterpriseSearch: ref(k8s.ExtractNamespacedName(&ent.EnterpriseSearch)), Beat: ref(k8s.ExtractNamespacedName(&fb.Beat)), + Logstash: ref(k8s.ExtractNamespacedName(&logstash.Logstash)), } err := stackVersions.Retrieve(k.Client) // check the retrieved versions first (before returning on err) @@ -128,6 +134,7 @@ type StackResourceVersions struct { ApmServer refVersion EnterpriseSearch refVersion Beat refVersion + Logstash refVersion } func (s StackResourceVersions) IsValid() bool { @@ -140,7 +147,7 @@ func (s StackResourceVersions) IsValid() bool { } func (s StackResourceVersions) AllSetTo(version string) bool { - for _, ref := range []refVersion{s.Elasticsearch, s.Kibana, s.ApmServer, s.EnterpriseSearch, s.Beat} { + for _, ref := range []refVersion{s.Elasticsearch, s.Kibana, s.ApmServer, s.EnterpriseSearch, s.Beat, s.Logstash} { if ref.version != version { return false } @@ -149,7 +156,7 @@ func (s StackResourceVersions) AllSetTo(version string) bool { } func (s *StackResourceVersions) Retrieve(client k8s.Client) error { - calls := []func(c k8s.Client) error{s.retrieveBeat, s.retrieveApmServer, s.retrieveKibana, s.retrieveEnterpriseSearch, s.retrieveElasticsearch} + calls := []func(c k8s.Client) error{s.retrieveBeat, s.retrieveApmServer, s.retrieveKibana, s.retrieveEnterpriseSearch, s.retrieveElasticsearch, s.retrieveLogstash} // grab at least one error if multiple occur var callsErr error for _, f := range calls { @@ -223,3 +230,12 @@ func (s *StackResourceVersions) retrieveBeat(c k8s.Client) error { s.Beat.version = beat.Status.Version return nil } + +func (s *StackResourceVersions) retrieveLogstash(c k8s.Client) error { + var logstash logstashv1alpha1.Logstash + if err := c.Get(context.Background(), s.Logstash.ref, &logstash); err != nil { + return err + } + s.Logstash.version = logstash.Status.Version + return nil +} diff --git a/test/e2e/test/helper/yaml.go b/test/e2e/test/helper/yaml.go index 0a035aa340..a567e1c0a5 100644 --- a/test/e2e/test/helper/yaml.go +++ b/test/e2e/test/helper/yaml.go @@ -33,6 +33,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" beatcommon "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/common" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -42,6 +43,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/kibana" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" ) type BuilderTransform func(test.Builder) test.Builder @@ -59,7 +61,7 @@ func NewYAMLDecoder() *YAMLDecoder { scheme.AddKnownTypes(beatv1beta1.GroupVersion, &beatv1beta1.Beat{}, &beatv1beta1.BeatList{}) scheme.AddKnownTypes(entv1.GroupVersion, &entv1.EnterpriseSearch{}, &entv1.EnterpriseSearchList{}) scheme.AddKnownTypes(agentv1alpha1.GroupVersion, &agentv1alpha1.Agent{}, &agentv1alpha1.AgentList{}) - + scheme.AddKnownTypes(logstashv1alpha1.GroupVersion, &logstashv1alpha1.Logstash{}, &logstashv1alpha1.LogstashList{}) scheme.AddKnownTypes(rbacv1.SchemeGroupVersion, &rbacv1.ClusterRoleBinding{}, &rbacv1.ClusterRoleBindingList{}) scheme.AddKnownTypes(rbacv1.SchemeGroupVersion, &rbacv1.ClusterRole{}, &rbacv1.ClusterRoleList{}) scheme.AddKnownTypes(corev1.SchemeGroupVersion, &corev1.ServiceAccount{}, &corev1.ServiceAccountList{}) @@ -108,6 +110,10 @@ func (yd *YAMLDecoder) ToBuilders(reader *bufio.Reader, transform BuilderTransfo b := enterprisesearch.NewBuilderWithoutSuffix(decodedObj.Name) b.EnterpriseSearch = *decodedObj builder = transform(b) + case *logstashv1alpha1.Logstash: + b := logstash.NewBuilderWithoutSuffix(decodedObj.Name) + b.Logstash = *decodedObj + builder = transform(b) default: return builders, fmt.Errorf("unexpected object type: %t", decodedObj) } @@ -304,6 +310,14 @@ func transformToE2E(namespace, fullTestName, suffix string, transformers []Build b = b.WithPodTemplateServiceAccount(b.PodTemplate.Spec.ServiceAccountName + "-" + suffix) } + builder = b + case *logstashv1alpha1.Logstash: + b := logstash.NewBuilderWithoutSuffix(decodedObj.Name) + b = b.WithNamespace(namespace). + WithSuffix(suffix). + WithLabel(run.TestNameLabel, fullTestName). + WithPodLabel(run.TestNameLabel, fullTestName) + builder = b case *corev1.ServiceAccount: decodedObj.Namespace = namespace From 5713bb4c00273c22b08bfac6749f539396d12cad Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 12:45:37 -0500 Subject: [PATCH 019/160] Added basic logstash verification Add a test to make sure that Logstash is running, by testing the metrics API endpoint and checking that the value of status is "green" --- docs/reference/api-docs.asciidoc | 2 +- test/e2e/test/logstash/checks.go | 32 ++++++++++++- test/e2e/test/logstash/http_client.go | 67 +++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 test/e2e/test/logstash/http_client.go diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index c1a58e4930..781b519f72 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1876,7 +1876,7 @@ LogstashSpec defines the desired state of Logstash | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. -| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API +| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 6c8ed2d188..e98540c6fc 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -6,6 +6,7 @@ package logstash import ( "context" + "encoding/json" "fmt" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" @@ -13,6 +14,11 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) +type logstashStatus struct { + Version string `json:"version"` + Status string `json:"status"` +} + // CheckSecrets checks that expected secrets have been created. func CheckSecrets(b Builder, k *test.K8sClient) test.Step { return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { @@ -58,6 +64,28 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { println(test.Ctx().TestTimeout) - // TODO: Add stack checks - return test.StepList{} + return test.StepList{ + { + Name: "Logstash should respond to requests", + Test: test.Eventually(func() error { + client, err := NewLogstashClient(b.Logstash, k) + if err != nil { + return err + } + bytes, err := DoRequest(client, b.Logstash, "GET", "/") + if err != nil { + return err + } + var status logstashStatus + if err := json.Unmarshal(bytes, &status); err != nil { + return err + } + + if status.Status != "green" { + return fmt.Errorf("expected green but got %s", status.Status) + } + return nil + }), + }, + } } diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go new file mode 100644 index 0000000000..d36519624e --- /dev/null +++ b/test/e2e/test/logstash/http_client.go @@ -0,0 +1,67 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "crypto/x509" + "fmt" + "io" + "net/http" + "net/url" + + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + +type APIError struct { + StatusCode int + msg string +} + +func (e *APIError) Error() string { + return e.msg +} + +// TODO refactor identical to Kibana client +func NewLogstashClient(logstash v1alpha1.Logstash, k *test.K8sClient) (*http.Client, error) { + var caCerts []*x509.Certificate + // if ems.Spec.HTTP.TLS.Enabled() { + // crts, err := k.GetHTTPCerts(maps.EMSNamer, ems.Namespace, ems.Name) + // if err != nil { + // return nil, err + // } + // caCerts = crts + //} + return test.NewHTTPClient(caCerts), nil +} + +func DoRequest(client *http.Client, logstash v1alpha1.Logstash, method, path string) ([]byte, error) { + scheme := "http" + + url, err := url.Parse(fmt.Sprintf("%s://%s.%s.svc:9600%s", scheme, v1alpha1.HTTPServiceName(logstash.Name), logstash.Namespace, path)) + if err != nil { + return nil, fmt.Errorf("while parsing URL: %w", err) + } + + request, err := http.NewRequestWithContext(context.Background(), method, url.String(), nil) + if err != nil { + return nil, fmt.Errorf("while constructing request: %w", err) + } + + resp, err := client.Do(request) + if err != nil { + return nil, fmt.Errorf("while making request: %w", err) + } + defer resp.Body.Close() + if resp.StatusCode < 200 || resp.StatusCode > 299 { + return nil, &APIError{ + StatusCode: resp.StatusCode, + msg: fmt.Sprintf("fail to request %s, status is %d)", path, resp.StatusCode), + } + } + return io.ReadAll(resp.Body) +} From e66b380e7e9cc2d9eb0e896c8e3798ce91c800fb Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 16:28:55 -0500 Subject: [PATCH 020/160] Fix readiness probe This commit fixes the readiness probe, by setting the default visibility of the logstash API to 0.0.0.0, allowing access to the metrics API to the probe --- pkg/controller/logstash/config.go | 4 +- pkg/controller/logstash/pod.go | 69 +++++++++++-------------------- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index 4a3fc0ed63..2536c6c70d 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -115,10 +115,10 @@ func getUserConfig(params Params) (*settings.CanonicalConfig, error) { return common.ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.ConfigRef, LogstashConfigFileName) } -// TODO: remove testing value func defaultConfig() *settings.CanonicalConfig { settingsMap := map[string]interface{}{ - "node.name": "test", + // Set 'api.http.host' by defaut to `0.0.0.0` for readiness probe to work. + "api.http.host": "0.0.0.0", } return settings.MustCanonicalConfig(settingsMap) diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 281757d135..077547de38 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -12,7 +12,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - // "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/apimachinery/pkg/util/intstr" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" @@ -82,8 +82,7 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - // WithReadinessProbe(readinessProbe(false)). - // WithLivenessProbe(livenessProbe(false)). + WithReadinessProbe(readinessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled @@ -103,46 +102,24 @@ func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.Conta } } -//// readinessProbe is the readiness probe for the Logstash container -// func readinessProbe(useTLS bool) corev1.Probe { -// scheme := corev1.URISchemeHTTP -// if useTLS { -// scheme = corev1.URISchemeHTTPS -// } -// return corev1.Probe{ -// FailureThreshold: 3, -// InitialDelaySeconds: 30, -// PeriodSeconds: 10, -// SuccessThreshold: 1, -// TimeoutSeconds: 5, -// ProbeHandler: corev1.ProbeHandler{ -// HTTPGet: &corev1.HTTPGetAction{ -// Port: intstr.FromInt(network.HTTPPort), -// Path: "/", -// Scheme: scheme, -// }, -// }, -// } -//} -// -//// livenessProbe is the liveness probe for the Logstash container -// func livenessProbe(useTLS bool) corev1.Probe { -// scheme := corev1.URISchemeHTTP -// if useTLS { -// scheme = corev1.URISchemeHTTPS -// } -// return corev1.Probe{ -// FailureThreshold: 3, -// InitialDelaySeconds: 60, -// PeriodSeconds: 10, -// SuccessThreshold: 1, -// TimeoutSeconds: 5, -// ProbeHandler: corev1.ProbeHandler{ -// HTTPGet: &corev1.HTTPGetAction{ -// Port: intstr.FromInt(network.HTTPPort), -// Path: "/", -// Scheme: scheme, -// }, -// }, -// } -//} +// readinessProbe is the readiness probe for the Logstash container +func readinessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 30, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} From 9fb1e20cda7c3dc556dd1060466ecddce0621c68 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 17:14:32 -0500 Subject: [PATCH 021/160] Tidy up --- pkg/controller/logstash/driver.go | 5 ++--- test/e2e/stack_test.go | 2 +- test/e2e/test/logstash/http_client.go | 2 +- test/e2e/test/logstash/steps.go | 5 ----- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 4be3660336..7c432ffb0f 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -9,11 +9,10 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" "hash/fnv" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" "k8s.io/client-go/tools/record" diff --git a/test/e2e/stack_test.go b/test/e2e/stack_test.go index 69faa4948a..620d1655e4 100644 --- a/test/e2e/stack_test.go +++ b/test/e2e/stack_test.go @@ -106,7 +106,7 @@ func TestVersionUpgradeOrdering(t *testing.T) { ApmServer: ref(k8s.ExtractNamespacedName(&apm.ApmServer)), EnterpriseSearch: ref(k8s.ExtractNamespacedName(&ent.EnterpriseSearch)), Beat: ref(k8s.ExtractNamespacedName(&fb.Beat)), - Logstash: ref(k8s.ExtractNamespacedName(&logstash.Logstash)), + Logstash: ref(k8s.ExtractNamespacedName(&logstash.Logstash)), } err := stackVersions.Retrieve(k.Client) // check the retrieved versions first (before returning on err) diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go index d36519624e..2aea4ce8bf 100644 --- a/test/e2e/test/logstash/http_client.go +++ b/test/e2e/test/logstash/http_client.go @@ -13,7 +13,6 @@ import ( "net/url" "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) @@ -29,6 +28,7 @@ func (e *APIError) Error() string { // TODO refactor identical to Kibana client func NewLogstashClient(logstash v1alpha1.Logstash, k *test.K8sClient) (*http.Client, error) { var caCerts []*x509.Certificate + // TODO: Integrate with TLS on metrics API // if ems.Spec.HTTP.TLS.Enabled() { // crts, err := k.GetHTTPCerts(maps.EMSNamer, ems.Namespace, ems.Name) // if err != nil { diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index 44f2a5f4e0..a9a324a621 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -11,12 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - // "k8s.io/apimachinery/pkg/types" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - // mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" From 34c2aca58f4dda92806b5c28c8b206be83224879 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 16 Feb 2023 18:28:59 +0000 Subject: [PATCH 022/160] add stack monitoring --- cmd/manager/main.go | 2 + config/crds/v1/all-crds.yaml | 109 ++++++++++++++ .../logstash.k8s.elastic.co_logstashes.yaml | 109 ++++++++++++++ .../eck-operator-crds/templates/all-crds.yaml | 109 ++++++++++++++ docs/reference/api-docs.asciidoc | 2 + pkg/apis/common/v1/association.go | 2 + pkg/apis/logstash/v1alpha1/logstash_types.go | 133 +++++++++++++++++- .../v1alpha1/zz_generated.deepcopy.go | 38 ++++- .../association/controller/logstash_es.go | 70 +++++++++ .../controller/logstash_monitoring.go | 57 ++++++++ pkg/controller/logstash/driver.go | 7 + pkg/controller/logstash/pod.go | 6 + .../logstash/stackmon/beat_config.go | 60 ++++++++ pkg/controller/logstash/stackmon/filebeat.yml | 18 +++ .../logstash/stackmon/metricbeat.tpl.yml | 13 ++ pkg/controller/logstash/stackmon/sidecar.go | 111 +++++++++++++++ test/e2e/logstash/stack_monitoring_test.go | 43 ++++++ test/e2e/test/logstash/builder.go | 7 + test/e2e/test/logstash/checks.go | 2 + 19 files changed, 895 insertions(+), 3 deletions(-) create mode 100644 pkg/controller/association/controller/logstash_es.go create mode 100644 pkg/controller/association/controller/logstash_monitoring.go create mode 100644 pkg/controller/logstash/stackmon/beat_config.go create mode 100644 pkg/controller/logstash/stackmon/filebeat.yml create mode 100644 pkg/controller/logstash/stackmon/metricbeat.tpl.yml create mode 100644 pkg/controller/logstash/stackmon/sidecar.go create mode 100644 test/e2e/logstash/stack_monitoring_test.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index fa6cc484a8..1273054e84 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -879,6 +879,7 @@ func registerControllers(mgr manager.Manager, params operator.Parameters, access {name: "ES-MONITORING", registerFunc: associationctl.AddEsMonitoring}, {name: "KB-MONITORING", registerFunc: associationctl.AddKbMonitoring}, {name: "BEAT-MONITORING", registerFunc: associationctl.AddBeatMonitoring}, + {name: "LOGSTASH-MONITORING", registerFunc: associationctl.AddLogstashMonitoring}, } for _, c := range assocControllers { @@ -917,6 +918,7 @@ func garbageCollectUsers(ctx context.Context, cfg *rest.Config, managedNamespace For(&beatv1beta1.BeatList{}, associationctl.BeatAssociationLabelNamespace, associationctl.BeatAssociationLabelName). For(&agentv1alpha1.AgentList{}, associationctl.AgentAssociationLabelNamespace, associationctl.AgentAssociationLabelName). For(&emsv1alpha1.ElasticMapsServerList{}, associationctl.MapsESAssociationLabelNamespace, associationctl.MapsESAssociationLabelName). + For(&logstashv1alpha1.LogstashList{}, associationctl.LogstashAssociationLabelNamespace, associationctl.LogstashAssociationLabelName). DoGarbageCollection(ctx) if err != nil { return fmt.Errorf("user garbage collector failed: %w", err) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 4c8e3d228d..c9302ed7d9 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9549,6 +9549,108 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + monitoring: + description: Monitoring enables you to collect and ship log and monitoring + data of this Logstash. Metricbeat and Filebeat are deployed in the + same Pod as sidecars and each one sends data to one or two different + Elasticsearch monitoring clusters running in the same Kubernetes + cluster. + properties: + logs: + description: Logs holds references to Elasticsearch clusters which + receive log data from an associated resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + metrics: + description: Metrics holds references to Elasticsearch clusters + which receive monitoring data from this resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. @@ -9616,6 +9718,13 @@ spec: expectedNodes: format: int32 type: integer + monitoringAssociationStatus: + additionalProperties: + description: AssociationStatus is the status of an association resource. + type: string + description: MonitoringAssociationStatus is the status of any auto-linking + to monitoring Elasticsearch clusters. + type: object observedGeneration: description: ObservedGeneration is the most recent generation observed for this Logstash instance. It corresponds to the metadata generation, diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 099a90ce2c..467a2e55b1 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -505,6 +505,108 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + monitoring: + description: Monitoring enables you to collect and ship log and monitoring + data of this Logstash. Metricbeat and Filebeat are deployed in the + same Pod as sidecars and each one sends data to one or two different + Elasticsearch monitoring clusters running in the same Kubernetes + cluster. + properties: + logs: + description: Logs holds references to Elasticsearch clusters which + receive log data from an associated resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + metrics: + description: Metrics holds references to Elasticsearch clusters + which receive monitoring data from this resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. @@ -7979,6 +8081,13 @@ spec: expectedNodes: format: int32 type: integer + monitoringAssociationStatus: + additionalProperties: + description: AssociationStatus is the status of an association resource. + type: string + description: MonitoringAssociationStatus is the status of any auto-linking + to monitoring Elasticsearch clusters. + type: object observedGeneration: description: ObservedGeneration is the most recent generation observed for this Logstash instance. It corresponds to the metadata generation, diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index b926b6c0de..ce343a1bd7 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9603,6 +9603,108 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + monitoring: + description: Monitoring enables you to collect and ship log and monitoring + data of this Logstash. Metricbeat and Filebeat are deployed in the + same Pod as sidecars and each one sends data to one or two different + Elasticsearch monitoring clusters running in the same Kubernetes + cluster. + properties: + logs: + description: Logs holds references to Elasticsearch clusters which + receive log data from an associated resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + metrics: + description: Metrics holds references to Elasticsearch clusters + which receive monitoring data from this resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. @@ -9670,6 +9772,13 @@ spec: expectedNodes: format: int32 type: integer + monitoringAssociationStatus: + additionalProperties: + description: AssociationStatus is the status of an association resource. + type: string + description: MonitoringAssociationStatus is the status of any auto-linking + to monitoring Elasticsearch clusters. + type: object observedGeneration: description: ObservedGeneration is the most recent generation observed for this Logstash instance. It corresponds to the metadata generation, diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 781b519f72..d56fa7a5f0 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -591,6 +591,7 @@ Monitoring holds references to both the metrics, and logs Elasticsearch clusters - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-elasticsearchspec[$$ElasticsearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] **** [cols="25a,75a", options="header"] @@ -1877,6 +1878,7 @@ LogstashSpec defines the desired state of Logstash | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. | *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs +| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. diff --git a/pkg/apis/common/v1/association.go b/pkg/apis/common/v1/association.go index 721055c273..8bcfaa2f23 100644 --- a/pkg/apis/common/v1/association.go +++ b/pkg/apis/common/v1/association.go @@ -110,6 +110,8 @@ const ( BeatAssociationType = "beat" BeatMonitoringAssociationType = "beat-monitoring" + LogstashMonitoringAssociationType = "ls-monitoring" + AssociationUnknown AssociationStatus = "" AssociationPending AssociationStatus = "Pending" AssociationEstablished AssociationStatus = "Established" diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 0d10621327..123369be30 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -5,6 +5,7 @@ package v1alpha1 import ( + "fmt" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -46,6 +47,12 @@ type LogstashSpec struct { // +kubebuilder:validation:Optional HTTP commonv1.HTTPConfig `json:"http,omitempty"` + // Monitoring enables you to collect and ship log and monitoring data of this Logstash. + // Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different + // Elasticsearch monitoring clusters running in the same Kubernetes cluster. + // +kubebuilder:validation:Optional + Monitoring commonv1.Monitoring `json:"monitoring,omitempty"` + // PodTemplate provides customisation options for the Logstash pods. PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` @@ -80,6 +87,9 @@ type LogstashStatus struct { // If the generation observed in status diverges from the generation in metadata, the Logstash // controller has not yet processed the changes contained in the Logstash specification. ObservedGeneration int64 `json:"observedGeneration,omitempty"` + + // MonitoringAssociationStatus is the status of any auto-linking to monitoring Elasticsearch clusters. + MonitoringAssociationStatus commonv1.AssociationStatusMap `json:"monitoringAssociationStatus,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -98,8 +108,9 @@ type Logstash struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec LogstashSpec `json:"spec,omitempty"` - Status LogstashStatus `json:"status,omitempty"` + Spec LogstashSpec `json:"spec,omitempty"` + Status LogstashStatus `json:"status,omitempty"` + MonitoringAssocConfs map[commonv1.ObjectSelector]commonv1.AssociationConf `json:"-"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -129,6 +140,124 @@ func (l *Logstash) GetObservedGeneration() int64 { return l.Status.ObservedGeneration } +func (l *Logstash) GetAssociations() []commonv1.Association { + associations := make([]commonv1.Association, 0) + + for _, ref := range l.Spec.Monitoring.Metrics.ElasticsearchRefs { + if ref.IsDefined() { + associations = append(associations, &LogstashMonitoringAssociation{ + Logstash: l, + ref: ref.WithDefaultNamespace(l.Namespace), + }) + } + } + for _, ref := range l.Spec.Monitoring.Logs.ElasticsearchRefs { + if ref.IsDefined() { + associations = append(associations, &LogstashMonitoringAssociation{ + Logstash: l, + ref: ref.WithDefaultNamespace(l.Namespace), + }) + } + } + + return associations +} + +func (l *Logstash) AssociationStatusMap(typ commonv1.AssociationType) commonv1.AssociationStatusMap { + switch typ { + case commonv1.LogstashMonitoringAssociationType: + for _, esRef := range l.Spec.Monitoring.Metrics.ElasticsearchRefs { + if esRef.IsDefined() { + return l.Status.MonitoringAssociationStatus + } + } + for _, esRef := range l.Spec.Monitoring.Logs.ElasticsearchRefs { + if esRef.IsDefined() { + return l.Status.MonitoringAssociationStatus + } + } + } + + return commonv1.AssociationStatusMap{} +} + +func (l *Logstash) SetAssociationStatusMap(typ commonv1.AssociationType, status commonv1.AssociationStatusMap) error { + switch typ { + case commonv1.LogstashMonitoringAssociationType: + l.Status.MonitoringAssociationStatus = status + return nil + default: + return fmt.Errorf("association type %s not known", typ) + } +} + +type LogstashMonitoringAssociation struct { + // The associated Logstash + *Logstash + // ref is the object selector of the monitoring Elasticsearch referenced in the Association + ref commonv1.ObjectSelector +} + +var _ commonv1.Association = &LogstashMonitoringAssociation{} + +func (lsmon *LogstashMonitoringAssociation) ElasticServiceAccount() (commonv1.ServiceAccountName, error) { + return "", nil +} + +func (lsmon *LogstashMonitoringAssociation) Associated() commonv1.Associated { + if lsmon == nil { + return nil + } + if lsmon.Logstash == nil { + lsmon.Logstash = &Logstash{} + } + return lsmon.Logstash +} + +func (lsmon *LogstashMonitoringAssociation) AssociationConfAnnotationName() string { + return commonv1.ElasticsearchConfigAnnotationName(lsmon.ref) +} + +func (lsmon *LogstashMonitoringAssociation) AssociationType() commonv1.AssociationType { + return commonv1.LogstashMonitoringAssociationType +} + +func (lsmon *LogstashMonitoringAssociation) AssociationRef() commonv1.ObjectSelector { + return lsmon.ref +} + +func (lsmon *LogstashMonitoringAssociation) AssociationConf() (*commonv1.AssociationConf, error) { + return commonv1.GetAndSetAssociationConfByRef(lsmon, lsmon.ref, lsmon.MonitoringAssocConfs) +} + +func (lsmon *LogstashMonitoringAssociation) SetAssociationConf(assocConf *commonv1.AssociationConf) { + if lsmon.MonitoringAssocConfs == nil { + lsmon.MonitoringAssocConfs = make(map[commonv1.ObjectSelector]commonv1.AssociationConf) + } + if assocConf != nil { + lsmon.MonitoringAssocConfs[lsmon.ref] = *assocConf + } +} + +func (lsmon *LogstashMonitoringAssociation) AssociationID() string { + return lsmon.ref.ToID() +} + +func (l *Logstash) GetMonitoringMetricsRefs() []commonv1.ObjectSelector { + return l.Spec.Monitoring.Metrics.ElasticsearchRefs +} + +func (l *Logstash) GetMonitoringLogsRefs() []commonv1.ObjectSelector { + return l.Spec.Monitoring.Logs.ElasticsearchRefs +} + +func (l *Logstash) MonitoringAssociation(esRef commonv1.ObjectSelector) commonv1.Association { + return &LogstashMonitoringAssociation{ + Logstash: l, + ref: esRef.WithDefaultNamespace(l.Namespace), + } +} + func init() { SchemeBuilder.Register(&Logstash{}, &LogstashList{}) } diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index 42ca5a613e..6229693d64 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -20,7 +20,14 @@ func (in *Logstash) DeepCopyInto(out *Logstash) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) + if in.MonitoringAssocConfs != nil { + in, out := &in.MonitoringAssocConfs, &out.MonitoringAssocConfs + *out = make(map[v1.ObjectSelector]v1.AssociationConf, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Logstash. @@ -73,6 +80,27 @@ func (in *LogstashList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashMonitoringAssociation) DeepCopyInto(out *LogstashMonitoringAssociation) { + *out = *in + if in.Logstash != nil { + in, out := &in.Logstash, &out.Logstash + *out = new(Logstash) + (*in).DeepCopyInto(*out) + } + out.ref = in.ref +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashMonitoringAssociation. +func (in *LogstashMonitoringAssociation) DeepCopy() *LogstashMonitoringAssociation { + if in == nil { + return nil + } + out := new(LogstashMonitoringAssociation) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { *out = *in @@ -86,6 +114,7 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { **out = **in } in.HTTP.DeepCopyInto(&out.HTTP) + in.Monitoring.DeepCopyInto(&out.Monitoring) in.PodTemplate.DeepCopyInto(&out.PodTemplate) if in.RevisionHistoryLimit != nil { in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit @@ -114,6 +143,13 @@ func (in *LogstashSpec) DeepCopy() *LogstashSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LogstashStatus) DeepCopyInto(out *LogstashStatus) { *out = *in + if in.MonitoringAssociationStatus != nil { + in, out := &in.MonitoringAssociationStatus, &out.MonitoringAssociationStatus + *out = make(v1.AssociationStatusMap, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashStatus. diff --git a/pkg/controller/association/controller/logstash_es.go b/pkg/controller/association/controller/logstash_es.go new file mode 100644 index 0000000000..75e1629ad9 --- /dev/null +++ b/pkg/controller/association/controller/logstash_es.go @@ -0,0 +1,70 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package controller + +import ( + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/manager" + "strings" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/association" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" + eslabel "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/rbac" +) + +const ( + // LogstashAssociationLabelName marks resources created for an association originating from Logstash with the + // Logstash name. + LogstashAssociationLabelName = "logstashassociation.k8s.elastic.co/name" + // LogstashAssociationLabelNamespace marks resources created for an association originating from Logstash with the + // Logstash namespace. + LogstashAssociationLabelNamespace = "logstashassociation.k8s.elastic.co/namespace" + // LogstashAssociationLabelType marks resources created for an association originating from Logstash + // with the target resource type (e.g. "elasticsearch"). + LogstashAssociationLabelType = "logstashassociation.k8s.elastic.co/type" + // LogstashSystemUserBuiltinRole is the name of the built-in role for the Logstash system user. + LogstashSystemUserBuiltinRole = "logstash_system" + // LogstashAdminUserBuiltinRole is the name of the built-in role for the Logstash admin user. + LogstashAdminUserBuiltinRole = "logstash_admin" +) + +func AddLogstashES(mgr manager.Manager, accessReviewer rbac.AccessReviewer, params operator.Parameters) error { + return association.AddAssociationController(mgr, accessReviewer, params, association.AssociationInfo{ + AssociationType: commonv1.ElasticsearchAssociationType, + AssociatedObjTemplate: func() commonv1.Associated { return &logstashv1alpha1.Logstash{} }, + ReferencedObjTemplate: func() client.Object { return &esv1.Elasticsearch{} }, + ReferencedResourceVersion: referencedElasticsearchStatusVersion, + ExternalServiceURL: getElasticsearchExternalURL, + ReferencedResourceNamer: esv1.ESNamer, + AssociationName: "logstash-es", + AssociatedShortName: "logstash", + Labels: func(associated types.NamespacedName) map[string]string { + return map[string]string{ + LogstashAssociationLabelName: associated.Name, + LogstashAssociationLabelNamespace: associated.Namespace, + LogstashAssociationLabelType: commonv1.ElasticsearchAssociationType, + } + }, + AssociationConfAnnotationNameBase: commonv1.ElasticsearchConfigAnnotationNameBase, + AssociationResourceNameLabelName: eslabel.ClusterNameLabelName, + AssociationResourceNamespaceLabelName: eslabel.ClusterNamespaceLabelName, + + ElasticsearchUserCreation: &association.ElasticsearchUserCreation{ + ElasticsearchRef: func(c k8s.Client, association commonv1.Association) (bool, commonv1.ObjectSelector, error) { + return true, association.AssociationRef(), nil + }, + UserSecretSuffix: "logstash-user", + ESUserRole: func(associated commonv1.Associated) (string, error) { + return strings.Join([]string{LogstashAdminUserBuiltinRole, LogstashSystemUserBuiltinRole}, ","), nil + }, + }, + }) +} diff --git a/pkg/controller/association/controller/logstash_monitoring.go b/pkg/controller/association/controller/logstash_monitoring.go new file mode 100644 index 0000000000..c97398d3c1 --- /dev/null +++ b/pkg/controller/association/controller/logstash_monitoring.go @@ -0,0 +1,57 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package controller + +import ( + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/manager" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/association" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" + eslabel "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/user" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/rbac" +) + +// AddLogstashMonitoring reconciles an association between Logstash and Elasticsearch clusters for Stack Monitoring. +// Beats are configured to collect monitoring metrics and logs data of the associated Logstash and send +// them to the Elasticsearch referenced in the association. +func AddLogstashMonitoring(mgr manager.Manager, accessReviewer rbac.AccessReviewer, params operator.Parameters) error { + return association.AddAssociationController(mgr, accessReviewer, params, association.AssociationInfo{ + AssociatedObjTemplate: func() commonv1.Associated { return &logstashv1alpha1.Logstash{} }, + ReferencedObjTemplate: func() client.Object { return &esv1.Elasticsearch{} }, + ReferencedResourceVersion: referencedElasticsearchStatusVersion, + ExternalServiceURL: getElasticsearchExternalURL, + AssociationType: commonv1.LogstashMonitoringAssociationType, + ReferencedResourceNamer: esv1.ESNamer, + AssociationName: "ls-monitoring", + AssociatedShortName: "ls-mon", + Labels: func(associated types.NamespacedName) map[string]string { + return map[string]string{ + LogstashAssociationLabelName: associated.Name, + LogstashAssociationLabelNamespace: associated.Namespace, + LogstashAssociationLabelType: commonv1.LogstashMonitoringAssociationType, + } + }, + AssociationConfAnnotationNameBase: commonv1.ElasticsearchConfigAnnotationNameBase, + AssociationResourceNameLabelName: eslabel.ClusterNameLabelName, + AssociationResourceNamespaceLabelName: eslabel.ClusterNamespaceLabelName, + + ElasticsearchUserCreation: &association.ElasticsearchUserCreation{ + ElasticsearchRef: func(c k8s.Client, association commonv1.Association) (bool, commonv1.ObjectSelector, error) { + return true, association.AssociationRef(), nil + }, + UserSecretSuffix: "beat-ls-mon-user", + ESUserRole: func(associated commonv1.Associated) (string, error) { + return user.StackMonitoringUserRole, nil + }, + }, + }) +} diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 7c432ffb0f..08a59d6b34 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -23,6 +23,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/stackmon" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" ) @@ -83,6 +84,12 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log configHash := fnv.New32a() + // reconcile beats config secrets if Stack Monitoring is defined + err = stackmon.ReconcileConfigSecrets(params.Context, params.Client, params.Logstash) + if err != nil { + return results.WithError(err), params.Status + } + if res := reconcileConfig(params, configHash); res.HasError() { return results.WithResults(res), params.Status } diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 077547de38..720cfb0ea1 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -20,6 +20,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/stackmon" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/maps" ) @@ -85,6 +86,11 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithReadinessProbe(readinessProbe(false)). WithVolumeLikes(vols...) + builder, err := stackmon.WithMonitoring(params.Context, params.Client, builder, params.Logstash) + if err != nil { + return corev1.PodTemplateSpec{} + } + // TODO integrate with api.ssl.enabled // if params.Logstash.Spec.HTTP.TLS.Enabled() { // httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) diff --git a/pkg/controller/logstash/stackmon/beat_config.go b/pkg/controller/logstash/stackmon/beat_config.go new file mode 100644 index 0000000000..d26950e8f8 --- /dev/null +++ b/pkg/controller/logstash/stackmon/beat_config.go @@ -0,0 +1,60 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package stackmon + +import ( + "context" + _ "embed" // for the beats config files + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/monitoring" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + +var ( + // metricbeatConfigTemplate is a configuration template for Metricbeat to collect monitoring data about Kibana + //go:embed metricbeat.tpl.yml + metricbeatConfigTemplate string + + // filebeatConfig is a static configuration for Filebeat to collect Kibana logs + //go:embed filebeat.yml + filebeatConfig string +) + +// ReconcileConfigSecrets reconciles the secrets holding beats configuration +func ReconcileConfigSecrets(ctx context.Context, client k8s.Client, logstash logstashv1alpha1.Logstash) error { + isMonitoringReconcilable, err := monitoring.IsReconcilable(&logstash) + if err != nil { + return err + } + if !isMonitoringReconcilable { + return nil + } + + if monitoring.IsMetricsDefined(&logstash) { + b, err := Metricbeat(ctx, client, logstash) + if err != nil { + return err + } + + if _, err := reconciler.ReconcileSecret(ctx, client, b.ConfigSecret, &logstash); err != nil { + return err + } + } + + if monitoring.IsLogsDefined(&logstash) { + b, err := Filebeat(ctx, client, logstash) + if err != nil { + return err + } + + if _, err := reconciler.ReconcileSecret(ctx, client, b.ConfigSecret, &logstash); err != nil { + return err + } + } + + return nil +} diff --git a/pkg/controller/logstash/stackmon/filebeat.yml b/pkg/controller/logstash/stackmon/filebeat.yml new file mode 100644 index 0000000000..eef95065a3 --- /dev/null +++ b/pkg/controller/logstash/stackmon/filebeat.yml @@ -0,0 +1,18 @@ +filebeat.modules: + - module: logstash + log: + enabled: true + var.paths: + - "/usr/share/logstash/logs/logstash-plain.log" + - "/usr/share/logstash/logs/logstash-json.log" + slowlog: + enabled: true + var.paths: + - "/usr/share/logstash/logs/logstash-slowlog-plain.log" + - "/usr/share/logstash/logs/logstash-slowlog-json.log" + +processors: + - add_cloud_metadata: {} + - add_host_metadata: {} + +# Elasticsearch output configuration is generated \ No newline at end of file diff --git a/pkg/controller/logstash/stackmon/metricbeat.tpl.yml b/pkg/controller/logstash/stackmon/metricbeat.tpl.yml new file mode 100644 index 0000000000..cbc84c40a9 --- /dev/null +++ b/pkg/controller/logstash/stackmon/metricbeat.tpl.yml @@ -0,0 +1,13 @@ +metricbeat.modules: + - module: logstash + metricsets: + - node + - node_stats + period: 10s + hosts: ["{{ .URL }}"] + xpack.enabled: true +processors: + - add_cloud_metadata: {} + - add_host_metadata: {} + +# Elasticsearch output configuration is generated diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go new file mode 100644 index 0000000000..b39e7a5f33 --- /dev/null +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -0,0 +1,111 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package stackmon + +import ( + "context" + "fmt" + "hash/fnv" + + corev1 "k8s.io/api/core/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/monitoring" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/volume" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/user" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + +const ( + // cfgHashAnnotation is used to store a hash of the Metricbeat and Filebeat configurations. + cfgHashAnnotation = "logstash.k8s.elastic.co/monitoring-config-hash" + + logstashLogsVolumeName = "logstash-logs" + logstashLogsMountPath = "/usr/share/logstash/logs" +) + +func Metricbeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha1.Logstash) (stackmon.BeatSidecar, error) { + username := user.MonitoringUserName + password, err := user.GetMonitoringUserPassword(client, k8s.ExtractNamespacedName(&logstash)) + if err != nil { + return stackmon.BeatSidecar{}, err + } + metricbeat, err := stackmon.NewMetricBeatSidecar( + ctx, + client, + commonv1.LogstashMonitoringAssociationType, + &logstash, + logstash.Spec.Version, + metricbeatConfigTemplate, + logstashv1alpha1.Namer, + fmt.Sprintf("%s://localhost:%d", "http" /*logstash.Spec.HTTP.Protocol()*/, network.HTTPPort), + username, + password, + false, /* logstash.Spec.HTTP.TLS.Enabled() */ + ) + if err != nil { + return stackmon.BeatSidecar{}, err + } + return metricbeat, nil +} + +func Filebeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha1.Logstash) (stackmon.BeatSidecar, error) { + return stackmon.NewFileBeatSidecar(ctx, client, &logstash, logstash.Spec.Version, filebeatConfig, nil) +} + +// WithMonitoring updates the Logstash Pod template builder to deploy Metricbeat and Filebeat in sidecar containers +// in the Logstash pod and injects the volumes for the beat configurations and the ES CA certificates. +func WithMonitoring(ctx context.Context, client k8s.Client, builder *defaults.PodTemplateBuilder, logstash logstashv1alpha1.Logstash) (*defaults.PodTemplateBuilder, error) { + isMonitoringReconcilable, err := monitoring.IsReconcilable(&logstash) + if err != nil { + return nil, err + } + if !isMonitoringReconcilable { + return builder, nil + } + + configHash := fnv.New32a() + volumes := make([]corev1.Volume, 0) + + if monitoring.IsMetricsDefined(&logstash) { + b, err := Metricbeat(ctx, client, logstash) + if err != nil { + return nil, err + } + + volumes = append(volumes, b.Volumes...) + builder.WithContainers(b.Container) + configHash.Write(b.ConfigHash.Sum(nil)) + } + + if monitoring.IsLogsDefined(&logstash) { + b, err := Filebeat(ctx, client, logstash) + if err != nil { + return nil, err + } + + // create a logs volume shared between Logstash and Filebeat + logsVolume := volume.NewEmptyDirVolume(logstashLogsVolumeName, logstashLogsMountPath) + volumes = append(volumes, logsVolume.Volume()) + filebeat := b.Container + filebeat.VolumeMounts = append(filebeat.VolumeMounts, logsVolume.VolumeMount()) + builder.WithVolumeMounts(logsVolume.VolumeMount()) + + volumes = append(volumes, b.Volumes...) + builder.WithContainers(filebeat) + configHash.Write(b.ConfigHash.Sum(nil)) + } + + // add the config hash annotation to ensure pod rotation when an ES password or a CA are rotated + builder.WithAnnotations(map[string]string{cfgHashAnnotation: fmt.Sprint(configHash.Sum32())}) + // inject all volumes + builder.WithVolumes(volumes...) + + return builder, nil +} diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go new file mode 100644 index 0000000000..64d417e5da --- /dev/null +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -0,0 +1,43 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +//go:build logstash || e2e + +package logstash + +import ( + "testing" + + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" +) + +// TestESStackMonitoring tests that when an Elasticsearch cluster is configured with monitoring, its log and metrics are +// correctly delivered to the referenced monitoring Elasticsearch clusters. +func TestLogstashStackMonitoring(t *testing.T) { + // only execute this test on supported version + err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion) + if err != nil { + t.SkipNow() + } + + // create 1 monitored and 2 monitoring clusters to collect separately metrics and logs + metrics := elasticsearch.NewBuilder("test-ls-mon-metrics"). + WithESMasterDataNodes(2, elasticsearch.DefaultResources) + logs := elasticsearch.NewBuilder("test-ls-mon-logs"). + WithESMasterDataNodes(2, elasticsearch.DefaultResources) + monitored := logstash.NewBuilder("test-ls-mon-a"). + WithNodeCount(1). + WithMonitoring(metrics.Ref(), logs.Ref()) + + // checks that the sidecar beats have sent data in the monitoring clusters + steps := func(k *test.K8sClient) test.StepList { + return checks.MonitoredSteps(&monitored, k) + } + + test.Sequence(nil, steps, metrics, logs, monitored).RunSequential(t) +} diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 8ae6cd1678..d2bb870f73 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -5,6 +5,7 @@ package logstash import ( + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" @@ -110,6 +111,12 @@ func (b Builder) WithMutatedFrom(mutatedFrom *Builder) Builder { return b } +func (b Builder) WithMonitoring(metricsESRef commonv1.ObjectSelector, logsESRef commonv1.ObjectSelector) Builder { + b.Logstash.Spec.Monitoring.Metrics.ElasticsearchRefs = []commonv1.ObjectSelector{metricsESRef} + b.Logstash.Spec.Monitoring.Logs.ElasticsearchRefs = []commonv1.ObjectSelector{logsESRef} + return b +} + func (b Builder) NSN() types.NamespacedName { return k8s.ExtractNamespacedName(&b.Logstash) } diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index e98540c6fc..86a7f342f4 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -8,6 +8,7 @@ import ( "context" "encoding/json" "fmt" + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" @@ -48,6 +49,7 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { } logstash.Status.ObservedGeneration = 0 + logstash.Status.MonitoringAssociationStatus = commonv1.AssociationStatusMap{} expected := logstashv1alpha1.LogstashStatus{ ExpectedNodes: b.Logstash.Spec.Count, From 131f17c93222df6071daba2f88dddb193e54bc74 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Feb 2023 11:38:49 +0000 Subject: [PATCH 023/160] update test --- test/e2e/test/logstash/checks.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 86a7f342f4..e4f5fcd632 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -8,8 +8,6 @@ import ( "context" "encoding/json" "fmt" - commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -49,14 +47,16 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { } logstash.Status.ObservedGeneration = 0 - logstash.Status.MonitoringAssociationStatus = commonv1.AssociationStatusMap{} expected := logstashv1alpha1.LogstashStatus{ ExpectedNodes: b.Logstash.Spec.Count, AvailableNodes: b.Logstash.Spec.Count, Version: b.Logstash.Spec.Version, } - if logstash.Status != expected { + + if (logstash.Status.ExpectedNodes != expected.ExpectedNodes) || + (logstash.Status.AvailableNodes != expected.AvailableNodes) || + (logstash.Status.Version != expected.Version) { return fmt.Errorf("expected status %+v but got %+v", expected, logstash.Status) } return nil From b55397050c0a292c7fa9627d5470a0af3f6b9bee Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Feb 2023 12:07:28 +0000 Subject: [PATCH 024/160] fix sidecar ES ref namespace --- pkg/apis/logstash/v1alpha1/namespace.go | 12 ++++++++++++ pkg/controller/logstash/stackmon/sidecar.go | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 pkg/apis/logstash/v1alpha1/namespace.go diff --git a/pkg/apis/logstash/v1alpha1/namespace.go b/pkg/apis/logstash/v1alpha1/namespace.go new file mode 100644 index 0000000000..8f48dc7732 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/namespace.go @@ -0,0 +1,12 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +func GetOrDefaultNamespace(ns string) string { + if ns != "" { + return ns + } + return "default" +} diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go index b39e7a5f33..916bec78bd 100644 --- a/pkg/controller/logstash/stackmon/sidecar.go +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "hash/fnv" + "k8s.io/apimachinery/pkg/types" corev1 "k8s.io/api/core/v1" @@ -31,8 +32,13 @@ const ( ) func Metricbeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha1.Logstash) (stackmon.BeatSidecar, error) { + esRef := logstash.Spec.Monitoring.Metrics.ElasticsearchRefs[0] + nsn := types.NamespacedName{ + Namespace: logstashv1alpha1.GetOrDefaultNamespace(esRef.Namespace), + Name: esRef.Name, + } username := user.MonitoringUserName - password, err := user.GetMonitoringUserPassword(client, k8s.ExtractNamespacedName(&logstash)) + password, err := user.GetMonitoringUserPassword(client, nsn) if err != nil { return stackmon.BeatSidecar{}, err } @@ -47,7 +53,7 @@ func Metricbeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha fmt.Sprintf("%s://localhost:%d", "http" /*logstash.Spec.HTTP.Protocol()*/, network.HTTPPort), username, password, - false, /* logstash.Spec.HTTP.TLS.Enabled() */ + false, ) if err != nil { return stackmon.BeatSidecar{}, err From d9f8f90d296305c83e8eb7eedeb186812ca61d3d Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Feb 2023 14:10:27 +0000 Subject: [PATCH 025/160] allow podTemplate update --- config/crds/v1/all-crds.yaml | 1 + .../crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml | 1 + config/samples/logstash/logstash.yaml | 6 +++--- .../charts/eck-operator-crds/templates/all-crds.yaml | 1 + pkg/apis/logstash/v1alpha1/logstash_types.go | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index c9302ed7d9..a634a90f38 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9655,6 +9655,7 @@ spec: description: PodTemplate provides customisation options for the Logstash pods. type: object + x-kubernetes-preserve-unknown-fields: true revisionHistoryLimit: description: RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 467a2e55b1..d8f1d80a62 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -8018,6 +8018,7 @@ spec: - containers type: object type: object + x-kubernetes-preserve-unknown-fields: true revisionHistoryLimit: description: RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml index e6283a9568..e0fbb4c773 100644 --- a/config/samples/logstash/logstash.yaml +++ b/config/samples/logstash/logstash.yaml @@ -22,6 +22,6 @@ spec: api.http.host: "0.0.0.0" queue.type: memory podTemplate: - spec: - containers: - - name: logstash + spec: + containers: + - name: logstash diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index ce343a1bd7..99738fbfa8 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9709,6 +9709,7 @@ spec: description: PodTemplate provides customisation options for the Logstash pods. type: object + x-kubernetes-preserve-unknown-fields: true revisionHistoryLimit: description: RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 123369be30..1f7bdf6a47 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -54,6 +54,7 @@ type LogstashSpec struct { Monitoring commonv1.Monitoring `json:"monitoring,omitempty"` // PodTemplate provides customisation options for the Logstash pods. + // +kubebuilder:pruning:PreserveUnknownFields PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` // RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. From f31ba83152e94919f72ac1fc2202d9f8c6347387 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Feb 2023 14:55:30 +0000 Subject: [PATCH 026/160] fix stack monitoring e2e --- test/e2e/logstash/stack_monitoring_test.go | 9 ++-- test/e2e/test/logstash/builder.go | 52 +++++++++++++++++++--- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 64d417e5da..b27e730617 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -7,16 +7,15 @@ package logstash import ( - "testing" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" + "testing" ) -// TestESStackMonitoring tests that when an Elasticsearch cluster is configured with monitoring, its log and metrics are +// TestESStackMonitoring tests that when an Logstash is configured with monitoring, its log and metrics are // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestLogstashStackMonitoring(t *testing.T) { // only execute this test on supported version @@ -32,7 +31,9 @@ func TestLogstashStackMonitoring(t *testing.T) { WithESMasterDataNodes(2, elasticsearch.DefaultResources) monitored := logstash.NewBuilder("test-ls-mon-a"). WithNodeCount(1). - WithMonitoring(metrics.Ref(), logs.Ref()) + WithMonitoring(metrics.Ref(), logs.Ref()). + //TODO: remove command when Logstash has built a container with monitor log4j2.properties + WithCommand([]string{"sh", "-c", "curl -o 'log4j2.properties' 'https://raw.githubusercontent.com/elastic/logstash/main/config/log4j2.properties' && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint"}) // checks that the sidecar beats have sent data in the monitoring clusters steps := func(k *test.K8sClient) test.StepList { diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index d2bb870f73..104c084aa5 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -5,17 +5,18 @@ package logstash import ( + "fmt" commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/rand" - "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" ) type Builder struct { @@ -117,6 +118,47 @@ func (b Builder) WithMonitoring(metricsESRef commonv1.ObjectSelector, logsESRef return b } +func (b Builder) WithCommand(command []string) Builder { + b.Logstash.Spec.PodTemplate.Spec.Containers = []corev1.Container{{Name: "logstash", Command: command}} + return b +} + +func (b Builder) GetMetricsIndexPattern() string { + v := version.MustParse(test.Ctx().ElasticStackVersion) + if v.GTE(version.MinFor(8, 3, 0)) { + return ".monitoring-logstash-8-mb" + } + if v.GTE(version.MinFor(8, 0, 0)) { + return fmt.Sprintf("metricbeat-%d.%d.%d*", v.Major, v.Minor, v.Patch) + } + + return ".monitoring-logstash-*" +} + +func (b Builder) Name() string { + return b.Logstash.Name +} + +func (b Builder) Namespace() string { + return b.Logstash.Namespace +} + +func (b Builder) GetLogsCluster() *types.NamespacedName { + if len(b.Logstash.Spec.Monitoring.Logs.ElasticsearchRefs) == 0 { + return nil + } + logsCluster := b.Logstash.Spec.Monitoring.Logs.ElasticsearchRefs[0].NamespacedName() + return &logsCluster +} + +func (b Builder) GetMetricsCluster() *types.NamespacedName { + if len(b.Logstash.Spec.Monitoring.Metrics.ElasticsearchRefs) == 0 { + return nil + } + metricsCluster := b.Logstash.Spec.Monitoring.Metrics.ElasticsearchRefs[0].NamespacedName() + return &metricsCluster +} + func (b Builder) NSN() types.NamespacedName { return k8s.ExtractNamespacedName(&b.Logstash) } From 7ff0f46e7eb081a6c4c7badff6389543483d26a7 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Feb 2023 12:20:52 +0000 Subject: [PATCH 027/160] doc and lint --- docs/reference/api-docs.asciidoc | 5 ----- pkg/apis/logstash/v1alpha1/logstash_types.go | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index d56fa7a5f0..e95f426bdc 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1842,11 +1842,6 @@ Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API g Logstash is the Schema for the logstashes API -.Appears In: -**** -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashlist[$$LogstashList$$] -**** - [cols="25a,75a", options="header"] |=== | Field | Description diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 1f7bdf6a47..3b79c84fc6 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -165,8 +165,7 @@ func (l *Logstash) GetAssociations() []commonv1.Association { } func (l *Logstash) AssociationStatusMap(typ commonv1.AssociationType) commonv1.AssociationStatusMap { - switch typ { - case commonv1.LogstashMonitoringAssociationType: + if typ == commonv1.LogstashMonitoringAssociationType { for _, esRef := range l.Spec.Monitoring.Metrics.ElasticsearchRefs { if esRef.IsDefined() { return l.Status.MonitoringAssociationStatus From 9cf60b1d73d173d9f218c73fadb450f15ff4ce1a Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Feb 2023 13:48:50 +0000 Subject: [PATCH 028/160] lint --- pkg/apis/logstash/v1alpha1/logstash_types.go | 1 + pkg/controller/association/controller/logstash_es.go | 3 ++- pkg/controller/logstash/stackmon/beat_config.go | 1 + pkg/controller/logstash/stackmon/sidecar.go | 1 + test/e2e/cmd/run/job.go | 2 +- test/e2e/test/logstash/builder.go | 12 +++++++----- test/e2e/test/logstash/checks.go | 1 + 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 3b79c84fc6..4278303502 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -6,6 +6,7 @@ package v1alpha1 import ( "fmt" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/controller/association/controller/logstash_es.go b/pkg/controller/association/controller/logstash_es.go index 75e1629ad9..a4d0cdc704 100644 --- a/pkg/controller/association/controller/logstash_es.go +++ b/pkg/controller/association/controller/logstash_es.go @@ -5,10 +5,11 @@ package controller import ( + "strings" + "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" - "strings" commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" diff --git a/pkg/controller/logstash/stackmon/beat_config.go b/pkg/controller/logstash/stackmon/beat_config.go index d26950e8f8..12e45eeb8d 100644 --- a/pkg/controller/logstash/stackmon/beat_config.go +++ b/pkg/controller/logstash/stackmon/beat_config.go @@ -7,6 +7,7 @@ package stackmon import ( "context" _ "embed" // for the beats config files + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go index 916bec78bd..2818a636f4 100644 --- a/pkg/controller/logstash/stackmon/sidecar.go +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "hash/fnv" + "k8s.io/apimachinery/pkg/types" corev1 "k8s.io/api/core/v1" diff --git a/test/e2e/cmd/run/job.go b/test/e2e/cmd/run/job.go index 1f23e89914..2ba4fd6d67 100644 --- a/test/e2e/cmd/run/job.go +++ b/test/e2e/cmd/run/job.go @@ -82,7 +82,7 @@ func (j *Job) WithDependency(dependency *Job) *Job { // onPodEvent ensures that log streaming is started and also manages the internal state of the Job based on the events // received from the informer. func (j *Job) onPodEvent(client *kubernetes.Clientset, pod *corev1.Pod) { - switch pod.Status.Phase { //nolint:exhaustive + switch pod.Status.Phase { case corev1.PodRunning: if !j.jobStarted { j.jobStarted = true diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 104c084aa5..14d40b6725 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -6,17 +6,19 @@ package logstash import ( "fmt" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/rand" - "sigs.k8s.io/controller-runtime/pkg/client" ) type Builder struct { diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index e4f5fcd632..c35021e9ba 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -8,6 +8,7 @@ import ( "context" "encoding/json" "fmt" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" From d7a587e3e299fe5c158e9c17e5f8da26d8ac2d19 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Feb 2023 18:17:39 +0000 Subject: [PATCH 029/160] fix doc gen --- docs/reference/api-docs.asciidoc | 9 +++++++-- hack/api-docs/config.yaml | 2 +- pkg/apis/logstash/v1alpha1/doc.go | 5 +---- pkg/apis/logstash/v1alpha1/logstash_types.go | 5 ++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index e95f426bdc..4990a0f434 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1835,6 +1835,9 @@ KibanaSpec holds the specification of a Kibana instance. Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API group +.Resource Types +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash[$$Logstash$$] + [id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash"] @@ -1842,9 +1845,13 @@ Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API g Logstash is the Schema for the logstashes API + + [cols="25a,75a", options="header"] |=== | Field | Description +| *`apiVersion`* __string__ | `logstash.k8s.elastic.co/v1alpha1` +| *`kind`* __string__ | `Logstash` | *`metadata`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#objectmeta-v1-meta[$$ObjectMeta$$]__ | Refer to Kubernetes API documentation for fields of `metadata`. | *`spec`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$]__ | @@ -1852,8 +1859,6 @@ Logstash is the Schema for the logstashes API |=== - - [id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec"] === LogstashSpec diff --git a/hack/api-docs/config.yaml b/hack/api-docs/config.yaml index ec20aa7197..0e09c97da0 100644 --- a/hack/api-docs/config.yaml +++ b/hack/api-docs/config.yaml @@ -1,6 +1,6 @@ processor: ignoreTypes: - - "(Elasticsearch|ElasticsearchAutoscaler|Kibana|ApmServer|EnterpriseSearch|Beat|Agent|StackConfigPolicy)List$" + - "(Elasticsearch|ElasticsearchAutoscaler|Kibana|ApmServer|EnterpriseSearch|Beat|Agent|StackConfigPolicy|Logstash)List$" - "(Kibana|ApmServer|EnterpriseSearch|Beat|Agent|StackConfigPolicy)Health$" - "(ElasticsearchAutoscaler|Kibana|ApmServer|Reconciler|EnterpriseSearch|Beat|Agent|Maps|Policy)Status$" - "ElasticsearchSettings$" diff --git a/pkg/apis/logstash/v1alpha1/doc.go b/pkg/apis/logstash/v1alpha1/doc.go index a92dd08678..3e12ffe660 100644 --- a/pkg/apis/logstash/v1alpha1/doc.go +++ b/pkg/apis/logstash/v1alpha1/doc.go @@ -3,9 +3,6 @@ // you may not use this file except in compliance with the Elastic License 2.0. // Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=github.com/elastic/cloud-on-k8s/pkg/apis/logstash -// +k8s:defaulter-gen=TypeMeta +// +kubebuilder:object:generate=true // +groupName=logstash.k8s.elastic.co package v1alpha1 diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 4278303502..6068381588 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -94,10 +94,9 @@ type LogstashStatus struct { MonitoringAssociationStatus commonv1.AssociationStatusMap `json:"monitoringAssociationStatus,omitempty"` } -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:object:root=true // Logstash is the Schema for the logstashes API -// +k8s:openapi-gen=true // +kubebuilder:resource:categories=elastic,shortName=ls // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="available",type="integer",JSONPath=".status.availableNodes",description="Available nodes" @@ -115,7 +114,7 @@ type Logstash struct { MonitoringAssocConfs map[commonv1.ObjectSelector]commonv1.AssociationConf `json:"-"` } -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:object:root=true // LogstashList contains a list of Logstash type LogstashList struct { From 0b41a42651721e564bb76cbe4e4bc7aa9ca1d60c Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Feb 2023 18:29:10 +0000 Subject: [PATCH 030/160] bring back lint --- test/e2e/cmd/run/job.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/cmd/run/job.go b/test/e2e/cmd/run/job.go index 2ba4fd6d67..1f23e89914 100644 --- a/test/e2e/cmd/run/job.go +++ b/test/e2e/cmd/run/job.go @@ -82,7 +82,7 @@ func (j *Job) WithDependency(dependency *Job) *Job { // onPodEvent ensures that log streaming is started and also manages the internal state of the Job based on the events // received from the informer. func (j *Job) onPodEvent(client *kubernetes.Clientset, pod *corev1.Pod) { - switch pod.Status.Phase { + switch pod.Status.Phase { //nolint:exhaustive case corev1.PodRunning: if !j.jobStarted { j.jobStarted = true From d96098fd6b8fb1f7178f5c3b30f0e4b52ba07bb3 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 11:13:51 +0000 Subject: [PATCH 031/160] add sample resources for stack monitoring --- .../logstash/logstash_stackmonitor.yaml | 59 +++++++++++++++++++ test/e2e/logstash/stack_monitoring_test.go | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 config/samples/logstash/logstash_stackmonitor.yaml diff --git a/config/samples/logstash/logstash_stackmonitor.yaml b/config/samples/logstash/logstash_stackmonitor.yaml new file mode 100644 index 0000000000..12ae1c9a72 --- /dev/null +++ b/config/samples/logstash/logstash_stackmonitor.yaml @@ -0,0 +1,59 @@ +--- +apiVersion: elasticsearch.k8s.elastic.co/v1 +kind: Elasticsearch +metadata: + name: monitoring +spec: + version: 8.6.1 + nodeSets: + - name: default + count: 1 + config: + node.store.allow_mmap: false +--- +apiVersion: elasticsearch.k8s.elastic.co/v1 +kind: Elasticsearch +metadata: + name: elasticsearch-sample +spec: + version: 8.6.1 + nodeSets: + - name: default + count: 1 + config: + node.store.allow_mmap: false +--- +apiVersion: logstash.k8s.elastic.co/v1alpha1 +kind: Logstash +metadata: + name: logstash-sample +spec: + count: 1 + version: 8.6.1 + config: + log.level: info + api.http.host: "0.0.0.0" + queue.type: memory + podTemplate: + spec: + containers: + - name: logstash + command: ['sh', '-c', 'curl -o "log4j2.properties" "https://raw.githubusercontent.com/elastic/logstash/main/config/log4j2.properties" && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint'] + monitoring: + metrics: + elasticsearchRefs: + - name: monitoring + logs: + elasticsearchRefs: + - name: monitoring +--- +apiVersion: kibana.k8s.elastic.co/v1 +kind: Kibana +metadata: + name: kibana-sample +spec: + version: 8.6.1 + elasticsearchRef: + name: monitoring + count: 1 +--- \ No newline at end of file diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index b27e730617..729674e264 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -32,7 +32,7 @@ func TestLogstashStackMonitoring(t *testing.T) { monitored := logstash.NewBuilder("test-ls-mon-a"). WithNodeCount(1). WithMonitoring(metrics.Ref(), logs.Ref()). - //TODO: remove command when Logstash has built a container with monitor log4j2.properties + //TODO: remove command when Logstash has built with a monitor version of log4j2.properties WithCommand([]string{"sh", "-c", "curl -o 'log4j2.properties' 'https://raw.githubusercontent.com/elastic/logstash/main/config/log4j2.properties' && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint"}) // checks that the sidecar beats have sent data in the monitoring clusters From 8eb21a21b14c151a17006ffe9cc1396c966f2ff0 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 17:19:31 +0000 Subject: [PATCH 032/160] add unit test --- pkg/apis/logstash/v1alpha1/logstash_types.go | 1 + .../logstash/stackmon/sidecar_test.go | 174 ++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 pkg/controller/logstash/stackmon/sidecar_test.go diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 6068381588..ced98519e2 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -14,6 +14,7 @@ import ( ) const ( + LogstashContainerName = "logstash" // Kind is inferred from the struct name using reflection in SchemeBuilder.Register() // we duplicate it as a constant here for practical purposes. Kind = "Logstash" diff --git a/pkg/controller/logstash/stackmon/sidecar_test.go b/pkg/controller/logstash/stackmon/sidecar_test.go new file mode 100644 index 0000000000..7bb9e35cd6 --- /dev/null +++ b/pkg/controller/logstash/stackmon/sidecar_test.go @@ -0,0 +1,174 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package stackmon + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/monitoring" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + +func TestWithMonitoring(t *testing.T) { + sampleLs := logstashv1alpha1.Logstash{ + ObjectMeta: metav1.ObjectMeta{ + Name: "sample", + Namespace: "aerospace", + }, + Spec: logstashv1alpha1.LogstashSpec{ + Version: "8.6.0", + }, + } + monitoringEsRef := []commonv1.ObjectSelector{{Name: "monitoring", Namespace: "observability"}} + logsEsRef := []commonv1.ObjectSelector{{Name: "logs", Namespace: "observability"}} + + fakeMetricsBeatUserSecret := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Name: "sample-observability-monitoring-beat-es-mon-user", Namespace: "aerospace"}, + Data: map[string][]byte{"aerospace-sample-observability-monitoring-beat-es-mon-user": []byte("1234567890")}, + } + fakeLogsBeatUserSecret := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Name: "sample-observability-logs-beat-es-mon-user", Namespace: "aerospace"}, + Data: map[string][]byte{"aerospace-sample-observability-logs-beat-es-mon-user": []byte("1234567890")}, + } + fakeEsHTTPCertSecret := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Name: "sample-es-http-certs-public", Namespace: "aerospace"}, + Data: map[string][]byte{ + "tls.crt": []byte("7H1515N074r341C3r71F1C473"), + "ca.crt": []byte("7H1515N074r341C3r71F1C473"), + }, + } + fakeLsHTTPCertSecret := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Name: "sample-ls-http-certs-public", Namespace: "aerospace"}, + Data: map[string][]byte{ + "tls.crt": []byte("7H1515N074r341C3r71F1C473"), + "ca.crt": []byte("7H1515N074r341C3r71F1C473"), + }, + } + fakeClient := k8s.NewFakeClient(&fakeMetricsBeatUserSecret, &fakeLogsBeatUserSecret, &fakeEsHTTPCertSecret, &fakeLsHTTPCertSecret) + + monitoringAssocConf := commonv1.AssociationConf{ + AuthSecretName: "sample-observability-monitoring-beat-es-mon-user", + AuthSecretKey: "aerospace-sample-observability-monitoring-beat-es-mon-user", + CACertProvided: true, + CASecretName: "sample-es-monitoring-observability-monitoring-ca", + URL: "https://monitoring-es-http.observability.svc:9200", + Version: "8.6.0", + } + logsAssocConf := commonv1.AssociationConf{ + AuthSecretName: "sample-observability-logs-beat-es-mon-user", + AuthSecretKey: "aerospace-sample-observability-logs-beat-es-mon-user", + CACertProvided: true, + CASecretName: "sample-es-logs-observability-monitoring-ca", + URL: "https://logs-es-http.observability.svc:9200", + Version: "8.6.0", + } + + tests := []struct { + name string + ls func() logstashv1alpha1.Logstash + containersLength int + podVolumesLength int + metricsVolumeMountsLength int + logVolumeMountsLength int + }{ + { + name: "without monitoring", + ls: func() logstashv1alpha1.Logstash { + return sampleLs + }, + containersLength: 1, + }, + { + name: "with metrics monitoring", + ls: func() logstashv1alpha1.Logstash { + sampleLs.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef + monitoring.GetMetricsAssociation(&sampleLs)[0].SetAssociationConf(&monitoringAssocConf) + return sampleLs + }, + containersLength: 2, + podVolumesLength: 2, + metricsVolumeMountsLength: 2, + }, + { + name: "with logs monitoring", + ls: func() logstashv1alpha1.Logstash { + sampleLs.Spec.Monitoring.Metrics.ElasticsearchRefs = nil + sampleLs.Spec.Monitoring.Logs.ElasticsearchRefs = monitoringEsRef + monitoring.GetLogsAssociation(&sampleLs)[0].SetAssociationConf(&monitoringAssocConf) + return sampleLs + }, + containersLength: 2, + podVolumesLength: 3, + logVolumeMountsLength: 3, + }, + { + name: "with metrics and logs monitoring", + ls: func() logstashv1alpha1.Logstash { + sampleLs.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef + monitoring.GetMetricsAssociation(&sampleLs)[0].SetAssociationConf(&monitoringAssocConf) + sampleLs.Spec.Monitoring.Logs.ElasticsearchRefs = monitoringEsRef + monitoring.GetLogsAssociation(&sampleLs)[0].SetAssociationConf(&logsAssocConf) + return sampleLs + }, + containersLength: 3, + podVolumesLength: 4, + metricsVolumeMountsLength: 2, + logVolumeMountsLength: 3, + }, + { + name: "with metrics and logs monitoring with different es ref", + ls: func() logstashv1alpha1.Logstash { + sampleLs.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef + monitoring.GetMetricsAssociation(&sampleLs)[0].SetAssociationConf(&monitoringAssocConf) + sampleLs.Spec.Monitoring.Logs.ElasticsearchRefs = logsEsRef + monitoring.GetLogsAssociation(&sampleLs)[0].SetAssociationConf(&logsAssocConf) + return sampleLs + }, + containersLength: 3, + podVolumesLength: 5, + metricsVolumeMountsLength: 2, + logVolumeMountsLength: 3, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + ls := tc.ls() + builder := defaults.NewPodTemplateBuilder(corev1.PodTemplateSpec{}, logstashv1alpha1.LogstashContainerName) + _, err := WithMonitoring(context.Background(), fakeClient, builder, ls) + assert.NoError(t, err) + + assert.Equal(t, tc.containersLength, len(builder.PodTemplate.Spec.Containers)) + for _, v := range builder.PodTemplate.Spec.Volumes { + fmt.Println(v) + } + assert.Equal(t, tc.podVolumesLength, len(builder.PodTemplate.Spec.Volumes)) + + if monitoring.IsMetricsDefined(&ls) { + for _, c := range builder.PodTemplate.Spec.Containers { + if c.Name == "metricbeat" { + assert.Equal(t, tc.metricsVolumeMountsLength, len(c.VolumeMounts)) + } + } + } + if monitoring.IsLogsDefined(&ls) { + for _, c := range builder.PodTemplate.Spec.Containers { + if c.Name == "filebeat" { + assert.Equal(t, tc.logVolumeMountsLength, len(c.VolumeMounts)) + } + } + } + }) + } +} From a524216e8e22701c45447251c05d3a7022e527c1 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 17:20:12 +0000 Subject: [PATCH 033/160] remove useless NamespacedName as metrics API does not take username and pw now --- pkg/controller/logstash/stackmon/sidecar.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go index 2818a636f4..05a31b34f2 100644 --- a/pkg/controller/logstash/stackmon/sidecar.go +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -9,8 +9,6 @@ import ( "fmt" "hash/fnv" - "k8s.io/apimachinery/pkg/types" - corev1 "k8s.io/api/core/v1" commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" @@ -19,7 +17,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/monitoring" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/volume" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/user" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) @@ -33,16 +30,6 @@ const ( ) func Metricbeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha1.Logstash) (stackmon.BeatSidecar, error) { - esRef := logstash.Spec.Monitoring.Metrics.ElasticsearchRefs[0] - nsn := types.NamespacedName{ - Namespace: logstashv1alpha1.GetOrDefaultNamespace(esRef.Namespace), - Name: esRef.Name, - } - username := user.MonitoringUserName - password, err := user.GetMonitoringUserPassword(client, nsn) - if err != nil { - return stackmon.BeatSidecar{}, err - } metricbeat, err := stackmon.NewMetricBeatSidecar( ctx, client, @@ -52,8 +39,8 @@ func Metricbeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha metricbeatConfigTemplate, logstashv1alpha1.Namer, fmt.Sprintf("%s://localhost:%d", "http" /*logstash.Spec.HTTP.Protocol()*/, network.HTTPPort), - username, - password, + "", /* no username for metrics API */ + "", /* no password for metrics API */ false, ) if err != nil { From 86df8fd513339efa2508425a145b51a5d6ec2878 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Mon, 27 Feb 2023 18:19:37 +0000 Subject: [PATCH 034/160] remove useless NamespacedName method --- pkg/apis/logstash/v1alpha1/namespace.go | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 pkg/apis/logstash/v1alpha1/namespace.go diff --git a/pkg/apis/logstash/v1alpha1/namespace.go b/pkg/apis/logstash/v1alpha1/namespace.go deleted file mode 100644 index 8f48dc7732..0000000000 --- a/pkg/apis/logstash/v1alpha1/namespace.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package v1alpha1 - -func GetOrDefaultNamespace(ns string) string { - if ns != "" { - return ns - } - return "default" -} From ce56d6ae779baaa7acf7012c933bfaac769b5233 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Fri, 10 Feb 2023 14:03:22 -0500 Subject: [PATCH 035/160] Initial Commit of ECK for Logstash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initial commit of a simple operator. The first operator will create: * A Service exposing the logstash metrics API, so it can be used for monitoring purposes * Secrets holding logstash.yml * A StatefulSet deploying the logstash pods * Pods with default liveness and readiness probes The sample logstash yml file as located in config/samples/logstash/logstash.yaml will create: ``` ✗ kubectl tree logstash logstash-sample NAMESPACE NAME READY REASON AGE default Logstash/logstash-sample - 4m5s default ├─Secret/logstash-sample-ls-config - 4m4s default ├─Service/logstash-sample-ls-http - 4m5s default │ └─EndpointSlice/logstash-sample-ls-http-kwfsg - 4m5s default └─StatefulSet/logstash-sample-ls - 4m4s default ├─ControllerRevision/logstash-sample-ls-79bd59f869 - 4m4s default ├─Pod/logstash-sample-ls-0 True 3m59s default ├─Pod/logstash-sample-ls-1 True 3m59s default └─Pod/logstash-sample-ls-2 True 3m59s ``` And shows status: ``` ✗ kubectl get logstash logstash-sample NAME AVAILABLE EXPECTED AGE VERSION logstash-sample 3 3 9m1s 8.6.1 ``` Still TODO: * Unit Tests * End to end Tests * Certificate handling on the HTTP Metrics API Tidy up Co-authored-by: Kaise Cheng --- cmd/manager/main.go | 21 +- config/crds/v1/all-crds.yaml | 590 ++ config/crds/v1/bases/kustomization.yaml | 1 + .../logstash.k8s.elastic.co_logstashes.yaml | 7997 +++++++++++++++++ config/crds/v1/patches/kustomization.yaml | 8 + config/crds/v1/patches/logstash-patches.yaml | 7 + config/samples/logstash/logstash.yaml | 27 + config/webhook/manifests.yaml | 22 + .../eck-operator-crds/templates/all-crds.yaml | 596 ++ docs/reference/api-docs.asciidoc | 125 + hack/upgrade-test-harness/go.sum | 4 +- pkg/apis/common/v1/association.go | 2 + pkg/apis/logstash/v1alpha1/doc.go | 11 + .../logstash/v1alpha1/groupversion_info.go | 21 + pkg/apis/logstash/v1alpha1/labels.go | 17 + pkg/apis/logstash/v1alpha1/logstash_types.go | 130 + pkg/apis/logstash/v1alpha1/name.go | 36 + pkg/apis/logstash/v1alpha1/validations.go | 56 + pkg/apis/logstash/v1alpha1/webhook.go | 88 + .../v1alpha1/zz_generated.deepcopy.go | 127 + pkg/controller/common/container/container.go | 1 + pkg/controller/common/container/defaulter.go | 7 + .../common/defaults/pod_template.go | 6 + pkg/controller/common/scheme/scheme.go | 3 + pkg/controller/common/version/version.go | 1 + pkg/controller/elasticsearch/user/roles.go | 11 + pkg/controller/logstash/config.go | 123 + pkg/controller/logstash/driver.go | 133 + pkg/controller/logstash/init_configuration.go | 75 + pkg/controller/logstash/labels.go | 16 + .../logstash/logstash_controller.go | 199 + pkg/controller/logstash/network/ports.go | 10 + pkg/controller/logstash/pod.go | 147 + pkg/controller/logstash/reconcile.go | 90 + pkg/controller/logstash/sset/sset.go | 93 + 35 files changed, 10791 insertions(+), 10 deletions(-) create mode 100644 config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml create mode 100644 config/crds/v1/patches/logstash-patches.yaml create mode 100644 config/samples/logstash/logstash.yaml create mode 100644 pkg/apis/logstash/v1alpha1/doc.go create mode 100644 pkg/apis/logstash/v1alpha1/groupversion_info.go create mode 100644 pkg/apis/logstash/v1alpha1/labels.go create mode 100644 pkg/apis/logstash/v1alpha1/logstash_types.go create mode 100644 pkg/apis/logstash/v1alpha1/name.go create mode 100644 pkg/apis/logstash/v1alpha1/validations.go create mode 100644 pkg/apis/logstash/v1alpha1/webhook.go create mode 100644 pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go create mode 100644 pkg/controller/logstash/config.go create mode 100644 pkg/controller/logstash/driver.go create mode 100644 pkg/controller/logstash/init_configuration.go create mode 100644 pkg/controller/logstash/labels.go create mode 100644 pkg/controller/logstash/logstash_controller.go create mode 100644 pkg/controller/logstash/network/ports.go create mode 100644 pkg/controller/logstash/pod.go create mode 100644 pkg/controller/logstash/reconcile.go create mode 100644 pkg/controller/logstash/sset/sset.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index fba83a755c..16cf2c55cb 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -8,6 +8,8 @@ import ( "context" "errors" "fmt" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "net/http" "net/http/pprof" "os" @@ -847,6 +849,7 @@ func registerControllers(mgr manager.Manager, params operator.Parameters, access {name: "Agent", registerFunc: agent.Add}, {name: "Maps", registerFunc: maps.Add}, {name: "StackConfigPolicy", registerFunc: stackconfigpolicy.Add}, + {name: "Logstash", registerFunc: logstash.Add}, } for _, c := range controllers { @@ -925,14 +928,15 @@ func garbageCollectSoftOwnedSecrets(ctx context.Context, k8sClient k8s.Client) { defer span.End() if err := reconciler.GarbageCollectAllSoftOwnedOrphanSecrets(ctx, k8sClient, map[string]client.Object{ - esv1.Kind: &esv1.Elasticsearch{}, - apmv1.Kind: &apmv1.ApmServer{}, - kbv1.Kind: &kbv1.Kibana{}, - entv1.Kind: &entv1.EnterpriseSearch{}, - beatv1beta1.Kind: &beatv1beta1.Beat{}, - agentv1alpha1.Kind: &agentv1alpha1.Agent{}, - emsv1alpha1.Kind: &emsv1alpha1.ElasticMapsServer{}, - policyv1alpha1.Kind: &policyv1alpha1.StackConfigPolicy{}, + esv1.Kind: &esv1.Elasticsearch{}, + apmv1.Kind: &apmv1.ApmServer{}, + kbv1.Kind: &kbv1.Kibana{}, + entv1.Kind: &entv1.EnterpriseSearch{}, + beatv1beta1.Kind: &beatv1beta1.Beat{}, + agentv1alpha1.Kind: &agentv1alpha1.Agent{}, + emsv1alpha1.Kind: &emsv1alpha1.ElasticMapsServer{}, + policyv1alpha1.Kind: &policyv1alpha1.StackConfigPolicy{}, + logstashv1alpha1.Kind: &logstashv1alpha1.Logstash{}, }); err != nil { log.Error(err, "Orphan secrets garbage collection failed, will be attempted again at next operator restart.") return @@ -973,6 +977,7 @@ func setupWebhook( &kbv1.Kibana{}, &kbv1beta1.Kibana{}, &emsv1alpha1.ElasticMapsServer{}, + &logstashv1alpha1.Logstash{}, } for _, obj := range webhookObjects { if err := commonwebhook.SetupValidatingWebhookWithConfig(&commonwebhook.Config{ diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 94bf0bcd2b..ab495fab43 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9045,6 +9045,596 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + name: logstashes.logstash.k8s.elastic.co +spec: + group: logstash.k8s.elastic.co + names: + categories: + - elastic + kind: Logstash + listKind: LogstashList + plural: logstashes + shortNames: + - ls + singular: logstash + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Available nodes + jsonPath: .status.availableNodes + name: available + type: integer + - description: Expected nodes + jsonPath: .status.expectedNodes + name: expected + type: integer + - jsonPath: .metadata.creationTimestamp + name: age + type: date + - description: Logstash version + jsonPath: .status.version + name: version + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Logstash is the Schema for the logstashes 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: LogstashSpec defines the desired state of Logstash + properties: + config: + description: Config holds the Logstash configuration. At most one + of [`Config`, `ConfigRef`] can be specified. + type: object + x-kubernetes-preserve-unknown-fields: true + configRef: + description: ConfigRef contains a reference to an existing Kubernetes + Secret holding the Logstash configuration. Logstash settings must + be specified as yaml, under a single "logstash.yml" entry. At most + one of [`Config`, `ConfigRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + count: + format: int32 + type: integer + http: + description: HTTP holds the HTTP layer configuration for the Agent + in Fleet mode with Fleet Server enabled. + properties: + service: + description: Service defines the template for the associated Kubernetes + Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. The + name and namespace provided here are managed by ECK and + will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may be + set to "false" if the cluster load-balancer does not + rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests will + be respected, regardless of this field. This field may + only be set for services with type LoadBalancer and + will be cleared if the type is changed to any other + type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is specified + manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This field + may not be changed through updates unless the type field + is also being changed to ExternalName (which requires + this field to be blank) or the type field is being changed + from ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + "None", empty string (""), or a valid IP address. Setting + this to "None" makes a "headless service" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range (as + per system configuration), and is not in use, it will + be allocated to the service; otherwise creation of the + service will fail. This field may not be changed through + updates unless the type field is also being changed + to ExternalName (which requires this field to be empty) + or the type field is being changed from ExternalName + (in which case this field may optionally be specified, + as describe above). Valid values are \"None\", empty + string (\"\"), or a valid IP address. Setting this + to \"None\" makes a \"headless service\" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. If this field is not + specified, it will be initialized from the clusterIP + field. If this field is specified, clients must ensure + that clusterIPs[0] and clusterIP have the same value. + \n This field may hold a maximum of two entries (dual-stack + IPs, in either order). These IPs must correspond to + the values of the ipFamilies field. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy field. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes system. + items: + type: string + type: array + externalName: + description: externalName is the external reference that + discovery mechanisms will return as an alias for this + service (e.g. a DNS CNAME record). No proxying will + be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires `type` + to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of the + Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that assumes + that external load balancers will take care of balancing + the service traffic between nodes, and so each node + will deliver traffic only to the node-local endpoints + of the service, without masquerading the client source + IP. (Traffic mistakenly sent to a node with no endpoints + will be dropped.) The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + Note that traffic sent to an External IP or LoadBalancer + IP from within the cluster will always get "Cluster" + semantics, but clients sending to a NodePort from within + the cluster may need to take traffic policy into account + when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External systems + (e.g. load-balancers) can use this port to determine + if a given node holds endpoints for this service or + not. If this field is specified when creating a Service + which does not need it, creation will fail. This field + will be wiped when updating a Service to no longer need + it (e.g. changing type). This field cannot be updated + once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods only + want to talk to endpoints of the service on the same + node as the pod, dropping the traffic if there are no + local endpoints. The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the cluster, + and ipFamilyPolicy allows it, it will be used; otherwise + creation of the service will fail. This field is conditionally + mutable: it allows for adding or removing a secondary + IP family, but it does not allow changing the primary + IP family of the Service. Valid values are \"IPv4\" + and \"IPv6\". This field only applies to Services of + types ClusterIP, NodePort, and LoadBalancer, and does + apply to \"headless\" services. This field will be wiped + when updating a Service to type ExternalName. \n This + field may hold a maximum of two entries (dual-stack + families, in either order). These families must correspond + to the values of the clusterIPs field, if specified. + Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is no + value provided, then this field will be set to SingleStack. + Services can be "SingleStack" (a single IP family), + "PreferDualStack" (two IP families on dual-stack configured + clusters or a single IP family on single-stack clusters), + or "RequireDualStack" (two IP families on dual-stack + configured clusters, otherwise fail). The ipFamilies + and clusterIPs fields depend on the value of this field. + This field will be wiped when updating a service to + type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set when + the Service type is 'LoadBalancer'. If not set, the + default load balancer implementation is used, today + this is typically done through the cloud provider integration, + but should apply for any default implementation. If + set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated to + a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load balancer + is created. This field will be ignored if the cloud-provider + does not support the feature. Deprecated: This field + was under-specified and its meaning varies across implementations, + and it cannot support dual-stack. As of Kubernetes v1.24, + users are encouraged to use implementation-specific + annotations when available. This field may be removed + in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified client + IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by this + service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this port. + This field follows standard Kubernetes label syntax. + Un-prefixed names are reserved for IANA standard + service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the service. + This must be a DNS_LABEL. All ports within a ServiceSpec + must have unique names. When considering the endpoints + for a Service, this must match the 'name' field + in the EndpointPort. Optional if only one ServicePort + is defined on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or LoadBalancer. Usually + assigned by the system. If a value is specified, + in-range, and not in use it will be used, otherwise + the operation will fail. If not specified, a + port will be allocated if this Service requires + one. If this field is specified when creating + a Service which does not need it, creation will + fail. This field will be wiped when updating a + Service to no longer need it (e.g. changing type + from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by this + service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number must + be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + If this is a string, it will be looked up as a + named port in the target Pod''s container ports. + If this is not specified, the value of the ''port'' + field is used (an identity map). This field is + ignored for services with clusterIP=None, and + should be omitted or set equal to the ''port'' + field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that any + agent which deals with endpoints for this Service should + disregard any indications of ready/not-ready. The primary + use case for setting this field is for a StatefulSet's + Headless Service to propagate SRV DNS records for its + Pods for the purpose of peer discovery. The Kubernetes + controllers that generate Endpoints and EndpointSlice + resources for Services interpret this to mean that all + endpoints are considered "ready" even if the Pods themselves + are not. Agents which consume only Kubernetes generated + endpoints through the Endpoints or EndpointSlice resources + can safely assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. More + info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based session + affinity. Must be ClientIP or None. Defaults to None. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The value + must be >0 && <=86400(for 1 day) if ServiceAffinity + == "ClientIP". Default value is 10800(for 3 + hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates + a cluster-internal IP address for load-balancing to + endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints rather + than a virtual IP. "NodePort" builds on ClusterIP and + allocates a port on every node which routes to the same + endpoints as the clusterIP. "LoadBalancer" builds on + NodePort and creates an external load-balancer (if supported + in the current cloud) which routes to the same endpoints + as the clusterIP. "ExternalName" aliases this service + to the specified externalName. Several other fields + do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes secret + that contains the certificate and private key for enabling + TLS. The referenced secret should contain the following: + \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: + The certificate (or a chain). - `tls.key`: The private key + to the first certificate in the certificate chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + image: + description: Image is the Logstash Docker image to deploy. Version + and Type have to match the Logstash in the image. + type: string + podTemplate: + description: PodTemplate provides customisation options for the Logstash + pods. + type: object + revisionHistoryLimit: + description: RevisionHistoryLimit is the number of revisions to retain + to allow rollback in the underlying StatefulSet. + format: int32 + type: integer + secureSettings: + description: SecureSettings is a list of references to Kubernetes + Secrets containing sensitive configuration options for the Logstash. + Secrets data can be then referenced in the Logstash config using + the Secret's keys or as specified in `Entries` field of each SecureSetting. + items: + description: SecretSource defines a data source based on a Kubernetes + Secret. + properties: + entries: + description: Entries define how to project each key-value pair + in the secret to filesystem paths. If not defined, all keys + will be projected to similarly named paths in the filesystem. + If defined, only the specified keys will be projected to the + corresponding paths. + items: + description: KeyToPath defines how to map a key in a Secret + object to a filesystem path. + properties: + key: + description: Key is the key contained in the secret. + type: string + path: + description: Path is the relative file path to map the + key to. Path must not be an absolute file path and must + not contain any ".." components. + type: string + required: + - key + type: object + type: array + secretName: + description: SecretName is the name of the secret. + type: string + required: + - secretName + type: object + type: array + serviceAccountName: + description: ServiceAccountName is used to check access from the current + resource to Elasticsearch resource in a different namespace. Can + only be used if ECK is enforcing RBAC on references. + type: string + version: + description: Version of the Logstash. + type: string + required: + - version + type: object + status: + description: LogstashStatus defines the observed state of Logstash + properties: + availableNodes: + format: int32 + type: integer + expectedNodes: + format: int32 + type: integer + observedGeneration: + description: ObservedGeneration is the most recent generation observed + for this Logstash instance. It corresponds to the metadata generation, + which is updated on mutation by the API Server. If the generation + observed in status diverges from the generation in metadata, the + Logstash controller has not yet processed the changes contained + in the Logstash specification. + format: int64 + type: integer + version: + description: 'Version of the stack resource currently running. During + version upgrades, multiple versions may run in parallel: this value + specifies the lowest version currently running.' + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.11.3 diff --git a/config/crds/v1/bases/kustomization.yaml b/config/crds/v1/bases/kustomization.yaml index 07d18db313..1c750971ee 100644 --- a/config/crds/v1/bases/kustomization.yaml +++ b/config/crds/v1/bases/kustomization.yaml @@ -8,3 +8,4 @@ resources: - agent.k8s.elastic.co_agents.yaml - maps.k8s.elastic.co_elasticmapsservers.yaml - stackconfigpolicy.k8s.elastic.co_stackconfigpolicies.yaml + - logstash.k8s.elastic.co_logstashes.yaml diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml new file mode 100644 index 0000000000..861b378eb4 --- /dev/null +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -0,0 +1,7997 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + name: logstashes.logstash.k8s.elastic.co +spec: + group: logstash.k8s.elastic.co + names: + categories: + - elastic + kind: Logstash + listKind: LogstashList + plural: logstashes + shortNames: + - ls + singular: logstash + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Available nodes + jsonPath: .status.availableNodes + name: available + type: integer + - description: Expected nodes + jsonPath: .status.expectedNodes + name: expected + type: integer + - jsonPath: .metadata.creationTimestamp + name: age + type: date + - description: Logstash version + jsonPath: .status.version + name: version + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Logstash is the Schema for the logstashes 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: LogstashSpec defines the desired state of Logstash + properties: + config: + description: Config holds the Logstash configuration. At most one + of [`Config`, `ConfigRef`] can be specified. + type: object + x-kubernetes-preserve-unknown-fields: true + configRef: + description: ConfigRef contains a reference to an existing Kubernetes + Secret holding the Logstash configuration. Logstash settings must + be specified as yaml, under a single "logstash.yml" entry. At most + one of [`Config`, `ConfigRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + count: + format: int32 + type: integer + http: + description: HTTP holds the HTTP layer configuration for the Agent + in Fleet mode with Fleet Server enabled. + properties: + service: + description: Service defines the template for the associated Kubernetes + Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. The + name and namespace provided here are managed by ECK and + will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may be + set to "false" if the cluster load-balancer does not + rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests will + be respected, regardless of this field. This field may + only be set for services with type LoadBalancer and + will be cleared if the type is changed to any other + type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is specified + manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This field + may not be changed through updates unless the type field + is also being changed to ExternalName (which requires + this field to be blank) or the type field is being changed + from ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + "None", empty string (""), or a valid IP address. Setting + this to "None" makes a "headless service" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range (as + per system configuration), and is not in use, it will + be allocated to the service; otherwise creation of the + service will fail. This field may not be changed through + updates unless the type field is also being changed + to ExternalName (which requires this field to be empty) + or the type field is being changed from ExternalName + (in which case this field may optionally be specified, + as describe above). Valid values are \"None\", empty + string (\"\"), or a valid IP address. Setting this + to \"None\" makes a \"headless service\" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. If this field is not + specified, it will be initialized from the clusterIP + field. If this field is specified, clients must ensure + that clusterIPs[0] and clusterIP have the same value. + \n This field may hold a maximum of two entries (dual-stack + IPs, in either order). These IPs must correspond to + the values of the ipFamilies field. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy field. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes system. + items: + type: string + type: array + externalName: + description: externalName is the external reference that + discovery mechanisms will return as an alias for this + service (e.g. a DNS CNAME record). No proxying will + be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires `type` + to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of the + Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that assumes + that external load balancers will take care of balancing + the service traffic between nodes, and so each node + will deliver traffic only to the node-local endpoints + of the service, without masquerading the client source + IP. (Traffic mistakenly sent to a node with no endpoints + will be dropped.) The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + Note that traffic sent to an External IP or LoadBalancer + IP from within the cluster will always get "Cluster" + semantics, but clients sending to a NodePort from within + the cluster may need to take traffic policy into account + when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External systems + (e.g. load-balancers) can use this port to determine + if a given node holds endpoints for this service or + not. If this field is specified when creating a Service + which does not need it, creation will fail. This field + will be wiped when updating a Service to no longer need + it (e.g. changing type). This field cannot be updated + once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods only + want to talk to endpoints of the service on the same + node as the pod, dropping the traffic if there are no + local endpoints. The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the cluster, + and ipFamilyPolicy allows it, it will be used; otherwise + creation of the service will fail. This field is conditionally + mutable: it allows for adding or removing a secondary + IP family, but it does not allow changing the primary + IP family of the Service. Valid values are \"IPv4\" + and \"IPv6\". This field only applies to Services of + types ClusterIP, NodePort, and LoadBalancer, and does + apply to \"headless\" services. This field will be wiped + when updating a Service to type ExternalName. \n This + field may hold a maximum of two entries (dual-stack + families, in either order). These families must correspond + to the values of the clusterIPs field, if specified. + Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is no + value provided, then this field will be set to SingleStack. + Services can be "SingleStack" (a single IP family), + "PreferDualStack" (two IP families on dual-stack configured + clusters or a single IP family on single-stack clusters), + or "RequireDualStack" (two IP families on dual-stack + configured clusters, otherwise fail). The ipFamilies + and clusterIPs fields depend on the value of this field. + This field will be wiped when updating a service to + type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set when + the Service type is 'LoadBalancer'. If not set, the + default load balancer implementation is used, today + this is typically done through the cloud provider integration, + but should apply for any default implementation. If + set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated to + a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load balancer + is created. This field will be ignored if the cloud-provider + does not support the feature. Deprecated: This field + was under-specified and its meaning varies across implementations, + and it cannot support dual-stack. As of Kubernetes v1.24, + users are encouraged to use implementation-specific + annotations when available. This field may be removed + in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified client + IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by this + service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this port. + This field follows standard Kubernetes label syntax. + Un-prefixed names are reserved for IANA standard + service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the service. + This must be a DNS_LABEL. All ports within a ServiceSpec + must have unique names. When considering the endpoints + for a Service, this must match the 'name' field + in the EndpointPort. Optional if only one ServicePort + is defined on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or LoadBalancer. Usually + assigned by the system. If a value is specified, + in-range, and not in use it will be used, otherwise + the operation will fail. If not specified, a + port will be allocated if this Service requires + one. If this field is specified when creating + a Service which does not need it, creation will + fail. This field will be wiped when updating a + Service to no longer need it (e.g. changing type + from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by this + service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number must + be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + If this is a string, it will be looked up as a + named port in the target Pod''s container ports. + If this is not specified, the value of the ''port'' + field is used (an identity map). This field is + ignored for services with clusterIP=None, and + should be omitted or set equal to the ''port'' + field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that any + agent which deals with endpoints for this Service should + disregard any indications of ready/not-ready. The primary + use case for setting this field is for a StatefulSet's + Headless Service to propagate SRV DNS records for its + Pods for the purpose of peer discovery. The Kubernetes + controllers that generate Endpoints and EndpointSlice + resources for Services interpret this to mean that all + endpoints are considered "ready" even if the Pods themselves + are not. Agents which consume only Kubernetes generated + endpoints through the Endpoints or EndpointSlice resources + can safely assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. More + info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based session + affinity. Must be ClientIP or None. Defaults to None. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The value + must be >0 && <=86400(for 1 day) if ServiceAffinity + == "ClientIP". Default value is 10800(for 3 + hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates + a cluster-internal IP address for load-balancing to + endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints rather + than a virtual IP. "NodePort" builds on ClusterIP and + allocates a port on every node which routes to the same + endpoints as the clusterIP. "LoadBalancer" builds on + NodePort and creates an external load-balancer (if supported + in the current cloud) which routes to the same endpoints + as the clusterIP. "ExternalName" aliases this service + to the specified externalName. Several other fields + do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes secret + that contains the certificate and private key for enabling + TLS. The referenced secret should contain the following: + \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: + The certificate (or a chain). - `tls.key`: The private key + to the first certificate in the certificate chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + image: + description: Image is the Logstash Docker image to deploy. Version + and Type have to match the Logstash in the image. + type: string + podTemplate: + description: PodTemplate provides customisation options for the Logstash + pods. + properties: + metadata: + description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata' + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: 'Specification of the desired behavior of the pod. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status' + properties: + activeDeadlineSeconds: + description: Optional duration in seconds the pod may be active + on the node relative to StartTime before the system will + actively try to mark it failed and kill associated containers. + Value must be a positive integer. + format: int64 + type: integer + affinity: + description: If specified, the pod's scheduling constraints + 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 + automountServiceAccountToken: + description: AutomountServiceAccountToken indicates whether + a service account token should be automatically mounted. + type: boolean + containers: + description: List of containers belonging to the pod. Containers + cannot currently be added or removed. There must be at least + one container in a Pod. Cannot be updated. + items: + description: A single application container that you want + to run within a pod. + properties: + args: + description: 'Arguments to the entrypoint. The container + image''s CMD is used if this is not provided. Variable + references $(VAR_NAME) are expanded using the container''s + environment. If a variable cannot be resolved, the + reference in the input string will be unchanged. Double + $$ are reduced to a single $, which allows for escaping + the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce + the string literal "$(VAR_NAME)". Escaped references + will never be expanded, regardless of whether the + variable exists or not. Cannot be updated. More info: + https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + command: + description: 'Entrypoint array. Not executed within + a shell. The container image''s ENTRYPOINT is used + if this is not provided. Variable references $(VAR_NAME) + are expanded using the container''s environment. If + a variable cannot be resolved, the reference in the + input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) + syntax: i.e. "$$(VAR_NAME)" will produce the string + literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists + or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + env: + description: List of environment variables to set in + the container. Cannot be updated. + items: + description: EnvVar represents an environment variable + present in a Container. + properties: + name: + description: Name of the environment variable. + Must be a C_IDENTIFIER. + type: string + value: + description: 'Variable references $(VAR_NAME) + are expanded using the previously defined environment + variables in the container and any service environment + variables. If a variable cannot be resolved, + the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows + for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" + will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults + to "".' + type: string + valueFrom: + description: Source for the environment variable's + value. Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + 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 + optional: + description: Specify whether the ConfigMap + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + description: 'Selects a field of the pod: + supports metadata.name, metadata.namespace, + `metadata.labels['''']`, `metadata.annotations['''']`, + spec.nodeName, spec.serviceAccountName, + status.hostIP, status.podIP, status.podIPs.' + properties: + apiVersion: + description: Version of the schema the + FieldPath is written in terms of, defaults + to "v1". + type: string + fieldPath: + description: Path of the field to select + in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, limits.ephemeral-storage, + requests.cpu, requests.memory and requests.ephemeral-storage) + are currently supported.' + properties: + containerName: + description: 'Container name: required + for volumes, optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format + of the exposed resources, defaults to + "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + description: Selects a key of a secret in + the pod's namespace + properties: + key: + description: The key of the secret to + select from. Must be a valid secret + key. + type: string + 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 + optional: + description: Specify whether the Secret + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + envFrom: + description: List of sources to populate environment + variables in the container. The keys defined within + a source must be a C_IDENTIFIER. All invalid keys + will be reported as an event when the container is + starting. When a key exists in multiple sources, the + value associated with the last source will take precedence. + Values defined by an Env with a duplicate key will + take precedence. Cannot be updated. + items: + description: EnvFromSource represents the source of + a set of ConfigMaps + properties: + configMapRef: + description: The ConfigMap to select from + 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 + optional: + description: Specify whether the ConfigMap + must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + prefix: + description: An optional identifier to prepend + to each key in the ConfigMap. Must be a C_IDENTIFIER. + type: string + secretRef: + description: The Secret to select from + 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 + optional: + description: Specify whether the Secret must + be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + type: object + type: array + image: + description: 'Container image name. More info: https://kubernetes.io/docs/concepts/containers/images + This field is optional to allow higher level config + management to default or override container images + in workload controllers like Deployments and StatefulSets.' + type: string + imagePullPolicy: + description: 'Image pull policy. One of Always, Never, + IfNotPresent. Defaults to Always if :latest tag is + specified, or IfNotPresent otherwise. Cannot be updated. + More info: https://kubernetes.io/docs/concepts/containers/images#updating-images' + type: string + lifecycle: + description: Actions that the management system should + take in response to container lifecycle events. Cannot + be updated. + properties: + postStart: + description: 'PostStart is called immediately after + a container is created. If the handler fails, + the container is terminated and restarted according + to its restart policy. Other management of the + container blocks until the hook completes. More + info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before + a container is terminated due to an API request + or management event such as liveness/startup probe + failure, preemption, resource contention, etc. + The handler is not called if the container crashes + or exits. The Pod''s termination grace period + countdown begins before the PreStop hook is executed. + Regardless of the outcome of the handler, the + container will eventually terminate within the + Pod''s termination grace period (unless delayed + by finalizers). Other management of the container + blocks until the hook completes or until the termination + grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object + livenessProbe: + description: 'Periodic probe of container liveness. + Container will be restarted if the probe fails. Cannot + be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + name: + description: Name of the container specified as a DNS_LABEL. + Each container in a pod must have a unique name (DNS_LABEL). + Cannot be updated. + type: string + ports: + description: List of ports to expose from the container. + Not specifying a port here DOES NOT prevent that port + from being exposed. Any port which is listening on + the default "0.0.0.0" address inside a container will + be accessible from the network. Modifying this array + with strategic merge patch may corrupt the data. For + more information See https://github.com/kubernetes/kubernetes/issues/108255. + Cannot be updated. + items: + description: ContainerPort represents a network port + in a single container. + properties: + containerPort: + description: Number of port to expose on the pod's + IP address. This must be a valid port number, + 0 < x < 65536. + format: int32 + type: integer + hostIP: + description: What host IP to bind the external + port to. + type: string + hostPort: + description: Number of port to expose on the host. + If specified, this must be a valid port number, + 0 < x < 65536. If HostNetwork is specified, + this must match ContainerPort. Most containers + do not need this. + format: int32 + type: integer + name: + description: If specified, this must be an IANA_SVC_NAME + and unique within the pod. Each named port in + a pod must have a unique name. Name for the + port that can be referred to by services. + type: string + protocol: + default: TCP + description: Protocol for port. Must be UDP, TCP, + or SCTP. Defaults to "TCP". + type: string + required: + - containerPort + type: object + type: array + x-kubernetes-list-map-keys: + - containerPort + - protocol + x-kubernetes-list-type: map + readinessProbe: + description: 'Periodic probe of container service readiness. + Container will be removed from service endpoints if + the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + resources: + description: 'Compute Resources required by this container. + Cannot be updated. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + 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." + 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. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + securityContext: + description: 'SecurityContext defines the security options + the container should be run with. If set, the fields + of SecurityContext override the equivalent fields + of PodSecurityContext. More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/' + properties: + allowPrivilegeEscalation: + description: 'AllowPrivilegeEscalation controls + whether a process can gain more privileges than + its parent process. This bool directly controls + if the no_new_privs flag will be set on the container + process. AllowPrivilegeEscalation is true always + when the container is: 1) run as Privileged 2) + has CAP_SYS_ADMIN Note that this field cannot + be set when spec.os.name is windows.' + type: boolean + capabilities: + description: The capabilities to add/drop when running + containers. Defaults to the default set of capabilities + granted by the container runtime. Note that this + field cannot be set when spec.os.name is windows. + properties: + add: + description: Added capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + drop: + description: Removed capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + type: object + privileged: + description: Run container in privileged mode. Processes + in privileged containers are essentially equivalent + to root on the host. Defaults to false. Note that + this field cannot be set when spec.os.name is + windows. + type: boolean + procMount: + description: procMount denotes the type of proc + mount to use for the containers. The default is + DefaultProcMount which uses the container runtime + defaults for readonly paths and masked paths. + This requires the ProcMountType feature flag to + be enabled. Note that this field cannot be set + when spec.os.name is windows. + type: string + readOnlyRootFilesystem: + description: Whether this container has a read-only + root filesystem. Default is false. Note that this + field cannot be set when spec.os.name is windows. + type: boolean + runAsGroup: + description: The GID to run the entrypoint of the + container process. Uses runtime default if unset. + May also be set in PodSecurityContext. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + format: int64 + type: integer + runAsNonRoot: + description: Indicates that the container must run + as a non-root user. If true, the Kubelet will + validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start + the container if it does. If unset or false, no + such validation will be performed. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. + type: boolean + runAsUser: + description: The UID to run the entrypoint of the + container process. Defaults to user specified + in image metadata if unspecified. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. Note that this + field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: The SELinux context to be applied to + the container. If unspecified, the container runtime + will allocate a random SELinux context for each + container. May also be set in PodSecurityContext. If + set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + properties: + level: + description: Level is SELinux level label that + applies to the container. + type: string + role: + description: Role is a SELinux role label that + applies to the container. + type: string + type: + description: Type is a SELinux type label that + applies to the container. + type: string + user: + description: User is a SELinux user label that + applies to the container. + type: string + type: object + seccompProfile: + description: The seccomp options to use by this + container. If seccomp options are provided at + both the pod & container level, the container + options override the pod options. Note that this + field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: localhostProfile indicates a profile + defined in a file on the node should be used. + The profile must be preconfigured on the node + to work. Must be a descending path, relative + to the kubelet's configured seccomp profile + location. Must only be set if type is "Localhost". + type: string + type: + description: "type indicates which kind of seccomp + profile will be applied. Valid options are: + \n Localhost - a profile defined in a file + on the node should be used. RuntimeDefault + - the container runtime default profile should + be used. Unconfined - no profile should be + applied." + type: string + required: + - type + type: object + windowsOptions: + description: The Windows specific settings applied + to all containers. If unspecified, the options + from the PodSecurityContext will be used. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is linux. + properties: + gmsaCredentialSpec: + description: GMSACredentialSpec is where the + GMSA admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) + inlines the contents of the GMSA credential + spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name + of the GMSA credential spec to use. + type: string + hostProcess: + description: HostProcess determines if a container + should be run as a 'Host Process' container. + This field is alpha-level and will only be + honored by components that enable the WindowsHostProcessContainers + feature flag. Setting this field without the + feature flag will result in errors when validating + the Pod. All of a Pod's containers must have + the same effective HostProcess value (it is + not allowed to have a mix of HostProcess containers + and non-HostProcess containers). In addition, + if HostProcess is true then HostNetwork must + also be set to true. + type: boolean + runAsUserName: + description: The UserName in Windows to run + the entrypoint of the container process. Defaults + to the user specified in image metadata if + unspecified. May also be set in PodSecurityContext. + If set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes + precedence. + type: string + type: object + type: object + startupProbe: + description: 'StartupProbe indicates that the Pod has + successfully initialized. If specified, no other probes + are executed until this completes successfully. If + this probe fails, the Pod will be restarted, just + as if the livenessProbe failed. This can be used to + provide different probe parameters at the beginning + of a Pod''s lifecycle, when it might take a long time + to load data or warm a cache, than during steady-state + operation. This cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + stdin: + description: Whether this container should allocate + a buffer for stdin in the container runtime. If this + is not set, reads from stdin in the container will + always result in EOF. Default is false. + type: boolean + stdinOnce: + description: Whether the container runtime should close + the stdin channel after it has been opened by a single + attach. When stdin is true the stdin stream will remain + open across multiple attach sessions. If stdinOnce + is set to true, stdin is opened on container start, + is empty until the first client attaches to stdin, + and then remains open and accepts data until the client + disconnects, at which time stdin is closed and remains + closed until the container is restarted. If this flag + is false, a container processes that reads from stdin + will never receive an EOF. Default is false + type: boolean + terminationMessagePath: + description: 'Optional: Path at which the file to which + the container''s termination message will be written + is mounted into the container''s filesystem. Message + written is intended to be brief final status, such + as an assertion failure message. Will be truncated + by the node if greater than 4096 bytes. The total + message length across all containers will be limited + to 12kb. Defaults to /dev/termination-log. Cannot + be updated.' + type: string + terminationMessagePolicy: + description: Indicate how the termination message should + be populated. File will use the contents of terminationMessagePath + to populate the container status message on both success + and failure. FallbackToLogsOnError will use the last + chunk of container log output if the termination message + file is empty and the container exited with an error. + The log output is limited to 2048 bytes or 80 lines, + whichever is smaller. Defaults to File. Cannot be + updated. + type: string + tty: + description: Whether this container should allocate + a TTY for itself, also requires 'stdin' to be true. + Default is false. + type: boolean + volumeDevices: + description: volumeDevices is the list of block devices + to be used by the container. + items: + description: volumeDevice describes a mapping of a + raw block device within a container. + properties: + devicePath: + description: devicePath is the path inside of + the container that the device will be mapped + to. + type: string + name: + description: name must match the name of a persistentVolumeClaim + in the pod + type: string + required: + - devicePath + - name + type: object + type: array + volumeMounts: + description: Pod volumes to mount into the container's + filesystem. Cannot be updated. + items: + description: VolumeMount describes a mounting of a + Volume within a container. + properties: + mountPath: + description: Path within the container at which + the volume should be mounted. Must not contain + ':'. + type: string + mountPropagation: + description: mountPropagation determines how mounts + are propagated from the host to container and + the other way around. When not set, MountPropagationNone + is used. This field is beta in 1.10. + type: string + name: + description: This must match the Name of a Volume. + type: string + readOnly: + description: Mounted read-only if true, read-write + otherwise (false or unspecified). Defaults to + false. + type: boolean + subPath: + description: Path within the volume from which + the container's volume should be mounted. Defaults + to "" (volume's root). + type: string + subPathExpr: + description: Expanded path within the volume from + which the container's volume should be mounted. + Behaves similarly to SubPath but environment + variable references $(VAR_NAME) are expanded + using the container's environment. Defaults + to "" (volume's root). SubPathExpr and SubPath + are mutually exclusive. + type: string + required: + - mountPath + - name + type: object + type: array + workingDir: + description: Container's working directory. If not specified, + the container runtime's default will be used, which + might be configured in the container image. Cannot + be updated. + type: string + required: + - name + type: object + type: array + dnsConfig: + description: Specifies the DNS parameters of a pod. Parameters + specified here will be merged to the generated DNS configuration + based on DNSPolicy. + properties: + nameservers: + description: A list of DNS name server IP addresses. This + will be appended to the base nameservers generated from + DNSPolicy. Duplicated nameservers will be removed. + items: + type: string + type: array + options: + description: A list of DNS resolver options. This will + be merged with the base options generated from DNSPolicy. + Duplicated entries will be removed. Resolution options + given in Options will override those that appear in + the base DNSPolicy. + items: + description: PodDNSConfigOption defines DNS resolver + options of a pod. + properties: + name: + description: Required. + type: string + value: + type: string + type: object + type: array + searches: + description: A list of DNS search domains for host-name + lookup. This will be appended to the base search paths + generated from DNSPolicy. Duplicated search paths will + be removed. + items: + type: string + type: array + type: object + dnsPolicy: + description: Set DNS policy for the pod. Defaults to "ClusterFirst". + Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', + 'Default' or 'None'. DNS parameters given in DNSConfig will + be merged with the policy selected with DNSPolicy. To have + DNS options set along with hostNetwork, you have to specify + DNS policy explicitly to 'ClusterFirstWithHostNet'. + type: string + enableServiceLinks: + description: 'EnableServiceLinks indicates whether information + about services should be injected into pod''s environment + variables, matching the syntax of Docker links. Optional: + Defaults to true.' + type: boolean + ephemeralContainers: + description: List of ephemeral containers run in this pod. + Ephemeral containers may be run in an existing pod to perform + user-initiated actions such as debugging. This list cannot + be specified when creating a pod, and it cannot be modified + by updating the pod spec. In order to add an ephemeral container + to an existing pod, use the pod's ephemeralcontainers subresource. + items: + description: "An EphemeralContainer is a temporary container + that you may add to an existing Pod for user-initiated + activities such as debugging. Ephemeral containers have + no resource or scheduling guarantees, and they will not + be restarted when they exit or when a Pod is removed or + restarted. The kubelet may evict a Pod if an ephemeral + container causes the Pod to exceed its resource allocation. + \n To add an ephemeral container, use the ephemeralcontainers + subresource of an existing Pod. Ephemeral containers may + not be removed or restarted." + properties: + args: + description: 'Arguments to the entrypoint. The image''s + CMD is used if this is not provided. Variable references + $(VAR_NAME) are expanded using the container''s environment. + If a variable cannot be resolved, the reference in + the input string will be unchanged. Double $$ are + reduced to a single $, which allows for escaping the + $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce + the string literal "$(VAR_NAME)". Escaped references + will never be expanded, regardless of whether the + variable exists or not. Cannot be updated. More info: + https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + command: + description: 'Entrypoint array. Not executed within + a shell. The image''s ENTRYPOINT is used if this is + not provided. Variable references $(VAR_NAME) are + expanded using the container''s environment. If a + variable cannot be resolved, the reference in the + input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) + syntax: i.e. "$$(VAR_NAME)" will produce the string + literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists + or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + env: + description: List of environment variables to set in + the container. Cannot be updated. + items: + description: EnvVar represents an environment variable + present in a Container. + properties: + name: + description: Name of the environment variable. + Must be a C_IDENTIFIER. + type: string + value: + description: 'Variable references $(VAR_NAME) + are expanded using the previously defined environment + variables in the container and any service environment + variables. If a variable cannot be resolved, + the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows + for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" + will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults + to "".' + type: string + valueFrom: + description: Source for the environment variable's + value. Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + 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 + optional: + description: Specify whether the ConfigMap + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + description: 'Selects a field of the pod: + supports metadata.name, metadata.namespace, + `metadata.labels['''']`, `metadata.annotations['''']`, + spec.nodeName, spec.serviceAccountName, + status.hostIP, status.podIP, status.podIPs.' + properties: + apiVersion: + description: Version of the schema the + FieldPath is written in terms of, defaults + to "v1". + type: string + fieldPath: + description: Path of the field to select + in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, limits.ephemeral-storage, + requests.cpu, requests.memory and requests.ephemeral-storage) + are currently supported.' + properties: + containerName: + description: 'Container name: required + for volumes, optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format + of the exposed resources, defaults to + "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + description: Selects a key of a secret in + the pod's namespace + properties: + key: + description: The key of the secret to + select from. Must be a valid secret + key. + type: string + 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 + optional: + description: Specify whether the Secret + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + envFrom: + description: List of sources to populate environment + variables in the container. The keys defined within + a source must be a C_IDENTIFIER. All invalid keys + will be reported as an event when the container is + starting. When a key exists in multiple sources, the + value associated with the last source will take precedence. + Values defined by an Env with a duplicate key will + take precedence. Cannot be updated. + items: + description: EnvFromSource represents the source of + a set of ConfigMaps + properties: + configMapRef: + description: The ConfigMap to select from + 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 + optional: + description: Specify whether the ConfigMap + must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + prefix: + description: An optional identifier to prepend + to each key in the ConfigMap. Must be a C_IDENTIFIER. + type: string + secretRef: + description: The Secret to select from + 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 + optional: + description: Specify whether the Secret must + be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + type: object + type: array + image: + description: 'Container image name. More info: https://kubernetes.io/docs/concepts/containers/images' + type: string + imagePullPolicy: + description: 'Image pull policy. One of Always, Never, + IfNotPresent. Defaults to Always if :latest tag is + specified, or IfNotPresent otherwise. Cannot be updated. + More info: https://kubernetes.io/docs/concepts/containers/images#updating-images' + type: string + lifecycle: + description: Lifecycle is not allowed for ephemeral + containers. + properties: + postStart: + description: 'PostStart is called immediately after + a container is created. If the handler fails, + the container is terminated and restarted according + to its restart policy. Other management of the + container blocks until the hook completes. More + info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before + a container is terminated due to an API request + or management event such as liveness/startup probe + failure, preemption, resource contention, etc. + The handler is not called if the container crashes + or exits. The Pod''s termination grace period + countdown begins before the PreStop hook is executed. + Regardless of the outcome of the handler, the + container will eventually terminate within the + Pod''s termination grace period (unless delayed + by finalizers). Other management of the container + blocks until the hook completes or until the termination + grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object + livenessProbe: + description: Probes are not allowed for ephemeral containers. + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + name: + description: Name of the ephemeral container specified + as a DNS_LABEL. This name must be unique among all + containers, init containers and ephemeral containers. + type: string + ports: + description: Ports are not allowed for ephemeral containers. + items: + description: ContainerPort represents a network port + in a single container. + properties: + containerPort: + description: Number of port to expose on the pod's + IP address. This must be a valid port number, + 0 < x < 65536. + format: int32 + type: integer + hostIP: + description: What host IP to bind the external + port to. + type: string + hostPort: + description: Number of port to expose on the host. + If specified, this must be a valid port number, + 0 < x < 65536. If HostNetwork is specified, + this must match ContainerPort. Most containers + do not need this. + format: int32 + type: integer + name: + description: If specified, this must be an IANA_SVC_NAME + and unique within the pod. Each named port in + a pod must have a unique name. Name for the + port that can be referred to by services. + type: string + protocol: + default: TCP + description: Protocol for port. Must be UDP, TCP, + or SCTP. Defaults to "TCP". + type: string + required: + - containerPort + type: object + type: array + x-kubernetes-list-map-keys: + - containerPort + - protocol + x-kubernetes-list-type: map + readinessProbe: + description: Probes are not allowed for ephemeral containers. + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + resources: + description: Resources are not allowed for ephemeral + containers. Ephemeral containers use spare resources + already allocated to the pod. + 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." + 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. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + securityContext: + description: 'Optional: SecurityContext defines the + security options the ephemeral container should be + run with. If set, the fields of SecurityContext override + the equivalent fields of PodSecurityContext.' + properties: + allowPrivilegeEscalation: + description: 'AllowPrivilegeEscalation controls + whether a process can gain more privileges than + its parent process. This bool directly controls + if the no_new_privs flag will be set on the container + process. AllowPrivilegeEscalation is true always + when the container is: 1) run as Privileged 2) + has CAP_SYS_ADMIN Note that this field cannot + be set when spec.os.name is windows.' + type: boolean + capabilities: + description: The capabilities to add/drop when running + containers. Defaults to the default set of capabilities + granted by the container runtime. Note that this + field cannot be set when spec.os.name is windows. + properties: + add: + description: Added capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + drop: + description: Removed capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + type: object + privileged: + description: Run container in privileged mode. Processes + in privileged containers are essentially equivalent + to root on the host. Defaults to false. Note that + this field cannot be set when spec.os.name is + windows. + type: boolean + procMount: + description: procMount denotes the type of proc + mount to use for the containers. The default is + DefaultProcMount which uses the container runtime + defaults for readonly paths and masked paths. + This requires the ProcMountType feature flag to + be enabled. Note that this field cannot be set + when spec.os.name is windows. + type: string + readOnlyRootFilesystem: + description: Whether this container has a read-only + root filesystem. Default is false. Note that this + field cannot be set when spec.os.name is windows. + type: boolean + runAsGroup: + description: The GID to run the entrypoint of the + container process. Uses runtime default if unset. + May also be set in PodSecurityContext. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + format: int64 + type: integer + runAsNonRoot: + description: Indicates that the container must run + as a non-root user. If true, the Kubelet will + validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start + the container if it does. If unset or false, no + such validation will be performed. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. + type: boolean + runAsUser: + description: The UID to run the entrypoint of the + container process. Defaults to user specified + in image metadata if unspecified. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. Note that this + field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: The SELinux context to be applied to + the container. If unspecified, the container runtime + will allocate a random SELinux context for each + container. May also be set in PodSecurityContext. If + set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + properties: + level: + description: Level is SELinux level label that + applies to the container. + type: string + role: + description: Role is a SELinux role label that + applies to the container. + type: string + type: + description: Type is a SELinux type label that + applies to the container. + type: string + user: + description: User is a SELinux user label that + applies to the container. + type: string + type: object + seccompProfile: + description: The seccomp options to use by this + container. If seccomp options are provided at + both the pod & container level, the container + options override the pod options. Note that this + field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: localhostProfile indicates a profile + defined in a file on the node should be used. + The profile must be preconfigured on the node + to work. Must be a descending path, relative + to the kubelet's configured seccomp profile + location. Must only be set if type is "Localhost". + type: string + type: + description: "type indicates which kind of seccomp + profile will be applied. Valid options are: + \n Localhost - a profile defined in a file + on the node should be used. RuntimeDefault + - the container runtime default profile should + be used. Unconfined - no profile should be + applied." + type: string + required: + - type + type: object + windowsOptions: + description: The Windows specific settings applied + to all containers. If unspecified, the options + from the PodSecurityContext will be used. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is linux. + properties: + gmsaCredentialSpec: + description: GMSACredentialSpec is where the + GMSA admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) + inlines the contents of the GMSA credential + spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name + of the GMSA credential spec to use. + type: string + hostProcess: + description: HostProcess determines if a container + should be run as a 'Host Process' container. + This field is alpha-level and will only be + honored by components that enable the WindowsHostProcessContainers + feature flag. Setting this field without the + feature flag will result in errors when validating + the Pod. All of a Pod's containers must have + the same effective HostProcess value (it is + not allowed to have a mix of HostProcess containers + and non-HostProcess containers). In addition, + if HostProcess is true then HostNetwork must + also be set to true. + type: boolean + runAsUserName: + description: The UserName in Windows to run + the entrypoint of the container process. Defaults + to the user specified in image metadata if + unspecified. May also be set in PodSecurityContext. + If set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes + precedence. + type: string + type: object + type: object + startupProbe: + description: Probes are not allowed for ephemeral containers. + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + stdin: + description: Whether this container should allocate + a buffer for stdin in the container runtime. If this + is not set, reads from stdin in the container will + always result in EOF. Default is false. + type: boolean + stdinOnce: + description: Whether the container runtime should close + the stdin channel after it has been opened by a single + attach. When stdin is true the stdin stream will remain + open across multiple attach sessions. If stdinOnce + is set to true, stdin is opened on container start, + is empty until the first client attaches to stdin, + and then remains open and accepts data until the client + disconnects, at which time stdin is closed and remains + closed until the container is restarted. If this flag + is false, a container processes that reads from stdin + will never receive an EOF. Default is false + type: boolean + targetContainerName: + description: "If set, the name of the container from + PodSpec that this ephemeral container targets. The + ephemeral container will be run in the namespaces + (IPC, PID, etc) of this container. If not set then + the ephemeral container uses the namespaces configured + in the Pod spec. \n The container runtime must implement + support for this feature. If the runtime does not + support namespace targeting then the result of setting + this field is undefined." + type: string + terminationMessagePath: + description: 'Optional: Path at which the file to which + the container''s termination message will be written + is mounted into the container''s filesystem. Message + written is intended to be brief final status, such + as an assertion failure message. Will be truncated + by the node if greater than 4096 bytes. The total + message length across all containers will be limited + to 12kb. Defaults to /dev/termination-log. Cannot + be updated.' + type: string + terminationMessagePolicy: + description: Indicate how the termination message should + be populated. File will use the contents of terminationMessagePath + to populate the container status message on both success + and failure. FallbackToLogsOnError will use the last + chunk of container log output if the termination message + file is empty and the container exited with an error. + The log output is limited to 2048 bytes or 80 lines, + whichever is smaller. Defaults to File. Cannot be + updated. + type: string + tty: + description: Whether this container should allocate + a TTY for itself, also requires 'stdin' to be true. + Default is false. + type: boolean + volumeDevices: + description: volumeDevices is the list of block devices + to be used by the container. + items: + description: volumeDevice describes a mapping of a + raw block device within a container. + properties: + devicePath: + description: devicePath is the path inside of + the container that the device will be mapped + to. + type: string + name: + description: name must match the name of a persistentVolumeClaim + in the pod + type: string + required: + - devicePath + - name + type: object + type: array + volumeMounts: + description: Pod volumes to mount into the container's + filesystem. Subpath mounts are not allowed for ephemeral + containers. Cannot be updated. + items: + description: VolumeMount describes a mounting of a + Volume within a container. + properties: + mountPath: + description: Path within the container at which + the volume should be mounted. Must not contain + ':'. + type: string + mountPropagation: + description: mountPropagation determines how mounts + are propagated from the host to container and + the other way around. When not set, MountPropagationNone + is used. This field is beta in 1.10. + type: string + name: + description: This must match the Name of a Volume. + type: string + readOnly: + description: Mounted read-only if true, read-write + otherwise (false or unspecified). Defaults to + false. + type: boolean + subPath: + description: Path within the volume from which + the container's volume should be mounted. Defaults + to "" (volume's root). + type: string + subPathExpr: + description: Expanded path within the volume from + which the container's volume should be mounted. + Behaves similarly to SubPath but environment + variable references $(VAR_NAME) are expanded + using the container's environment. Defaults + to "" (volume's root). SubPathExpr and SubPath + are mutually exclusive. + type: string + required: + - mountPath + - name + type: object + type: array + workingDir: + description: Container's working directory. If not specified, + the container runtime's default will be used, which + might be configured in the container image. Cannot + be updated. + type: string + required: + - name + type: object + type: array + hostAliases: + description: HostAliases is an optional list of hosts and + IPs that will be injected into the pod's hosts file if specified. + This is only valid for non-hostNetwork pods. + items: + description: HostAlias holds the mapping between IP and + hostnames that will be injected as an entry in the pod's + hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + ip: + description: IP address of the host file entry. + type: string + type: object + type: array + hostIPC: + description: 'Use the host''s ipc namespace. Optional: Default + to false.' + type: boolean + hostNetwork: + description: Host networking requested for this pod. Use the + host's network namespace. If this option is set, the ports + that will be used must be specified. Default to false. + type: boolean + hostPID: + description: 'Use the host''s pid namespace. Optional: Default + to false.' + type: boolean + hostUsers: + description: 'Use the host''s user namespace. Optional: Default + to true. If set to true or not present, the pod will be + run in the host user namespace, useful for when the pod + needs a feature only available to the host user namespace, + such as loading a kernel module with CAP_SYS_MODULE. When + set to false, a new userns is created for the pod. Setting + false is useful for mitigating container breakout vulnerabilities + even allowing users to run their containers as root without + actually having root privileges on the host. This field + is alpha-level and is only honored by servers that enable + the UserNamespacesSupport feature.' + type: boolean + hostname: + description: Specifies the hostname of the Pod If not specified, + the pod's hostname will be set to a system-defined value. + type: string + imagePullSecrets: + description: 'ImagePullSecrets is an optional list of references + to secrets in the same namespace to use for pulling any + of the images used by this PodSpec. If specified, these + secrets will be passed to individual puller implementations + for them to use. More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod' + items: + 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: array + initContainers: + description: 'List of initialization containers belonging + to the pod. Init containers are executed in order prior + to containers being started. If any init container fails, + the pod is considered to have failed and is handled according + to its restartPolicy. The name for an init container or + normal container must be unique among all containers. Init + containers may not have Lifecycle actions, Readiness probes, + Liveness probes, or Startup probes. The resourceRequirements + of an init container are taken into account during scheduling + by finding the highest request/limit for each resource type, + and then using the max of of that value or the sum of the + normal containers. Limits are applied to init containers + in a similar fashion. Init containers cannot currently be + added or removed. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/' + items: + description: A single application container that you want + to run within a pod. + properties: + args: + description: 'Arguments to the entrypoint. The container + image''s CMD is used if this is not provided. Variable + references $(VAR_NAME) are expanded using the container''s + environment. If a variable cannot be resolved, the + reference in the input string will be unchanged. Double + $$ are reduced to a single $, which allows for escaping + the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce + the string literal "$(VAR_NAME)". Escaped references + will never be expanded, regardless of whether the + variable exists or not. Cannot be updated. More info: + https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + command: + description: 'Entrypoint array. Not executed within + a shell. The container image''s ENTRYPOINT is used + if this is not provided. Variable references $(VAR_NAME) + are expanded using the container''s environment. If + a variable cannot be resolved, the reference in the + input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) + syntax: i.e. "$$(VAR_NAME)" will produce the string + literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists + or not. Cannot be updated. More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell' + items: + type: string + type: array + env: + description: List of environment variables to set in + the container. Cannot be updated. + items: + description: EnvVar represents an environment variable + present in a Container. + properties: + name: + description: Name of the environment variable. + Must be a C_IDENTIFIER. + type: string + value: + description: 'Variable references $(VAR_NAME) + are expanded using the previously defined environment + variables in the container and any service environment + variables. If a variable cannot be resolved, + the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows + for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" + will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults + to "".' + type: string + valueFrom: + description: Source for the environment variable's + value. Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + 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 + optional: + description: Specify whether the ConfigMap + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + description: 'Selects a field of the pod: + supports metadata.name, metadata.namespace, + `metadata.labels['''']`, `metadata.annotations['''']`, + spec.nodeName, spec.serviceAccountName, + status.hostIP, status.podIP, status.podIPs.' + properties: + apiVersion: + description: Version of the schema the + FieldPath is written in terms of, defaults + to "v1". + type: string + fieldPath: + description: Path of the field to select + in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, limits.ephemeral-storage, + requests.cpu, requests.memory and requests.ephemeral-storage) + are currently supported.' + properties: + containerName: + description: 'Container name: required + for volumes, optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format + of the exposed resources, defaults to + "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + description: Selects a key of a secret in + the pod's namespace + properties: + key: + description: The key of the secret to + select from. Must be a valid secret + key. + type: string + 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 + optional: + description: Specify whether the Secret + or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + envFrom: + description: List of sources to populate environment + variables in the container. The keys defined within + a source must be a C_IDENTIFIER. All invalid keys + will be reported as an event when the container is + starting. When a key exists in multiple sources, the + value associated with the last source will take precedence. + Values defined by an Env with a duplicate key will + take precedence. Cannot be updated. + items: + description: EnvFromSource represents the source of + a set of ConfigMaps + properties: + configMapRef: + description: The ConfigMap to select from + 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 + optional: + description: Specify whether the ConfigMap + must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + prefix: + description: An optional identifier to prepend + to each key in the ConfigMap. Must be a C_IDENTIFIER. + type: string + secretRef: + description: The Secret to select from + 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 + optional: + description: Specify whether the Secret must + be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + type: object + type: array + image: + description: 'Container image name. More info: https://kubernetes.io/docs/concepts/containers/images + This field is optional to allow higher level config + management to default or override container images + in workload controllers like Deployments and StatefulSets.' + type: string + imagePullPolicy: + description: 'Image pull policy. One of Always, Never, + IfNotPresent. Defaults to Always if :latest tag is + specified, or IfNotPresent otherwise. Cannot be updated. + More info: https://kubernetes.io/docs/concepts/containers/images#updating-images' + type: string + lifecycle: + description: Actions that the management system should + take in response to container lifecycle events. Cannot + be updated. + properties: + postStart: + description: 'PostStart is called immediately after + a container is created. If the handler fails, + the container is terminated and restarted according + to its restart policy. Other management of the + container blocks until the hook completes. More + info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before + a container is terminated due to an API request + or management event such as liveness/startup probe + failure, preemption, resource contention, etc. + The handler is not called if the container crashes + or exits. The Pod''s termination grace period + countdown begins before the PreStop hook is executed. + Regardless of the outcome of the handler, the + container will eventually terminate within the + Pod''s termination grace period (unless delayed + by finalizers). Other management of the container + blocks until the hook completes or until the termination + grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line + to execute inside the container, the working + directory for the command is root ('/') + in the container's filesystem. The command + is simply exec'd, it is not run inside + a shell, so traditional shell instructions + ('|', etc) won't work. To use a shell, + you need to explicitly call out to that + shell. Exit status of 0 is treated as + live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set + "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the + request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP + server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting + to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: Deprecated. TCPSocket is NOT supported + as a LifecycleHandler and kept for the backward + compatibility. There are no validation of + this field and lifecycle hooks will fail in + runtime when tcp handler is specified. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port + to access on the container. Number must + be in the range 1 to 65535. Name must + be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object + livenessProbe: + description: 'Periodic probe of container liveness. + Container will be restarted if the probe fails. Cannot + be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + name: + description: Name of the container specified as a DNS_LABEL. + Each container in a pod must have a unique name (DNS_LABEL). + Cannot be updated. + type: string + ports: + description: List of ports to expose from the container. + Not specifying a port here DOES NOT prevent that port + from being exposed. Any port which is listening on + the default "0.0.0.0" address inside a container will + be accessible from the network. Modifying this array + with strategic merge patch may corrupt the data. For + more information See https://github.com/kubernetes/kubernetes/issues/108255. + Cannot be updated. + items: + description: ContainerPort represents a network port + in a single container. + properties: + containerPort: + description: Number of port to expose on the pod's + IP address. This must be a valid port number, + 0 < x < 65536. + format: int32 + type: integer + hostIP: + description: What host IP to bind the external + port to. + type: string + hostPort: + description: Number of port to expose on the host. + If specified, this must be a valid port number, + 0 < x < 65536. If HostNetwork is specified, + this must match ContainerPort. Most containers + do not need this. + format: int32 + type: integer + name: + description: If specified, this must be an IANA_SVC_NAME + and unique within the pod. Each named port in + a pod must have a unique name. Name for the + port that can be referred to by services. + type: string + protocol: + default: TCP + description: Protocol for port. Must be UDP, TCP, + or SCTP. Defaults to "TCP". + type: string + required: + - containerPort + type: object + type: array + x-kubernetes-list-map-keys: + - containerPort + - protocol + x-kubernetes-list-type: map + readinessProbe: + description: 'Periodic probe of container service readiness. + Container will be removed from service endpoints if + the probe fails. Cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + resources: + description: 'Compute Resources required by this container. + Cannot be updated. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + 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." + 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. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + securityContext: + description: 'SecurityContext defines the security options + the container should be run with. If set, the fields + of SecurityContext override the equivalent fields + of PodSecurityContext. More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/' + properties: + allowPrivilegeEscalation: + description: 'AllowPrivilegeEscalation controls + whether a process can gain more privileges than + its parent process. This bool directly controls + if the no_new_privs flag will be set on the container + process. AllowPrivilegeEscalation is true always + when the container is: 1) run as Privileged 2) + has CAP_SYS_ADMIN Note that this field cannot + be set when spec.os.name is windows.' + type: boolean + capabilities: + description: The capabilities to add/drop when running + containers. Defaults to the default set of capabilities + granted by the container runtime. Note that this + field cannot be set when spec.os.name is windows. + properties: + add: + description: Added capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + drop: + description: Removed capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + type: object + privileged: + description: Run container in privileged mode. Processes + in privileged containers are essentially equivalent + to root on the host. Defaults to false. Note that + this field cannot be set when spec.os.name is + windows. + type: boolean + procMount: + description: procMount denotes the type of proc + mount to use for the containers. The default is + DefaultProcMount which uses the container runtime + defaults for readonly paths and masked paths. + This requires the ProcMountType feature flag to + be enabled. Note that this field cannot be set + when spec.os.name is windows. + type: string + readOnlyRootFilesystem: + description: Whether this container has a read-only + root filesystem. Default is false. Note that this + field cannot be set when spec.os.name is windows. + type: boolean + runAsGroup: + description: The GID to run the entrypoint of the + container process. Uses runtime default if unset. + May also be set in PodSecurityContext. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + format: int64 + type: integer + runAsNonRoot: + description: Indicates that the container must run + as a non-root user. If true, the Kubelet will + validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start + the container if it does. If unset or false, no + such validation will be performed. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. + type: boolean + runAsUser: + description: The UID to run the entrypoint of the + container process. Defaults to user specified + in image metadata if unspecified. May also be + set in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in + SecurityContext takes precedence. Note that this + field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: The SELinux context to be applied to + the container. If unspecified, the container runtime + will allocate a random SELinux context for each + container. May also be set in PodSecurityContext. If + set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is windows. + properties: + level: + description: Level is SELinux level label that + applies to the container. + type: string + role: + description: Role is a SELinux role label that + applies to the container. + type: string + type: + description: Type is a SELinux type label that + applies to the container. + type: string + user: + description: User is a SELinux user label that + applies to the container. + type: string + type: object + seccompProfile: + description: The seccomp options to use by this + container. If seccomp options are provided at + both the pod & container level, the container + options override the pod options. Note that this + field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: localhostProfile indicates a profile + defined in a file on the node should be used. + The profile must be preconfigured on the node + to work. Must be a descending path, relative + to the kubelet's configured seccomp profile + location. Must only be set if type is "Localhost". + type: string + type: + description: "type indicates which kind of seccomp + profile will be applied. Valid options are: + \n Localhost - a profile defined in a file + on the node should be used. RuntimeDefault + - the container runtime default profile should + be used. Unconfined - no profile should be + applied." + type: string + required: + - type + type: object + windowsOptions: + description: The Windows specific settings applied + to all containers. If unspecified, the options + from the PodSecurityContext will be used. If set + in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name + is linux. + properties: + gmsaCredentialSpec: + description: GMSACredentialSpec is where the + GMSA admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) + inlines the contents of the GMSA credential + spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name + of the GMSA credential spec to use. + type: string + hostProcess: + description: HostProcess determines if a container + should be run as a 'Host Process' container. + This field is alpha-level and will only be + honored by components that enable the WindowsHostProcessContainers + feature flag. Setting this field without the + feature flag will result in errors when validating + the Pod. All of a Pod's containers must have + the same effective HostProcess value (it is + not allowed to have a mix of HostProcess containers + and non-HostProcess containers). In addition, + if HostProcess is true then HostNetwork must + also be set to true. + type: boolean + runAsUserName: + description: The UserName in Windows to run + the entrypoint of the container process. Defaults + to the user specified in image metadata if + unspecified. May also be set in PodSecurityContext. + If set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes + precedence. + type: string + type: object + type: object + startupProbe: + description: 'StartupProbe indicates that the Pod has + successfully initialized. If specified, no other probes + are executed until this completes successfully. If + this probe fails, the Pod will be restarted, just + as if the livenessProbe failed. This can be used to + provide different probe parameters at the beginning + of a Pod''s lifecycle, when it might take a long time + to load data or warm a cache, than during steady-state + operation. This cannot be updated. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + properties: + exec: + description: Exec specifies the action to take. + properties: + command: + description: Command is the command line to + execute inside the container, the working + directory for the command is root ('/') in + the container's filesystem. The command is + simply exec'd, it is not run inside a shell, + so traditional shell instructions ('|', etc) + won't work. To use a shell, you need to explicitly + call out to that shell. Exit status of 0 is + treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + failureThreshold: + description: Minimum consecutive failures for the + probe to be considered failed after having succeeded. + Defaults to 3. Minimum value is 1. + format: int32 + type: integer + grpc: + description: GRPC specifies an action involving + a GRPC port. This is a beta field and requires + enabling GRPCContainerProbe feature gate. + properties: + port: + description: Port number of the gRPC service. + Number must be in the range 1 to 65535. + format: int32 + type: integer + service: + description: "Service is the name of the service + to place in the gRPC HealthCheckRequest (see + https://github.com/grpc/grpc/blob/master/doc/health-checking.md). + \n If this is not specified, the default behavior + is defined by gRPC." + type: string + required: + - port + type: object + httpGet: + description: HTTPGet specifies the http request + to perform. + properties: + host: + description: Host name to connect to, defaults + to the pod IP. You probably want to set "Host" + in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. + HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom + header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to + the host. Defaults to HTTP. + type: string + required: + - port + type: object + initialDelaySeconds: + description: 'Number of seconds after the container + has started before liveness probes are initiated. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + periodSeconds: + description: How often (in seconds) to perform the + probe. Default to 10 seconds. Minimum value is + 1. + format: int32 + type: integer + successThreshold: + description: Minimum consecutive successes for the + probe to be considered successful after having + failed. Defaults to 1. Must be 1 for liveness + and startup. Minimum value is 1. + format: int32 + type: integer + tcpSocket: + description: TCPSocket specifies an action involving + a TCP port. + properties: + host: + description: 'Optional: Host name to connect + to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access + on the container. Number must be in the range + 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod + needs to terminate gracefully upon probe failure. + The grace period is the duration in seconds after + the processes running in the pod are sent a termination + signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer + than the expected cleanup time for your process. + If this value is nil, the pod's terminationGracePeriodSeconds + will be used. Otherwise, this value overrides + the value provided by the pod spec. Value must + be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity + to shut down). This is a beta field and requires + enabling ProbeTerminationGracePeriod feature gate. + Minimum value is 1. spec.terminationGracePeriodSeconds + is used if unset. + format: int64 + type: integer + timeoutSeconds: + description: 'Number of seconds after which the + probe times out. Defaults to 1 second. Minimum + value is 1. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + format: int32 + type: integer + type: object + stdin: + description: Whether this container should allocate + a buffer for stdin in the container runtime. If this + is not set, reads from stdin in the container will + always result in EOF. Default is false. + type: boolean + stdinOnce: + description: Whether the container runtime should close + the stdin channel after it has been opened by a single + attach. When stdin is true the stdin stream will remain + open across multiple attach sessions. If stdinOnce + is set to true, stdin is opened on container start, + is empty until the first client attaches to stdin, + and then remains open and accepts data until the client + disconnects, at which time stdin is closed and remains + closed until the container is restarted. If this flag + is false, a container processes that reads from stdin + will never receive an EOF. Default is false + type: boolean + terminationMessagePath: + description: 'Optional: Path at which the file to which + the container''s termination message will be written + is mounted into the container''s filesystem. Message + written is intended to be brief final status, such + as an assertion failure message. Will be truncated + by the node if greater than 4096 bytes. The total + message length across all containers will be limited + to 12kb. Defaults to /dev/termination-log. Cannot + be updated.' + type: string + terminationMessagePolicy: + description: Indicate how the termination message should + be populated. File will use the contents of terminationMessagePath + to populate the container status message on both success + and failure. FallbackToLogsOnError will use the last + chunk of container log output if the termination message + file is empty and the container exited with an error. + The log output is limited to 2048 bytes or 80 lines, + whichever is smaller. Defaults to File. Cannot be + updated. + type: string + tty: + description: Whether this container should allocate + a TTY for itself, also requires 'stdin' to be true. + Default is false. + type: boolean + volumeDevices: + description: volumeDevices is the list of block devices + to be used by the container. + items: + description: volumeDevice describes a mapping of a + raw block device within a container. + properties: + devicePath: + description: devicePath is the path inside of + the container that the device will be mapped + to. + type: string + name: + description: name must match the name of a persistentVolumeClaim + in the pod + type: string + required: + - devicePath + - name + type: object + type: array + volumeMounts: + description: Pod volumes to mount into the container's + filesystem. Cannot be updated. + items: + description: VolumeMount describes a mounting of a + Volume within a container. + properties: + mountPath: + description: Path within the container at which + the volume should be mounted. Must not contain + ':'. + type: string + mountPropagation: + description: mountPropagation determines how mounts + are propagated from the host to container and + the other way around. When not set, MountPropagationNone + is used. This field is beta in 1.10. + type: string + name: + description: This must match the Name of a Volume. + type: string + readOnly: + description: Mounted read-only if true, read-write + otherwise (false or unspecified). Defaults to + false. + type: boolean + subPath: + description: Path within the volume from which + the container's volume should be mounted. Defaults + to "" (volume's root). + type: string + subPathExpr: + description: Expanded path within the volume from + which the container's volume should be mounted. + Behaves similarly to SubPath but environment + variable references $(VAR_NAME) are expanded + using the container's environment. Defaults + to "" (volume's root). SubPathExpr and SubPath + are mutually exclusive. + type: string + required: + - mountPath + - name + type: object + type: array + workingDir: + description: Container's working directory. If not specified, + the container runtime's default will be used, which + might be configured in the container image. Cannot + be updated. + type: string + required: + - name + type: object + type: array + nodeName: + description: NodeName is a request to schedule this pod onto + a specific node. If it is non-empty, the scheduler simply + schedules this pod onto that node, assuming that it fits + resource requirements. + type: string + nodeSelector: + additionalProperties: + type: string + description: 'NodeSelector is a selector which must be true + for the pod to fit on a node. Selector which must match + a node''s labels for the pod to be scheduled on that node. + More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/' + type: object + x-kubernetes-map-type: atomic + os: + description: "Specifies the OS of the containers in the pod. + Some pod and container fields are restricted if this is + set. \n If the OS field is set to linux, the following fields + must be unset: -securityContext.windowsOptions \n If the + OS field is set to windows, following fields must be unset: + - spec.hostPID - spec.hostIPC - spec.hostUsers - spec.securityContext.seLinuxOptions + - spec.securityContext.seccompProfile - spec.securityContext.fsGroup + - spec.securityContext.fsGroupChangePolicy - spec.securityContext.sysctls + - spec.shareProcessNamespace - spec.securityContext.runAsUser + - spec.securityContext.runAsGroup - spec.securityContext.supplementalGroups + - spec.containers[*].securityContext.seLinuxOptions - spec.containers[*].securityContext.seccompProfile + - spec.containers[*].securityContext.capabilities - spec.containers[*].securityContext.readOnlyRootFilesystem + - spec.containers[*].securityContext.privileged - spec.containers[*].securityContext.allowPrivilegeEscalation + - spec.containers[*].securityContext.procMount - spec.containers[*].securityContext.runAsUser + - spec.containers[*].securityContext.runAsGroup" + properties: + name: + description: 'Name is the name of the operating system. + The currently supported values are linux and windows. + Additional value may be defined in future and can be + one of: https://github.com/opencontainers/runtime-spec/blob/master/config.md#platform-specific-configuration + Clients should expect to handle additional values and + treat unrecognized values in this field as os: null' + type: string + required: + - name + type: object + overhead: + 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: 'Overhead represents the resource overhead associated + with running a pod for a given RuntimeClass. This field + will be autopopulated at admission time by the RuntimeClass + admission controller. If the RuntimeClass admission controller + is enabled, overhead must not be set in Pod create requests. + The RuntimeClass admission controller will reject Pod create + requests which have the overhead already set. If RuntimeClass + is configured and selected in the PodSpec, Overhead will + be set to the value defined in the corresponding RuntimeClass, + otherwise it will remain unset and treated as zero. More + info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md' + type: object + preemptionPolicy: + description: PreemptionPolicy is the Policy for preempting + pods with lower priority. One of Never, PreemptLowerPriority. + Defaults to PreemptLowerPriority if unset. + type: string + priority: + description: The priority value. Various system components + use this field to find the priority of the pod. When Priority + Admission Controller is enabled, it prevents users from + setting this field. The admission controller populates this + field from PriorityClassName. The higher the value, the + higher the priority. + format: int32 + type: integer + priorityClassName: + description: If specified, indicates the pod's priority. "system-node-critical" + and "system-cluster-critical" are two special keywords which + indicate the highest priorities with the former being the + highest priority. Any other name must be defined by creating + a PriorityClass object with that name. If not specified, + the pod priority will be default or zero if there is no + default. + type: string + readinessGates: + description: 'If specified, all readiness gates will be evaluated + for pod readiness. A pod is ready when all its containers + are ready AND all conditions specified in the readiness + gates have status equal to "True" More info: https://git.k8s.io/enhancements/keps/sig-network/580-pod-readiness-gates' + items: + description: PodReadinessGate contains the reference to + a pod condition + properties: + conditionType: + description: ConditionType refers to a condition in + the pod's condition list with matching type. + type: string + required: + - conditionType + type: object + type: array + resourceClaims: + description: "ResourceClaims defines which ResourceClaims + must be allocated and reserved before the Pod is allowed + to start. The resources will be made available to those + containers which consume them by name. \n This is an alpha + field and requires enabling the DynamicResourceAllocation + feature gate. \n This field is immutable." + items: + description: PodResourceClaim references exactly one ResourceClaim + through a ClaimSource. It adds a name to it that uniquely + identifies the ResourceClaim inside the Pod. Containers + that need access to the ResourceClaim reference it with + this name. + properties: + name: + description: Name uniquely identifies this resource + claim inside the pod. This must be a DNS_LABEL. + type: string + source: + description: Source describes where to find the ResourceClaim. + properties: + resourceClaimName: + description: ResourceClaimName is the name of a + ResourceClaim object in the same namespace as + this pod. + type: string + resourceClaimTemplateName: + description: "ResourceClaimTemplateName is the name + of a ResourceClaimTemplate object in the same + namespace as this pod. \n The template will be + used to create a new ResourceClaim, which will + be bound to this pod. When this pod is deleted, + the ResourceClaim will also be deleted. The name + of the ResourceClaim will be -, where is the PodResourceClaim.Name. + Pod validation will reject the pod if the concatenated + name is not valid for a ResourceClaim (e.g. too + long). \n An existing ResourceClaim with that + name that is not owned by the pod will not be + used for the pod to avoid using an unrelated resource + by mistake. Scheduling and pod startup are then + blocked until the unrelated ResourceClaim is removed. + \n This field is immutable and no changes will + be made to the corresponding ResourceClaim by + the control plane after creating the ResourceClaim." + type: string + type: object + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + restartPolicy: + description: 'Restart policy for all containers within the + pod. One of Always, OnFailure, Never. Default to Always. + More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy' + type: string + runtimeClassName: + description: 'RuntimeClassName refers to a RuntimeClass object + in the node.k8s.io group, which should be used to run this + pod. If no RuntimeClass resource matches the named class, + the pod will not be run. If unset or empty, the "legacy" + RuntimeClass will be used, which is an implicit class with + an empty definition that uses the default runtime handler. + More info: https://git.k8s.io/enhancements/keps/sig-node/585-runtime-class' + type: string + schedulerName: + description: If specified, the pod will be dispatched by specified + scheduler. If not specified, the pod will be dispatched + by default scheduler. + type: string + schedulingGates: + description: "SchedulingGates is an opaque list of values + that if specified will block scheduling the pod. More info: + \ https://git.k8s.io/enhancements/keps/sig-scheduling/3521-pod-scheduling-readiness. + \n This is an alpha-level feature enabled by PodSchedulingReadiness + feature gate." + items: + description: PodSchedulingGate is associated to a Pod to + guard its scheduling. + properties: + name: + description: Name of the scheduling gate. Each scheduling + gate must have a unique name field. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + securityContext: + description: 'SecurityContext holds pod-level security attributes + and common container settings. Optional: Defaults to empty. See + type description for default values of each field.' + properties: + fsGroup: + description: "A special supplemental group that applies + to all containers in a pod. Some volume types allow + the Kubelet to change the ownership of that volume to + be owned by the pod: \n 1. The owning GID will be the + FSGroup 2. The setgid bit is set (new files created + in the volume will be owned by FSGroup) 3. The permission + bits are OR'd with rw-rw---- \n If unset, the Kubelet + will not modify the ownership and permissions of any + volume. Note that this field cannot be set when spec.os.name + is windows." + format: int64 + type: integer + fsGroupChangePolicy: + description: 'fsGroupChangePolicy defines behavior of + changing ownership and permission of the volume before + being exposed inside Pod. This field will only apply + to volume types which support fsGroup based ownership(and + permissions). It will have no effect on ephemeral volume + types such as: secret, configmaps and emptydir. Valid + values are "OnRootMismatch" and "Always". If not specified, + "Always" is used. Note that this field cannot be set + when spec.os.name is windows.' + type: string + runAsGroup: + description: The GID to run the entrypoint of the container + process. Uses runtime default if unset. May also be + set in SecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in SecurityContext + takes precedence for that container. Note that this + field cannot be set when spec.os.name is windows. + format: int64 + type: integer + runAsNonRoot: + description: Indicates that the container must run as + a non-root user. If true, the Kubelet will validate + the image at runtime to ensure that it does not run + as UID 0 (root) and fail to start the container if it + does. If unset or false, no such validation will be + performed. May also be set in SecurityContext. If set + in both SecurityContext and PodSecurityContext, the + value specified in SecurityContext takes precedence. + type: boolean + runAsUser: + description: The UID to run the entrypoint of the container + process. Defaults to user specified in image metadata + if unspecified. May also be set in SecurityContext. If + set in both SecurityContext and PodSecurityContext, + the value specified in SecurityContext takes precedence + for that container. Note that this field cannot be set + when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: The SELinux context to be applied to all + containers. If unspecified, the container runtime will + allocate a random SELinux context for each container. May + also be set in SecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in SecurityContext + takes precedence for that container. Note that this + field cannot be set when spec.os.name is windows. + properties: + level: + description: Level is SELinux level label that applies + to the container. + type: string + role: + description: Role is a SELinux role label that applies + to the container. + type: string + type: + description: Type is a SELinux type label that applies + to the container. + type: string + user: + description: User is a SELinux user label that applies + to the container. + type: string + type: object + seccompProfile: + description: The seccomp options to use by the containers + in this pod. Note that this field cannot be set when + spec.os.name is windows. + properties: + localhostProfile: + description: localhostProfile indicates a profile + defined in a file on the node should be used. The + profile must be preconfigured on the node to work. + Must be a descending path, relative to the kubelet's + configured seccomp profile location. Must only be + set if type is "Localhost". + type: string + type: + description: "type indicates which kind of seccomp + profile will be applied. Valid options are: \n Localhost + - a profile defined in a file on the node should + be used. RuntimeDefault - the container runtime + default profile should be used. Unconfined - no + profile should be applied." + type: string + required: + - type + type: object + supplementalGroups: + description: A list of groups applied to the first process + run in each container, in addition to the container's + primary GID, the fsGroup (if specified), and group memberships + defined in the container image for the uid of the container + process. If unspecified, no additional groups are added + to any container. Note that group memberships defined + in the container image for the uid of the container + process are still effective, even if they are not included + in this list. Note that this field cannot be set when + spec.os.name is windows. + items: + format: int64 + type: integer + type: array + sysctls: + description: Sysctls hold a list of namespaced sysctls + used for the pod. Pods with unsupported sysctls (by + the container runtime) might fail to launch. Note that + this field cannot be set when spec.os.name is windows. + items: + description: Sysctl defines a kernel parameter to be + set + properties: + name: + description: Name of a property to set + type: string + value: + description: Value of a property to set + type: string + required: + - name + - value + type: object + type: array + windowsOptions: + description: The Windows specific settings applied to + all containers. If unspecified, the options within a + container's SecurityContext will be used. If set in + both SecurityContext and PodSecurityContext, the value + specified in SecurityContext takes precedence. Note + that this field cannot be set when spec.os.name is linux. + properties: + gmsaCredentialSpec: + description: GMSACredentialSpec is where the GMSA + admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) + inlines the contents of the GMSA credential spec + named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name of + the GMSA credential spec to use. + type: string + hostProcess: + description: HostProcess determines if a container + should be run as a 'Host Process' container. This + field is alpha-level and will only be honored by + components that enable the WindowsHostProcessContainers + feature flag. Setting this field without the feature + flag will result in errors when validating the Pod. + All of a Pod's containers must have the same effective + HostProcess value (it is not allowed to have a mix + of HostProcess containers and non-HostProcess containers). In + addition, if HostProcess is true then HostNetwork + must also be set to true. + type: boolean + runAsUserName: + description: The UserName in Windows to run the entrypoint + of the container process. Defaults to the user specified + in image metadata if unspecified. May also be set + in PodSecurityContext. If set in both SecurityContext + and PodSecurityContext, the value specified in SecurityContext + takes precedence. + type: string + type: object + type: object + serviceAccount: + description: 'DeprecatedServiceAccount is a depreciated alias + for ServiceAccountName. Deprecated: Use serviceAccountName + instead.' + type: string + serviceAccountName: + description: 'ServiceAccountName is the name of the ServiceAccount + to use to run this pod. More info: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/' + type: string + setHostnameAsFQDN: + description: If true the pod's hostname will be configured + as the pod's FQDN, rather than the leaf name (the default). + In Linux containers, this means setting the FQDN in the + hostname field of the kernel (the nodename field of struct + utsname). In Windows containers, this means setting the + registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters + to FQDN. If a pod does not have FQDN, this has no effect. + Default to false. + type: boolean + shareProcessNamespace: + description: 'Share a single process namespace between all + of the containers in a pod. When this is set containers + will be able to view and signal processes from other containers + in the same pod, and the first process in each container + will not be assigned PID 1. HostPID and ShareProcessNamespace + cannot both be set. Optional: Default to false.' + type: boolean + subdomain: + description: If specified, the fully qualified Pod hostname + will be "...svc.". If not specified, the pod will not have a domainname + at all. + type: string + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod needs to + terminate gracefully. May be decreased in delete request. + Value must be non-negative integer. The value zero indicates + stop immediately via the kill signal (no opportunity to + shut down). If this value is nil, the default grace period + will be used instead. The grace period is the duration in + seconds after the processes running in the pod are sent + a termination signal and the time when the processes are + forcibly halted with a kill signal. Set this value longer + than the expected cleanup time for your process. Defaults + to 30 seconds. + format: int64 + type: integer + tolerations: + description: If specified, the pod's tolerations. + items: + description: The pod this Toleration is attached to tolerates + any taint that matches the triple using + the matching operator . + properties: + effect: + description: Effect indicates the taint effect to match. + Empty means match all taint effects. When specified, + allowed values are NoSchedule, PreferNoSchedule and + NoExecute. + type: string + key: + description: Key is the taint key that the toleration + applies to. Empty means match all taint keys. If the + key is empty, operator must be Exists; this combination + means to match all values and all keys. + type: string + operator: + description: Operator represents a key's relationship + to the value. Valid operators are Exists and Equal. + Defaults to Equal. Exists is equivalent to wildcard + for value, so that a pod can tolerate all taints of + a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the period + of time the toleration (which must be of effect NoExecute, + otherwise this field is ignored) tolerates the taint. + By default, it is not set, which means tolerate the + taint forever (do not evict). Zero and negative values + will be treated as 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration + matches to. If the operator is Exists, the value should + be empty, otherwise just a regular string. + type: string + type: object + type: array + topologySpreadConstraints: + description: TopologySpreadConstraints describes how a group + of pods ought to spread across topology domains. Scheduler + will schedule pods in a way which abides by the constraints. + All topologySpreadConstraints are ANDed. + items: + description: TopologySpreadConstraint specifies how to spread + matching pods among the given topology. + properties: + labelSelector: + description: LabelSelector is used to find matching + pods. Pods that match this label selector are counted + to determine the number of pods in their corresponding + topology domain. + 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 + matchLabelKeys: + description: MatchLabelKeys is a set of pod label keys + to select the pods over which spreading will be calculated. + The keys are used to lookup values from the incoming + pod labels, those key-value labels are ANDed with + labelSelector to select the group of existing pods + over which spreading will be calculated for the incoming + pod. Keys that don't exist in the incoming pod labels + will be ignored. A null or empty list means only match + against labelSelector. + items: + type: string + type: array + x-kubernetes-list-type: atomic + maxSkew: + description: 'MaxSkew describes the degree to which + pods may be unevenly distributed. When `whenUnsatisfiable=DoNotSchedule`, + it is the maximum permitted difference between the + number of matching pods in the target topology and + the global minimum. The global minimum is the minimum + number of matching pods in an eligible domain or zero + if the number of eligible domains is less than MinDomains. + For example, in a 3-zone cluster, MaxSkew is set to + 1, and pods with the same labelSelector spread as + 2/2/1: In this case, the global minimum is 1. | zone1 + | zone2 | zone3 | | P P | P P | P | - if MaxSkew + is 1, incoming pod can only be scheduled to zone3 + to become 2/2/2; scheduling it onto zone1(zone2) would + make the ActualSkew(3-1) on zone1(zone2) violate MaxSkew(1). + - if MaxSkew is 2, incoming pod can be scheduled onto + any zone. When `whenUnsatisfiable=ScheduleAnyway`, + it is used to give higher precedence to topologies + that satisfy it. It''s a required field. Default value + is 1 and 0 is not allowed.' + format: int32 + type: integer + minDomains: + description: "MinDomains indicates a minimum number + of eligible domains. When the number of eligible domains + with matching topology keys is less than minDomains, + Pod Topology Spread treats \"global minimum\" as 0, + and then the calculation of Skew is performed. And + when the number of eligible domains with matching + topology keys equals or greater than minDomains, this + value has no effect on scheduling. As a result, when + the number of eligible domains is less than minDomains, + scheduler won't schedule more than maxSkew Pods to + those domains. If value is nil, the constraint behaves + as if MinDomains is equal to 1. Valid values are integers + greater than 0. When value is not nil, WhenUnsatisfiable + must be DoNotSchedule. \n For example, in a 3-zone + cluster, MaxSkew is set to 2, MinDomains is set to + 5 and pods with the same labelSelector spread as 2/2/2: + | zone1 | zone2 | zone3 | | P P | P P | P P | + The number of domains is less than 5(MinDomains), + so \"global minimum\" is treated as 0. In this situation, + new pod with the same labelSelector cannot be scheduled, + because computed skew will be 3(3 - 0) if new Pod + is scheduled to any of the three zones, it will violate + MaxSkew. \n This is a beta field and requires the + MinDomainsInPodTopologySpread feature gate to be enabled + (enabled by default)." + format: int32 + type: integer + nodeAffinityPolicy: + description: "NodeAffinityPolicy indicates how we will + treat Pod's nodeAffinity/nodeSelector when calculating + pod topology spread skew. Options are: - Honor: only + nodes matching nodeAffinity/nodeSelector are included + in the calculations. - Ignore: nodeAffinity/nodeSelector + are ignored. All nodes are included in the calculations. + \n If this value is nil, the behavior is equivalent + to the Honor policy. This is a beta-level feature + default enabled by the NodeInclusionPolicyInPodTopologySpread + feature flag." + type: string + nodeTaintsPolicy: + description: "NodeTaintsPolicy indicates how we will + treat node taints when calculating pod topology spread + skew. Options are: - Honor: nodes without taints, + along with tainted nodes for which the incoming pod + has a toleration, are included. - Ignore: node taints + are ignored. All nodes are included. \n If this value + is nil, the behavior is equivalent to the Ignore policy. + This is a beta-level feature default enabled by the + NodeInclusionPolicyInPodTopologySpread feature flag." + type: string + topologyKey: + description: TopologyKey is the key of node labels. + Nodes that have a label with this key and identical + values are considered to be in the same topology. + We consider each as a "bucket", and try + to put balanced number of pods into each bucket. We + define a domain as a particular instance of a topology. + Also, we define an eligible domain as a domain whose + nodes meet the requirements of nodeAffinityPolicy + and nodeTaintsPolicy. e.g. If TopologyKey is "kubernetes.io/hostname", + each Node is a domain of that topology. And, if TopologyKey + is "topology.kubernetes.io/zone", each zone is a domain + of that topology. It's a required field. + type: string + whenUnsatisfiable: + description: 'WhenUnsatisfiable indicates how to deal + with a pod if it doesn''t satisfy the spread constraint. + - DoNotSchedule (default) tells the scheduler not + to schedule it. - ScheduleAnyway tells the scheduler + to schedule the pod in any location, but giving higher + precedence to topologies that would help reduce the + skew. A constraint is considered "Unsatisfiable" for + an incoming pod if and only if every possible node + assignment for that pod would violate "MaxSkew" on + some topology. For example, in a 3-zone cluster, MaxSkew + is set to 1, and pods with the same labelSelector + spread as 3/1/1: | zone1 | zone2 | zone3 | | P P P + | P | P | If WhenUnsatisfiable is set to DoNotSchedule, + incoming pod can only be scheduled to zone2(zone3) + to become 3/2/1(3/1/2) as ActualSkew(2-1) on zone2(zone3) + satisfies MaxSkew(1). In other words, the cluster + can still be imbalanced, but scheduler won''t make + it *more* imbalanced. It''s a required field.' + type: string + required: + - maxSkew + - topologyKey + - whenUnsatisfiable + type: object + type: array + x-kubernetes-list-map-keys: + - topologyKey + - whenUnsatisfiable + x-kubernetes-list-type: map + volumes: + description: 'List of volumes that can be mounted by containers + belonging to the pod. More info: https://kubernetes.io/docs/concepts/storage/volumes' + items: + description: Volume represents a named volume in a pod that + may be accessed by any container in the pod. + properties: + awsElasticBlockStore: + description: 'awsElasticBlockStore represents an AWS + Disk resource that is attached to a kubelet''s host + machine and then exposed to the pod. More info: https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore' + properties: + fsType: + description: 'fsType is the filesystem type of the + volume that you want to mount. Tip: Ensure that + the filesystem type is supported by the host operating + system. Examples: "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. More info: + https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore + TODO: how do we prevent errors in the filesystem + from compromising the machine' + type: string + partition: + description: 'partition is the partition in the + volume that you want to mount. If omitted, the + default is to mount by volume name. Examples: + For volume /dev/sda1, you specify the partition + as "1". Similarly, the volume partition for /dev/sda + is "0" (or you can leave the property empty).' + format: int32 + type: integer + readOnly: + description: 'readOnly value true will force the + readOnly setting in VolumeMounts. More info: https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore' + type: boolean + volumeID: + description: 'volumeID is unique ID of the persistent + disk resource in AWS (Amazon EBS volume). More + info: https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore' + type: string + required: + - volumeID + type: object + azureDisk: + description: azureDisk represents an Azure Data Disk + mount on the host and bind mount to the pod. + properties: + cachingMode: + description: 'cachingMode is the Host Caching mode: + None, Read Only, Read Write.' + type: string + diskName: + description: diskName is the Name of the data disk + in the blob storage + type: string + diskURI: + description: diskURI is the URI of data disk in + the blob storage + type: string + fsType: + description: fsType is Filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. + type: string + kind: + description: 'kind expected values are Shared: multiple + blob disks per storage account Dedicated: single + blob disk per storage account Managed: azure + managed data disk (only in managed availability + set). defaults to shared' + type: string + readOnly: + description: readOnly Defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + required: + - diskName + - diskURI + type: object + azureFile: + description: azureFile represents an Azure File Service + mount on the host and bind mount to the pod. + properties: + readOnly: + description: readOnly defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + secretName: + description: secretName is the name of secret that + contains Azure Storage Account Name and Key + type: string + shareName: + description: shareName is the azure share Name + type: string + required: + - secretName + - shareName + type: object + cephfs: + description: cephFS represents a Ceph FS mount on the + host that shares a pod's lifetime + properties: + monitors: + description: 'monitors is Required: Monitors is + a collection of Ceph monitors More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + items: + type: string + type: array + path: + description: 'path is Optional: Used as the mounted + root, rather than the full Ceph tree, default + is /' + type: string + readOnly: + description: 'readOnly is Optional: Defaults to + false (read/write). ReadOnly here will force the + ReadOnly setting in VolumeMounts. More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + type: boolean + secretFile: + description: 'secretFile is Optional: SecretFile + is the path to key ring for User, default is /etc/ceph/user.secret + More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + type: string + secretRef: + description: 'secretRef is Optional: SecretRef is + reference to the authentication secret for User, + default is empty. More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + 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 + user: + description: 'user is optional: User is the rados + user name, default is admin More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it' + type: string + required: + - monitors + type: object + cinder: + description: 'cinder represents a cinder volume attached + and mounted on kubelets host machine. More info: https://examples.k8s.io/mysql-cinder-pd/README.md' + properties: + fsType: + description: 'fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Examples: "ext4", "xfs", "ntfs". + Implicitly inferred to be "ext4" if unspecified. + More info: https://examples.k8s.io/mysql-cinder-pd/README.md' + type: string + readOnly: + description: 'readOnly defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. More info: https://examples.k8s.io/mysql-cinder-pd/README.md' + type: boolean + secretRef: + description: 'secretRef is optional: points to a + secret object containing parameters used to connect + to OpenStack.' + 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 + volumeID: + description: 'volumeID used to identify the volume + in cinder. More info: https://examples.k8s.io/mysql-cinder-pd/README.md' + type: string + required: + - volumeID + type: object + configMap: + description: configMap represents a configMap that should + populate this volume + properties: + defaultMode: + description: 'defaultMode is optional: mode bits + used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or + a decimal value between 0 and 511. YAML accepts + both octal and decimal values, JSON requires decimal + values for mode bits. Defaults to 0644. Directories + within the path are not affected by this setting. + This might be in conflict with other options that + affect the file mode, like fsGroup, and the result + can be other mode bits set.' + format: int32 + type: integer + items: + description: items if unspecified, each key-value + pair in the Data field of the referenced ConfigMap + will be projected into the volume as a file whose + name is the key and content is the value. If specified, + the listed keys will be projected into the specified + paths, and unlisted keys will not be present. + If a key is specified which is not present in + the ConfigMap, the volume setup will error unless + it is marked optional. Paths must be relative + and may not contain the '..' path or start with + '..'. + items: + description: Maps a string key to a path within + a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: 'mode is Optional: mode bits + used to set permissions on this file. Must + be an octal value between 0000 and 0777 + or a decimal value between 0 and 511. YAML + accepts both octal and decimal values, JSON + requires decimal values for mode bits. If + not specified, the volume defaultMode will + be used. This might be in conflict with + other options that affect the file mode, + like fsGroup, and the result can be other + mode bits set.' + format: int32 + type: integer + path: + description: path is the relative path of + the file to map the key to. May not be an + absolute path. May not contain the path + element '..'. May not start with the string + '..'. + type: string + required: + - key + - path + type: object + type: array + 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 + optional: + description: optional specify whether the ConfigMap + or its keys must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + csi: + description: csi (Container Storage Interface) represents + ephemeral storage that is handled by certain external + CSI drivers (Beta feature). + properties: + driver: + description: driver is the name of the CSI driver + that handles this volume. Consult with your admin + for the correct name as registered in the cluster. + type: string + fsType: + description: fsType to mount. Ex. "ext4", "xfs", + "ntfs". If not provided, the empty value is passed + to the associated CSI driver which will determine + the default filesystem to apply. + type: string + nodePublishSecretRef: + description: nodePublishSecretRef is a reference + to the secret object containing sensitive information + to pass to the CSI driver to complete the CSI + NodePublishVolume and NodeUnpublishVolume calls. + This field is optional, and may be empty if no + secret is required. If the secret object contains + more than one secret, all secret references are + passed. + 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 + readOnly: + description: readOnly specifies a read-only configuration + for the volume. Defaults to false (read/write). + type: boolean + volumeAttributes: + additionalProperties: + type: string + description: volumeAttributes stores driver-specific + properties that are passed to the CSI driver. + Consult your driver's documentation for supported + values. + type: object + required: + - driver + type: object + downwardAPI: + description: downwardAPI represents downward API about + the pod that should populate this volume + properties: + defaultMode: + description: 'Optional: mode bits to use on created + files by default. Must be a Optional: mode bits + used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or + a decimal value between 0 and 511. YAML accepts + both octal and decimal values, JSON requires decimal + values for mode bits. Defaults to 0644. Directories + within the path are not affected by this setting. + This might be in conflict with other options that + affect the file mode, like fsGroup, and the result + can be other mode bits set.' + format: int32 + type: integer + items: + description: Items is a list of downward API volume + file + items: + description: DownwardAPIVolumeFile represents + information to create the file containing the + pod field + properties: + fieldRef: + description: 'Required: Selects a field of + the pod: only annotations, labels, name + and namespace are supported.' + properties: + apiVersion: + description: Version of the schema the + FieldPath is written in terms of, defaults + to "v1". + type: string + fieldPath: + description: Path of the field to select + in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + mode: + description: 'Optional: mode bits used to + set permissions on this file, must be an + octal value between 0000 and 0777 or a decimal + value between 0 and 511. YAML accepts both + octal and decimal values, JSON requires + decimal values for mode bits. If not specified, + the volume defaultMode will be used. This + might be in conflict with other options + that affect the file mode, like fsGroup, + and the result can be other mode bits set.' + format: int32 + type: integer + path: + description: 'Required: Path is the relative + path name of the file to be created. Must + not be absolute or contain the ''..'' path. + Must be utf-8 encoded. The first item of + the relative path must not start with ''..''' + type: string + resourceFieldRef: + description: 'Selects a resource of the container: + only resources limits and requests (limits.cpu, + limits.memory, requests.cpu and requests.memory) + are currently supported.' + properties: + containerName: + description: 'Container name: required + for volumes, optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format + of the exposed resources, defaults to + "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + required: + - path + type: object + type: array + type: object + emptyDir: + description: 'emptyDir represents a temporary directory + that shares a pod''s lifetime. More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir' + properties: + medium: + description: 'medium represents what type of storage + medium should back this directory. The default + is "" which means to use the node''s default medium. + Must be an empty string (default) or Memory. More + info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir' + type: string + sizeLimit: + anyOf: + - type: integer + - type: string + description: 'sizeLimit is the total amount of local + storage required for this EmptyDir volume. The + size limit is also applicable for memory medium. + The maximum usage on memory medium EmptyDir would + be the minimum value between the SizeLimit specified + here and the sum of memory limits of all containers + in a pod. The default is nil which means that + the limit is undefined. More info: http://kubernetes.io/docs/user-guide/volumes#emptydir' + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + ephemeral: + description: "ephemeral represents a volume that is + handled by a cluster storage driver. The volume's + lifecycle is tied to the pod that defines it - it + will be created before the pod starts, and deleted + when the pod is removed. \n Use this if: a) the volume + is only needed while the pod runs, b) features of + normal volumes like restoring from snapshot or capacity + tracking are needed, c) the storage driver is specified + through a storage class, and d) the storage driver + supports dynamic volume provisioning through a PersistentVolumeClaim + (see EphemeralVolumeSource for more information on + the connection between this volume type and PersistentVolumeClaim). + \n Use PersistentVolumeClaim or one of the vendor-specific + APIs for volumes that persist for longer than the + lifecycle of an individual pod. \n Use CSI for light-weight + local ephemeral volumes if the CSI driver is meant + to be used that way - see the documentation of the + driver for more information. \n A pod can use both + types of ephemeral volumes and persistent volumes + at the same time." + properties: + volumeClaimTemplate: + description: "Will be used to create a stand-alone + PVC to provision the volume. The pod in which + this EphemeralVolumeSource is embedded will be + the owner of the PVC, i.e. the PVC will be deleted + together with the pod. The name of the PVC will + be `-` where `` + is the name from the `PodSpec.Volumes` array entry. + Pod validation will reject the pod if the concatenated + name is not valid for a PVC (for example, too + long). \n An existing PVC with that name that + is not owned by the pod will *not* be used for + the pod to avoid using an unrelated volume by + mistake. Starting the pod is then blocked until + the unrelated PVC is removed. If such a pre-created + PVC is meant to be used by the pod, the PVC has + to updated with an owner reference to the pod + once the pod exists. Normally this should not + be necessary, but it may be useful when manually + reconstructing a broken cluster. \n This field + is read-only and no changes will be made by Kubernetes + to the PVC after it has been created. \n Required, + must not be nil." + properties: + metadata: + description: May contain labels and annotations + that will be copied into the PVC when creating + it. No other fields are allowed and will be + rejected during validation. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: The specification for the PersistentVolumeClaim. + The entire content is copied unchanged into + the PVC that gets created from this template. + The same fields as in a PersistentVolumeClaim + are also valid here. + properties: + accessModes: + description: 'accessModes contains the desired + access modes the volume should have. More + info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1' + items: + type: string + type: array + dataSource: + description: 'dataSource field can be used + to specify either: * An existing VolumeSnapshot + object (snapshot.storage.k8s.io/VolumeSnapshot) + * An existing PVC (PersistentVolumeClaim) + If the provisioner or an external controller + can support the specified data source, + it will create a new volume based on the + contents of the specified data source. + When the AnyVolumeDataSource feature gate + is enabled, dataSource contents will be + copied to dataSourceRef, and dataSourceRef + contents will be copied to dataSource + when dataSourceRef.namespace is not specified. + If the namespace is specified, then dataSourceRef + will not be copied to dataSource.' + properties: + apiGroup: + description: APIGroup is the group for + the resource being referenced. If + APIGroup is not specified, the specified + Kind must be in the core API group. + For any other third-party types, APIGroup + is required. + type: string + kind: + description: Kind is the type of resource + being referenced + type: string + name: + description: Name is the name of resource + being referenced + type: string + required: + - kind + - name + type: object + x-kubernetes-map-type: atomic + dataSourceRef: + description: 'dataSourceRef specifies the + object from which to populate the volume + with data, if a non-empty volume is desired. + This may be any object from a non-empty + API group (non core object) or a PersistentVolumeClaim + object. When this field is specified, + volume binding will only succeed if the + type of the specified object matches some + installed volume populator or dynamic + provisioner. This field will replace the + functionality of the dataSource field + and as such if both fields are non-empty, + they must have the same value. For backwards + compatibility, when namespace isn''t specified + in dataSourceRef, both fields (dataSource + and dataSourceRef) will be set to the + same value automatically if one of them + is empty and the other is non-empty. When + namespace is specified in dataSourceRef, + dataSource isn''t set to the same value + and must be empty. There are three important + differences between dataSource and dataSourceRef: + * While dataSource only allows two specific + types of objects, dataSourceRef allows + any non-core object, as well as PersistentVolumeClaim + objects. * While dataSource ignores disallowed + values (dropping them), dataSourceRef + preserves all values, and generates an + error if a disallowed value is specified. + * While dataSource only allows local objects, + dataSourceRef allows objects in any namespaces. + (Beta) Using this field requires the AnyVolumeDataSource + feature gate to be enabled. (Alpha) Using + the namespace field of dataSourceRef requires + the CrossNamespaceVolumeDataSource feature + gate to be enabled.' + properties: + apiGroup: + description: APIGroup is the group for + the resource being referenced. If + APIGroup is not specified, the specified + Kind must be in the core API group. + For any other third-party types, APIGroup + is required. + type: string + kind: + description: Kind is the type of resource + being referenced + type: string + name: + description: Name is the name of resource + being referenced + type: string + namespace: + description: Namespace is the namespace + of resource being referenced Note + that when a namespace is specified, + a gateway.networking.k8s.io/ReferenceGrant + object is required in the referent + namespace to allow that namespace's + owner to accept the reference. See + the ReferenceGrant documentation for + details. (Alpha) This field requires + the CrossNamespaceVolumeDataSource + feature gate to be enabled. + type: string + required: + - kind + - name + type: object + resources: + description: 'resources represents the minimum + resources the volume should have. If RecoverVolumeExpansionFailure + feature is enabled users are allowed to + specify resource requirements that are + lower than previous value but must still + be higher than capacity recorded in the + status field of the claim. More info: + https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources' + 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." + 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. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + selector: + description: selector is a label query over + volumes to consider for binding. + 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 + storageClassName: + description: 'storageClassName is the name + of the StorageClass required by the claim. + More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1' + type: string + volumeMode: + description: volumeMode defines what type + of volume is required by the claim. Value + of Filesystem is implied when not included + in claim spec. + type: string + volumeName: + description: volumeName is the binding reference + to the PersistentVolume backing this claim. + type: string + type: object + required: + - spec + type: object + type: object + fc: + description: fc represents a Fibre Channel resource + that is attached to a kubelet's host machine and then + exposed to the pod. + properties: + fsType: + description: 'fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. TODO: how + do we prevent errors in the filesystem from compromising + the machine' + type: string + lun: + description: 'lun is Optional: FC target lun number' + format: int32 + type: integer + readOnly: + description: 'readOnly is Optional: Defaults to + false (read/write). ReadOnly here will force the + ReadOnly setting in VolumeMounts.' + type: boolean + targetWWNs: + description: 'targetWWNs is Optional: FC target + worldwide names (WWNs)' + items: + type: string + type: array + wwids: + description: 'wwids Optional: FC volume world wide + identifiers (wwids) Either wwids or combination + of targetWWNs and lun must be set, but not both + simultaneously.' + items: + type: string + type: array + type: object + flexVolume: + description: flexVolume represents a generic volume + resource that is provisioned/attached using an exec + based plugin. + properties: + driver: + description: driver is the name of the driver to + use for this volume. + type: string + fsType: + description: fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". The + default filesystem depends on FlexVolume script. + type: string + options: + additionalProperties: + type: string + description: 'options is Optional: this field holds + extra command options if any.' + type: object + readOnly: + description: 'readOnly is Optional: defaults to + false (read/write). ReadOnly here will force the + ReadOnly setting in VolumeMounts.' + type: boolean + secretRef: + description: 'secretRef is Optional: secretRef is + reference to the secret object containing sensitive + information to pass to the plugin scripts. This + may be empty if no secret object is specified. + If the secret object contains more than one secret, + all secrets are passed to the plugin scripts.' + 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 + required: + - driver + type: object + flocker: + description: flocker represents a Flocker volume attached + to a kubelet's host machine. This depends on the Flocker + control service being running + properties: + datasetName: + description: datasetName is Name of the dataset + stored as metadata -> name on the dataset for + Flocker should be considered as deprecated + type: string + datasetUUID: + description: datasetUUID is the UUID of the dataset. + This is unique identifier of a Flocker dataset + type: string + type: object + gcePersistentDisk: + description: 'gcePersistentDisk represents a GCE Disk + resource that is attached to a kubelet''s host machine + and then exposed to the pod. More info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk' + properties: + fsType: + description: 'fsType is filesystem type of the volume + that you want to mount. Tip: Ensure that the filesystem + type is supported by the host operating system. + Examples: "ext4", "xfs", "ntfs". Implicitly inferred + to be "ext4" if unspecified. More info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk + TODO: how do we prevent errors in the filesystem + from compromising the machine' + type: string + partition: + description: 'partition is the partition in the + volume that you want to mount. If omitted, the + default is to mount by volume name. Examples: + For volume /dev/sda1, you specify the partition + as "1". Similarly, the volume partition for /dev/sda + is "0" (or you can leave the property empty). + More info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk' + format: int32 + type: integer + pdName: + description: 'pdName is unique name of the PD resource + in GCE. Used to identify the disk in GCE. More + info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk' + type: string + readOnly: + description: 'readOnly here will force the ReadOnly + setting in VolumeMounts. Defaults to false. More + info: https://kubernetes.io/docs/concepts/storage/volumes#gcepersistentdisk' + type: boolean + required: + - pdName + type: object + gitRepo: + description: 'gitRepo represents a git repository at + a particular revision. DEPRECATED: GitRepo is deprecated. + To provision a container with a git repo, mount an + EmptyDir into an InitContainer that clones the repo + using git, then mount the EmptyDir into the Pod''s + container.' + properties: + directory: + description: directory is the target directory name. + Must not contain or start with '..'. If '.' is + supplied, the volume directory will be the git + repository. Otherwise, if specified, the volume + will contain the git repository in the subdirectory + with the given name. + type: string + repository: + description: repository is the URL + type: string + revision: + description: revision is the commit hash for the + specified revision. + type: string + required: + - repository + type: object + glusterfs: + description: 'glusterfs represents a Glusterfs mount + on the host that shares a pod''s lifetime. More info: + https://examples.k8s.io/volumes/glusterfs/README.md' + properties: + endpoints: + description: 'endpoints is the endpoint name that + details Glusterfs topology. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod' + type: string + path: + description: 'path is the Glusterfs volume path. + More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod' + type: string + readOnly: + description: 'readOnly here will force the Glusterfs + volume to be mounted with read-only permissions. + Defaults to false. More info: https://examples.k8s.io/volumes/glusterfs/README.md#create-a-pod' + type: boolean + required: + - endpoints + - path + type: object + hostPath: + description: 'hostPath represents a pre-existing file + or directory on the host machine that is directly + exposed to the container. This is generally used for + system agents or other privileged things that are + allowed to see the host machine. Most containers will + NOT need this. More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath + --- TODO(jonesdl) We need to restrict who can use + host directory mounts and who can/can not mount host + directories as read/write.' + properties: + path: + description: 'path of the directory on the host. + If the path is a symlink, it will follow the link + to the real path. More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath' + type: string + type: + description: 'type for HostPath Volume Defaults + to "" More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath' + type: string + required: + - path + type: object + iscsi: + description: 'iscsi represents an ISCSI Disk resource + that is attached to a kubelet''s host machine and + then exposed to the pod. More info: https://examples.k8s.io/volumes/iscsi/README.md' + properties: + chapAuthDiscovery: + description: chapAuthDiscovery defines whether support + iSCSI Discovery CHAP authentication + type: boolean + chapAuthSession: + description: chapAuthSession defines whether support + iSCSI Session CHAP authentication + type: boolean + fsType: + description: 'fsType is the filesystem type of the + volume that you want to mount. Tip: Ensure that + the filesystem type is supported by the host operating + system. Examples: "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. More info: + https://kubernetes.io/docs/concepts/storage/volumes#iscsi + TODO: how do we prevent errors in the filesystem + from compromising the machine' + type: string + initiatorName: + description: initiatorName is the custom iSCSI Initiator + Name. If initiatorName is specified with iscsiInterface + simultaneously, new iSCSI interface : will be created for the connection. + type: string + iqn: + description: iqn is the target iSCSI Qualified Name. + type: string + iscsiInterface: + description: iscsiInterface is the interface Name + that uses an iSCSI transport. Defaults to 'default' + (tcp). + type: string + lun: + description: lun represents iSCSI Target Lun number. + format: int32 + type: integer + portals: + description: portals is the iSCSI Target Portal + List. The portal is either an IP or ip_addr:port + if the port is other than default (typically TCP + ports 860 and 3260). + items: + type: string + type: array + readOnly: + description: readOnly here will force the ReadOnly + setting in VolumeMounts. Defaults to false. + type: boolean + secretRef: + description: secretRef is the CHAP Secret for iSCSI + target and initiator authentication + 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 + targetPortal: + description: targetPortal is iSCSI Target Portal. + The Portal is either an IP or ip_addr:port if + the port is other than default (typically TCP + ports 860 and 3260). + type: string + required: + - iqn + - lun + - targetPortal + type: object + name: + description: 'name of the volume. Must be a DNS_LABEL + and unique within the pod. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + nfs: + description: 'nfs represents an NFS mount on the host + that shares a pod''s lifetime More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs' + properties: + path: + description: 'path that is exported by the NFS server. + More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs' + type: string + readOnly: + description: 'readOnly here will force the NFS export + to be mounted with read-only permissions. Defaults + to false. More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs' + type: boolean + server: + description: 'server is the hostname or IP address + of the NFS server. More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs' + type: string + required: + - path + - server + type: object + persistentVolumeClaim: + description: 'persistentVolumeClaimVolumeSource represents + a reference to a PersistentVolumeClaim in the same + namespace. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims' + properties: + claimName: + description: 'claimName is the name of a PersistentVolumeClaim + in the same namespace as the pod using this volume. + More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims' + type: string + readOnly: + description: readOnly Will force the ReadOnly setting + in VolumeMounts. Default false. + type: boolean + required: + - claimName + type: object + photonPersistentDisk: + description: photonPersistentDisk represents a PhotonController + persistent disk attached and mounted on kubelets host + machine + properties: + fsType: + description: fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. + type: string + pdID: + description: pdID is the ID that identifies Photon + Controller persistent disk + type: string + required: + - pdID + type: object + portworxVolume: + description: portworxVolume represents a portworx volume + attached and mounted on kubelets host machine + properties: + fsType: + description: fSType represents the filesystem type + to mount Must be a filesystem type supported by + the host operating system. Ex. "ext4", "xfs". + Implicitly inferred to be "ext4" if unspecified. + type: string + readOnly: + description: readOnly defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + volumeID: + description: volumeID uniquely identifies a Portworx + volume + type: string + required: + - volumeID + type: object + projected: + description: projected items for all in one resources + secrets, configmaps, and downward API + properties: + defaultMode: + description: defaultMode are the mode bits used + to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or + a decimal value between 0 and 511. YAML accepts + both octal and decimal values, JSON requires decimal + values for mode bits. Directories within the path + are not affected by this setting. This might be + in conflict with other options that affect the + file mode, like fsGroup, and the result can be + other mode bits set. + format: int32 + type: integer + sources: + description: sources is the list of volume projections + items: + description: Projection that may be projected + along with other supported volume types + properties: + configMap: + description: configMap information about the + configMap data to project + properties: + items: + description: items if unspecified, each + key-value pair in the Data field of + the referenced ConfigMap will be projected + into the volume as a file whose name + is the key and content is the value. + If specified, the listed keys will be + projected into the specified paths, + and unlisted keys will not be present. + If a key is specified which is not present + in the ConfigMap, the volume setup will + error unless it is marked optional. + Paths must be relative and may not contain + the '..' path or start with '..'. + items: + description: Maps a string key to a + path within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: 'mode is Optional: + mode bits used to set permissions + on this file. Must be an octal + value between 0000 and 0777 or + a decimal value between 0 and + 511. YAML accepts both octal and + decimal values, JSON requires + decimal values for mode bits. + If not specified, the volume defaultMode + will be used. This might be in + conflict with other options that + affect the file mode, like fsGroup, + and the result can be other mode + bits set.' + format: int32 + type: integer + path: + description: path is the relative + path of the file to map the key + to. May not be an absolute path. + May not contain the path element + '..'. May not start with the string + '..'. + type: string + required: + - key + - path + type: object + type: array + 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 + optional: + description: optional specify whether + the ConfigMap or its keys must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + downwardAPI: + description: downwardAPI information about + the downwardAPI data to project + properties: + items: + description: Items is a list of DownwardAPIVolume + file + items: + description: DownwardAPIVolumeFile represents + information to create the file containing + the pod field + properties: + fieldRef: + description: 'Required: Selects + a field of the pod: only annotations, + labels, name and namespace are + supported.' + properties: + apiVersion: + description: Version of the + schema the FieldPath is written + in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field + to select in the specified + API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + mode: + description: 'Optional: mode bits + used to set permissions on this + file, must be an octal value between + 0000 and 0777 or a decimal value + between 0 and 511. YAML accepts + both octal and decimal values, + JSON requires decimal values for + mode bits. If not specified, the + volume defaultMode will be used. + This might be in conflict with + other options that affect the + file mode, like fsGroup, and the + result can be other mode bits + set.' + format: int32 + type: integer + path: + description: 'Required: Path is the + relative path name of the file + to be created. Must not be absolute + or contain the ''..'' path. Must + be utf-8 encoded. The first item + of the relative path must not + start with ''..''' + type: string + resourceFieldRef: + description: 'Selects a resource + of the container: only resources + limits and requests (limits.cpu, + limits.memory, requests.cpu and + requests.memory) are currently + supported.' + properties: + containerName: + description: 'Container name: + required for volumes, optional + for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output + format of the exposed resources, + defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource + to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + required: + - path + type: object + type: array + type: object + secret: + description: secret information about the + secret data to project + properties: + items: + description: items if unspecified, each + key-value pair in the Data field of + the referenced Secret will be projected + into the volume as a file whose name + is the key and content is the value. + If specified, the listed keys will be + projected into the specified paths, + and unlisted keys will not be present. + If a key is specified which is not present + in the Secret, the volume setup will + error unless it is marked optional. + Paths must be relative and may not contain + the '..' path or start with '..'. + items: + description: Maps a string key to a + path within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: 'mode is Optional: + mode bits used to set permissions + on this file. Must be an octal + value between 0000 and 0777 or + a decimal value between 0 and + 511. YAML accepts both octal and + decimal values, JSON requires + decimal values for mode bits. + If not specified, the volume defaultMode + will be used. This might be in + conflict with other options that + affect the file mode, like fsGroup, + and the result can be other mode + bits set.' + format: int32 + type: integer + path: + description: path is the relative + path of the file to map the key + to. May not be an absolute path. + May not contain the path element + '..'. May not start with the string + '..'. + type: string + required: + - key + - path + type: object + type: array + 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 + optional: + description: optional field specify whether + the Secret or its key must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + serviceAccountToken: + description: serviceAccountToken is information + about the serviceAccountToken data to project + properties: + audience: + description: audience is the intended + audience of the token. A recipient of + a token must identify itself with an + identifier specified in the audience + of the token, and otherwise should reject + the token. The audience defaults to + the identifier of the apiserver. + type: string + expirationSeconds: + description: expirationSeconds is the + requested duration of validity of the + service account token. As the token + approaches expiration, the kubelet volume + plugin will proactively rotate the service + account token. The kubelet will start + trying to rotate the token if the token + is older than 80 percent of its time + to live or if the token is older than + 24 hours.Defaults to 1 hour and must + be at least 10 minutes. + format: int64 + type: integer + path: + description: path is the path relative + to the mount point of the file to project + the token into. + type: string + required: + - path + type: object + type: object + type: array + type: object + quobyte: + description: quobyte represents a Quobyte mount on the + host that shares a pod's lifetime + properties: + group: + description: group to map volume access to Default + is no group + type: string + readOnly: + description: readOnly here will force the Quobyte + volume to be mounted with read-only permissions. + Defaults to false. + type: boolean + registry: + description: registry represents a single or multiple + Quobyte Registry services specified as a string + as host:port pair (multiple entries are separated + with commas) which acts as the central registry + for volumes + type: string + tenant: + description: tenant owning the given Quobyte volume + in the Backend Used with dynamically provisioned + Quobyte volumes, value is set by the plugin + type: string + user: + description: user to map volume access to Defaults + to serivceaccount user + type: string + volume: + description: volume is a string that references + an already created Quobyte volume by name. + type: string + required: + - registry + - volume + type: object + rbd: + description: 'rbd represents a Rados Block Device mount + on the host that shares a pod''s lifetime. More info: + https://examples.k8s.io/volumes/rbd/README.md' + properties: + fsType: + description: 'fsType is the filesystem type of the + volume that you want to mount. Tip: Ensure that + the filesystem type is supported by the host operating + system. Examples: "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. More info: + https://kubernetes.io/docs/concepts/storage/volumes#rbd + TODO: how do we prevent errors in the filesystem + from compromising the machine' + type: string + image: + description: 'image is the rados image name. More + info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: string + keyring: + description: 'keyring is the path to key ring for + RBDUser. Default is /etc/ceph/keyring. More info: + https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: string + monitors: + description: 'monitors is a collection of Ceph monitors. + More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + items: + type: string + type: array + pool: + description: 'pool is the rados pool name. Default + is rbd. More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: string + readOnly: + description: 'readOnly here will force the ReadOnly + setting in VolumeMounts. Defaults to false. More + info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: boolean + secretRef: + description: 'secretRef is name of the authentication + secret for RBDUser. If provided overrides keyring. + Default is nil. More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + 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 + user: + description: 'user is the rados user name. Default + is admin. More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it' + type: string + required: + - image + - monitors + type: object + scaleIO: + description: scaleIO represents a ScaleIO persistent + volume attached and mounted on Kubernetes nodes. + properties: + fsType: + description: fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Default + is "xfs". + type: string + gateway: + description: gateway is the host address of the + ScaleIO API Gateway. + type: string + protectionDomain: + description: protectionDomain is the name of the + ScaleIO Protection Domain for the configured storage. + type: string + readOnly: + description: readOnly Defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + secretRef: + description: secretRef references to the secret + for ScaleIO user and other sensitive information. + If this is not provided, Login operation will + fail. + 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 + sslEnabled: + description: sslEnabled Flag enable/disable SSL + communication with Gateway, default false + type: boolean + storageMode: + description: storageMode indicates whether the storage + for a volume should be ThickProvisioned or ThinProvisioned. + Default is ThinProvisioned. + type: string + storagePool: + description: storagePool is the ScaleIO Storage + Pool associated with the protection domain. + type: string + system: + description: system is the name of the storage system + as configured in ScaleIO. + type: string + volumeName: + description: volumeName is the name of a volume + already created in the ScaleIO system that is + associated with this volume source. + type: string + required: + - gateway + - secretRef + - system + type: object + secret: + description: 'secret represents a secret that should + populate this volume. More info: https://kubernetes.io/docs/concepts/storage/volumes#secret' + properties: + defaultMode: + description: 'defaultMode is Optional: mode bits + used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or + a decimal value between 0 and 511. YAML accepts + both octal and decimal values, JSON requires decimal + values for mode bits. Defaults to 0644. Directories + within the path are not affected by this setting. + This might be in conflict with other options that + affect the file mode, like fsGroup, and the result + can be other mode bits set.' + format: int32 + type: integer + items: + description: items If unspecified, each key-value + pair in the Data field of the referenced Secret + will be projected into the volume as a file whose + name is the key and content is the value. If specified, + the listed keys will be projected into the specified + paths, and unlisted keys will not be present. + If a key is specified which is not present in + the Secret, the volume setup will error unless + it is marked optional. Paths must be relative + and may not contain the '..' path or start with + '..'. + items: + description: Maps a string key to a path within + a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: 'mode is Optional: mode bits + used to set permissions on this file. Must + be an octal value between 0000 and 0777 + or a decimal value between 0 and 511. YAML + accepts both octal and decimal values, JSON + requires decimal values for mode bits. If + not specified, the volume defaultMode will + be used. This might be in conflict with + other options that affect the file mode, + like fsGroup, and the result can be other + mode bits set.' + format: int32 + type: integer + path: + description: path is the relative path of + the file to map the key to. May not be an + absolute path. May not contain the path + element '..'. May not start with the string + '..'. + type: string + required: + - key + - path + type: object + type: array + optional: + description: optional field specify whether the + Secret or its keys must be defined + type: boolean + secretName: + description: 'secretName is the name of the secret + in the pod''s namespace to use. More info: https://kubernetes.io/docs/concepts/storage/volumes#secret' + type: string + type: object + storageos: + description: storageOS represents a StorageOS volume + attached and mounted on Kubernetes nodes. + properties: + fsType: + description: fsType is the filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. + type: string + readOnly: + description: readOnly defaults to false (read/write). + ReadOnly here will force the ReadOnly setting + in VolumeMounts. + type: boolean + secretRef: + description: secretRef specifies the secret to use + for obtaining the StorageOS API credentials. If + not specified, default values will be attempted. + 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 + volumeName: + description: volumeName is the human-readable name + of the StorageOS volume. Volume names are only + unique within a namespace. + type: string + volumeNamespace: + description: volumeNamespace specifies the scope + of the volume within StorageOS. If no namespace + is specified then the Pod's namespace will be + used. This allows the Kubernetes name scoping + to be mirrored within StorageOS for tighter integration. + Set VolumeName to any name to override the default + behaviour. Set to "default" if you are not using + namespaces within StorageOS. Namespaces that do + not pre-exist within StorageOS will be created. + type: string + type: object + vsphereVolume: + description: vsphereVolume represents a vSphere volume + attached and mounted on kubelets host machine + properties: + fsType: + description: fsType is filesystem type to mount. + Must be a filesystem type supported by the host + operating system. Ex. "ext4", "xfs", "ntfs". Implicitly + inferred to be "ext4" if unspecified. + type: string + storagePolicyID: + description: storagePolicyID is the storage Policy + Based Management (SPBM) profile ID associated + with the StoragePolicyName. + type: string + storagePolicyName: + description: storagePolicyName is the storage Policy + Based Management (SPBM) profile name. + type: string + volumePath: + description: volumePath is the path that identifies + vSphere volume vmdk + type: string + required: + - volumePath + type: object + required: + - name + type: object + type: array + required: + - containers + type: object + type: object + revisionHistoryLimit: + description: RevisionHistoryLimit is the number of revisions to retain + to allow rollback in the underlying StatefulSet. + format: int32 + type: integer + secureSettings: + description: SecureSettings is a list of references to Kubernetes + Secrets containing sensitive configuration options for the Logstash. + Secrets data can be then referenced in the Logstash config using + the Secret's keys or as specified in `Entries` field of each SecureSetting. + items: + description: SecretSource defines a data source based on a Kubernetes + Secret. + properties: + entries: + description: Entries define how to project each key-value pair + in the secret to filesystem paths. If not defined, all keys + will be projected to similarly named paths in the filesystem. + If defined, only the specified keys will be projected to the + corresponding paths. + items: + description: KeyToPath defines how to map a key in a Secret + object to a filesystem path. + properties: + key: + description: Key is the key contained in the secret. + type: string + path: + description: Path is the relative file path to map the + key to. Path must not be an absolute file path and must + not contain any ".." components. + type: string + required: + - key + type: object + type: array + secretName: + description: SecretName is the name of the secret. + type: string + required: + - secretName + type: object + type: array + serviceAccountName: + description: ServiceAccountName is used to check access from the current + resource to Elasticsearch resource in a different namespace. Can + only be used if ECK is enforcing RBAC on references. + type: string + version: + description: Version of the Logstash. + type: string + required: + - version + type: object + status: + description: LogstashStatus defines the observed state of Logstash + properties: + availableNodes: + format: int32 + type: integer + expectedNodes: + format: int32 + type: integer + observedGeneration: + description: ObservedGeneration is the most recent generation observed + for this Logstash instance. It corresponds to the metadata generation, + which is updated on mutation by the API Server. If the generation + observed in status diverges from the generation in metadata, the + Logstash controller has not yet processed the changes contained + in the Logstash specification. + format: int64 + type: integer + version: + description: 'Version of the stack resource currently running. During + version upgrades, multiple versions may run in parallel: this value + specifies the lowest version currently running.' + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/crds/v1/patches/kustomization.yaml b/config/crds/v1/patches/kustomization.yaml index f8dfffb0f8..60556c047d 100644 --- a/config/crds/v1/patches/kustomization.yaml +++ b/config/crds/v1/patches/kustomization.yaml @@ -70,4 +70,12 @@ patchesJson6902: kind: CustomResourceDefinition name: elasticmapsservers.maps.k8s.elastic.co path: maps-patches.yaml + # custom patches for Beat + - target: + group: apiextensions.k8s.io + version: v1 + kind: CustomResourceDefinition + name: logstashes.logstash.k8s.elastic.co + path: logstash-patches.yaml + diff --git a/config/crds/v1/patches/logstash-patches.yaml b/config/crds/v1/patches/logstash-patches.yaml new file mode 100644 index 0000000000..ce8f164770 --- /dev/null +++ b/config/crds/v1/patches/logstash-patches.yaml @@ -0,0 +1,7 @@ +# Using `kubectl apply` stores the complete CRD file as an annotation, +# which may be too big for the annotations size limit. +# One way to mitigate this problem is to remove the (huge) podTemplate properties from the CRD. +# It also avoids the problem of having any k8s-version specific field in the Pod schema, +# that would maybe not match the user's k8s version. +- op: remove + path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/podTemplate/properties diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml new file mode 100644 index 0000000000..530891e91a --- /dev/null +++ b/config/samples/logstash/logstash.yaml @@ -0,0 +1,27 @@ +apiVersion: elasticsearch.k8s.elastic.co/v1 +kind: Elasticsearch +metadata: + name: elasticsearch-sample +spec: + version: 8.6.1 + nodeSets: + - name: default + count: 1 + config: + node.store.allow_mmap: false +--- +apiVersion: logstash.k8s.elastic.co/v1alpha1 +kind: Logstash +metadata: + name: logstash-sample +spec: + count: 3 + version: 8.6.1 + config: + log.level: info + api.http.host: "0.0.0.0" + queue.type: memory + podTemplate: + spec: + containers: + - name: logstash diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 2bb647a6db..1870792dd2 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -203,6 +203,28 @@ webhooks: resources: - kibanas sideEffects: None +- admissionReviewVersions: + - v1 + - v1beta1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /validate-logstash-k8s-elastic-co-v1alpha1-logstash + failurePolicy: Ignore + matchPolicy: Exact + name: elastic-logstash-validation-v1alpha1.k8s.elastic.co + rules: + - apiGroups: + - logstash.k8s.elastic.co + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - logstashs + sideEffects: None - admissionReviewVersions: - v1alpha1 clientConfig: diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index ed9ff0e618..b9fab1fb80 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9093,6 +9093,602 @@ spec: --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.11.3 + creationTimestamp: null + labels: + app.kubernetes.io/instance: '{{ .Release.Name }}' + app.kubernetes.io/managed-by: '{{ .Release.Service }}' + app.kubernetes.io/name: '{{ include "eck-operator-crds.name" . }}' + app.kubernetes.io/version: '{{ .Chart.AppVersion }}' + helm.sh/chart: '{{ include "eck-operator-crds.chart" . }}' + name: logstashes.logstash.k8s.elastic.co +spec: + group: logstash.k8s.elastic.co + names: + categories: + - elastic + kind: Logstash + listKind: LogstashList + plural: logstashes + shortNames: + - ls + singular: logstash + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Available nodes + jsonPath: .status.availableNodes + name: available + type: integer + - description: Expected nodes + jsonPath: .status.expectedNodes + name: expected + type: integer + - jsonPath: .metadata.creationTimestamp + name: age + type: date + - description: Logstash version + jsonPath: .status.version + name: version + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Logstash is the Schema for the logstashes 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: LogstashSpec defines the desired state of Logstash + properties: + config: + description: Config holds the Logstash configuration. At most one + of [`Config`, `ConfigRef`] can be specified. + type: object + x-kubernetes-preserve-unknown-fields: true + configRef: + description: ConfigRef contains a reference to an existing Kubernetes + Secret holding the Logstash configuration. Logstash settings must + be specified as yaml, under a single "logstash.yml" entry. At most + one of [`Config`, `ConfigRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + count: + format: int32 + type: integer + http: + description: HTTP holds the HTTP layer configuration for the Agent + in Fleet mode with Fleet Server enabled. + properties: + service: + description: Service defines the template for the associated Kubernetes + Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. The + name and namespace provided here are managed by ECK and + will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may be + set to "false" if the cluster load-balancer does not + rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests will + be respected, regardless of this field. This field may + only be set for services with type LoadBalancer and + will be cleared if the type is changed to any other + type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is specified + manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This field + may not be changed through updates unless the type field + is also being changed to ExternalName (which requires + this field to be blank) or the type field is being changed + from ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + "None", empty string (""), or a valid IP address. Setting + this to "None" makes a "headless service" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range (as + per system configuration), and is not in use, it will + be allocated to the service; otherwise creation of the + service will fail. This field may not be changed through + updates unless the type field is also being changed + to ExternalName (which requires this field to be empty) + or the type field is being changed from ExternalName + (in which case this field may optionally be specified, + as describe above). Valid values are \"None\", empty + string (\"\"), or a valid IP address. Setting this + to \"None\" makes a \"headless service\" (no virtual + IP), which is useful when direct endpoint connections + are preferred and proxying is not required. Only applies + to types ClusterIP, NodePort, and LoadBalancer. If this + field is specified when creating a Service of type ExternalName, + creation will fail. This field will be wiped when updating + a Service to type ExternalName. If this field is not + specified, it will be initialized from the clusterIP + field. If this field is specified, clients must ensure + that clusterIPs[0] and clusterIP have the same value. + \n This field may hold a maximum of two entries (dual-stack + IPs, in either order). These IPs must correspond to + the values of the ipFamilies field. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy field. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes system. + items: + type: string + type: array + externalName: + description: externalName is the external reference that + discovery mechanisms will return as an alias for this + service (e.g. a DNS CNAME record). No proxying will + be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires `type` + to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of the + Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that assumes + that external load balancers will take care of balancing + the service traffic between nodes, and so each node + will deliver traffic only to the node-local endpoints + of the service, without masquerading the client source + IP. (Traffic mistakenly sent to a node with no endpoints + will be dropped.) The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + Note that traffic sent to an External IP or LoadBalancer + IP from within the cluster will always get "Cluster" + semantics, but clients sending to a NodePort from within + the cluster may need to take traffic policy into account + when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External systems + (e.g. load-balancers) can use this port to determine + if a given node holds endpoints for this service or + not. If this field is specified when creating a Service + which does not need it, creation will fail. This field + will be wiped when updating a Service to no longer need + it (e.g. changing type). This field cannot be updated + once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods only + want to talk to endpoints of the service on the same + node as the pod, dropping the traffic if there are no + local endpoints. The default value, "Cluster", uses + the standard behavior of routing to all endpoints evenly + (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the cluster, + and ipFamilyPolicy allows it, it will be used; otherwise + creation of the service will fail. This field is conditionally + mutable: it allows for adding or removing a secondary + IP family, but it does not allow changing the primary + IP family of the Service. Valid values are \"IPv4\" + and \"IPv6\". This field only applies to Services of + types ClusterIP, NodePort, and LoadBalancer, and does + apply to \"headless\" services. This field will be wiped + when updating a Service to type ExternalName. \n This + field may hold a maximum of two entries (dual-stack + families, in either order). These families must correspond + to the values of the clusterIPs field, if specified. + Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is no + value provided, then this field will be set to SingleStack. + Services can be "SingleStack" (a single IP family), + "PreferDualStack" (two IP families on dual-stack configured + clusters or a single IP family on single-stack clusters), + or "RequireDualStack" (two IP families on dual-stack + configured clusters, otherwise fail). The ipFamilies + and clusterIPs fields depend on the value of this field. + This field will be wiped when updating a service to + type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set when + the Service type is 'LoadBalancer'. If not set, the + default load balancer implementation is used, today + this is typically done through the cloud provider integration, + but should apply for any default implementation. If + set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated to + a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load balancer + is created. This field will be ignored if the cloud-provider + does not support the feature. Deprecated: This field + was under-specified and its meaning varies across implementations, + and it cannot support dual-stack. As of Kubernetes v1.24, + users are encouraged to use implementation-specific + annotations when available. This field may be removed + in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified client + IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by this + service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this port. + This field follows standard Kubernetes label syntax. + Un-prefixed names are reserved for IANA standard + service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the service. + This must be a DNS_LABEL. All ports within a ServiceSpec + must have unique names. When considering the endpoints + for a Service, this must match the 'name' field + in the EndpointPort. Optional if only one ServicePort + is defined on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or LoadBalancer. Usually + assigned by the system. If a value is specified, + in-range, and not in use it will be used, otherwise + the operation will fail. If not specified, a + port will be allocated if this Service requires + one. If this field is specified when creating + a Service which does not need it, creation will + fail. This field will be wiped when updating a + Service to no longer need it (e.g. changing type + from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by this + service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number must + be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + If this is a string, it will be looked up as a + named port in the target Pod''s container ports. + If this is not specified, the value of the ''port'' + field is used (an identity map). This field is + ignored for services with clusterIP=None, and + should be omitted or set equal to the ''port'' + field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that any + agent which deals with endpoints for this Service should + disregard any indications of ready/not-ready. The primary + use case for setting this field is for a StatefulSet's + Headless Service to propagate SRV DNS records for its + Pods for the purpose of peer discovery. The Kubernetes + controllers that generate Endpoints and EndpointSlice + resources for Services interpret this to mean that all + endpoints are considered "ready" even if the Pods themselves + are not. Agents which consume only Kubernetes generated + endpoints through the Endpoints or EndpointSlice resources + can safely assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. More + info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based session + affinity. Must be ClientIP or None. Defaults to None. + More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The value + must be >0 && <=86400(for 1 day) if ServiceAffinity + == "ClientIP". Default value is 10800(for 3 + hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates + a cluster-internal IP address for load-balancing to + endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints rather + than a virtual IP. "NodePort" builds on ClusterIP and + allocates a port on every node which routes to the same + endpoints as the clusterIP. "LoadBalancer" builds on + NodePort and creates an external load-balancer (if supported + in the current cloud) which routes to the same endpoints + as the clusterIP. "ExternalName" aliases this service + to the specified externalName. Several other fields + do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes secret + that contains the certificate and private key for enabling + TLS. The referenced secret should contain the following: + \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: + The certificate (or a chain). - `tls.key`: The private key + to the first certificate in the certificate chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + image: + description: Image is the Logstash Docker image to deploy. Version + and Type have to match the Logstash in the image. + type: string + podTemplate: + description: PodTemplate provides customisation options for the Logstash + pods. + type: object + revisionHistoryLimit: + description: RevisionHistoryLimit is the number of revisions to retain + to allow rollback in the underlying StatefulSet. + format: int32 + type: integer + secureSettings: + description: SecureSettings is a list of references to Kubernetes + Secrets containing sensitive configuration options for the Logstash. + Secrets data can be then referenced in the Logstash config using + the Secret's keys or as specified in `Entries` field of each SecureSetting. + items: + description: SecretSource defines a data source based on a Kubernetes + Secret. + properties: + entries: + description: Entries define how to project each key-value pair + in the secret to filesystem paths. If not defined, all keys + will be projected to similarly named paths in the filesystem. + If defined, only the specified keys will be projected to the + corresponding paths. + items: + description: KeyToPath defines how to map a key in a Secret + object to a filesystem path. + properties: + key: + description: Key is the key contained in the secret. + type: string + path: + description: Path is the relative file path to map the + key to. Path must not be an absolute file path and must + not contain any ".." components. + type: string + required: + - key + type: object + type: array + secretName: + description: SecretName is the name of the secret. + type: string + required: + - secretName + type: object + type: array + serviceAccountName: + description: ServiceAccountName is used to check access from the current + resource to Elasticsearch resource in a different namespace. Can + only be used if ECK is enforcing RBAC on references. + type: string + version: + description: Version of the Logstash. + type: string + required: + - version + type: object + status: + description: LogstashStatus defines the observed state of Logstash + properties: + availableNodes: + format: int32 + type: integer + expectedNodes: + format: int32 + type: integer + observedGeneration: + description: ObservedGeneration is the most recent generation observed + for this Logstash instance. It corresponds to the metadata generation, + which is updated on mutation by the API Server. If the generation + observed in status diverges from the generation in metadata, the + Logstash controller has not yet processed the changes contained + in the Logstash specification. + format: int64 + type: integer + version: + description: 'Version of the stack resource currently running. During + version upgrades, multiple versions may run in parallel: this value + specifies the lowest version currently running.' + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.11.3 diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 04cdc02ee7..a06cf4cb7f 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -26,6 +26,7 @@ endif::[] - xref:{anchor_prefix}-enterprisesearch-k8s-elastic-co-v1beta1[$$enterprisesearch.k8s.elastic.co/v1beta1$$] - xref:{anchor_prefix}-kibana-k8s-elastic-co-v1[$$kibana.k8s.elastic.co/v1$$] - xref:{anchor_prefix}-kibana-k8s-elastic-co-v1beta1[$$kibana.k8s.elastic.co/v1beta1$$] +- xref:{anchor_prefix}-logstash-k8s-elastic-co-v1alpha1[$$logstash.k8s.elastic.co/v1alpha1$$] - xref:{anchor_prefix}-maps-k8s-elastic-co-v1alpha1[$$maps.k8s.elastic.co/v1alpha1$$] - xref:{anchor_prefix}-stackconfigpolicy-k8s-elastic-co-v1alpha1[$$stackconfigpolicy.k8s.elastic.co/v1alpha1$$] @@ -448,6 +449,7 @@ Config represents untyped YAML configuration. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-stackconfigpolicy-v1alpha1-indextemplates[$$IndexTemplates$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-nodeset[$$NodeSet$$] **** @@ -465,6 +467,7 @@ ConfigSource references configuration settings. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] **** @@ -491,6 +494,7 @@ HTTPConfig holds the HTTP layer configuration for resources. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] **** @@ -587,6 +591,7 @@ Monitoring holds references to both the metrics, and logs Elasticsearch clusters - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-elasticsearchspec[$$ElasticsearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] **** [cols="25a,75a", options="header"] @@ -611,6 +616,7 @@ ObjectSelector defines a reference to a Kubernetes object which can be an Elasti - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-logsmonitoring[$$LogsMonitoring$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-metricsmonitoring[$$MetricsMonitoring$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-agent-v1alpha1-output[$$Output$$] @@ -678,6 +684,7 @@ SecretSource defines a data source based on a Kubernetes Secret. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-elasticsearchspec[$$ElasticsearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-stackconfigpolicy-v1alpha1-stackconfigpolicyspec[$$StackConfigPolicySpec$$] **** @@ -1824,6 +1831,124 @@ KibanaSpec holds the specification of a Kibana instance. +[id="{anchor_prefix}-logstash-k8s-elastic-co-v1alpha1"] +== logstash.k8s.elastic.co/v1alpha1 + +Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API group + + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-deploymentspec"] +=== DeploymentSpec + + + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | +| *`replicas`* __integer__ | +| *`strategy`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#deploymentstrategy-v1-apps[$$DeploymentStrategy$$]__ | +|=== + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash"] +=== Logstash + +Logstash is the Schema for the logstashes API + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashlist[$$LogstashList$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`metadata`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#objectmeta-v1-meta[$$ObjectMeta$$]__ | Refer to Kubernetes API documentation for fields of `metadata`. + +| *`spec`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$]__ | +| *`status`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashstatus[$$LogstashStatus$$]__ | +|=== + + + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec"] +=== LogstashSpec + +LogstashSpec defines the desired state of Logstash + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash[$$Logstash$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`version`* __string__ | Version of the Logstash. +| *`elasticsearchRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-objectselector[$$ObjectSelector$$]__ | ElasticsearchRef is a reference to an Elasticsearch cluster running in the same Kubernetes cluster. +| *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. +| *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. +| *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. +| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelineRef`] can be specified. +| *`pipelineRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelineRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipeline must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelineRef`] can be specified. +| *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. +| *`serviceAccountName`* __string__ | ServiceAccountName is used to check access from the current resource to Elasticsearch resource in a different namespace. Can only be used if ECK is enforcing RBAC on references. +| *`deployment`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-deploymentspec[$$DeploymentSpec$$]__ | Deployment specifies the Logstash should be deployed as a Deployment, and allows providing its spec. Cannot be used along with `StatefulSet`. +| *`statefulSet`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-statefulsetspec[$$StatefulSetSpec$$]__ | StatefulSet specifies the Logstash should be deployed as a StatefulSet, and allows providing its spec. Cannot be used along with `Deployment`. +| *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying DaemonSet or Deployment. +| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Agent in Fleet mode with Fleet Server enabled. +| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. See https://www.elastic.co/guide/en/kibana/current/xpack-monitoring.html. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. +|=== + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashstatus"] +=== LogstashStatus + +LogstashStatus defines the observed state of Logstash + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash[$$Logstash$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`version`* __string__ | Version of the stack resource currently running. During version upgrades, multiple versions may run in parallel: this value specifies the lowest version currently running. +| *`expectedNodes`* __integer__ | +| *`availableNodes`* __integer__ | +| *`observedGeneration`* __integer__ | ObservedGeneration is the most recent generation observed for this Logstash instance. It corresponds to the metadata generation, which is updated on mutation by the API Server. If the generation observed in status diverges from the generation in metadata, the Logstash controller has not yet processed the changes contained in the Logstash specification. +|=== + + +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-statefulsetspec"] +=== StatefulSetSpec + + + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | +| *`replicas`* __integer__ | +| *`volumeClaimTemplates`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#persistentvolumeclaim-v1-core[$$PersistentVolumeClaim$$] array__ | VolumeClaimTemplates is a list of persistent volume claims to be used by each Pod in this NodeSet. Every claim in this list must have a matching volumeMount in one of the containers defined in the PodTemplate. Items defined here take precedence over any default claims added by the operator with the same name. +|=== + + + [id="{anchor_prefix}-maps-k8s-elastic-co-v1alpha1"] == maps.k8s.elastic.co/v1alpha1 diff --git a/hack/upgrade-test-harness/go.sum b/hack/upgrade-test-harness/go.sum index 33f26b3dc9..3e5bb00679 100644 --- a/hack/upgrade-test-harness/go.sum +++ b/hack/upgrade-test-harness/go.sum @@ -627,8 +627,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= +golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= diff --git a/pkg/apis/common/v1/association.go b/pkg/apis/common/v1/association.go index 721055c273..8bcfaa2f23 100644 --- a/pkg/apis/common/v1/association.go +++ b/pkg/apis/common/v1/association.go @@ -110,6 +110,8 @@ const ( BeatAssociationType = "beat" BeatMonitoringAssociationType = "beat-monitoring" + LogstashMonitoringAssociationType = "ls-monitoring" + AssociationUnknown AssociationStatus = "" AssociationPending AssociationStatus = "Pending" AssociationEstablished AssociationStatus = "Established" diff --git a/pkg/apis/logstash/v1alpha1/doc.go b/pkg/apis/logstash/v1alpha1/doc.go new file mode 100644 index 0000000000..a92dd08678 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/doc.go @@ -0,0 +1,11 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +// Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API group +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=github.com/elastic/cloud-on-k8s/pkg/apis/logstash +// +k8s:defaulter-gen=TypeMeta +// +groupName=logstash.k8s.elastic.co +package v1alpha1 diff --git a/pkg/apis/logstash/v1alpha1/groupversion_info.go b/pkg/apis/logstash/v1alpha1/groupversion_info.go new file mode 100644 index 0000000000..5589c3a240 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/groupversion_info.go @@ -0,0 +1,21 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "logstash.k8s.elastic.co", Version: "v1alpha1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} + + // AddToScheme is required by pkg/client/... + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/pkg/apis/logstash/v1alpha1/labels.go b/pkg/apis/logstash/v1alpha1/labels.go new file mode 100644 index 0000000000..70e5fa8cf5 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/labels.go @@ -0,0 +1,17 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" +) + +// GetIdentityLabels will return the common Elastic assigned labels for Logstash +func (logstash* Logstash) GetIdentityLabels() map[string]string { + return map[string]string{ + commonv1.TypeLabelName: "logstash", + "logstash.k8s.elastic.co/name": logstash.Name, + } +} diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go new file mode 100644 index 0000000000..d948fd2b96 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -0,0 +1,130 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + // Kind is inferred from the struct name using reflection in SchemeBuilder.Register() + // we duplicate it as a constant here for practical purposes. + Kind = "Logstash" +) + +// LogstashSpec defines the desired state of Logstash +type LogstashSpec struct { + // Version of the Logstash. + Version string `json:"version"` + + Count int32 `json:"count,omitempty"` + + // Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. + // +kubebuilder:validation:Optional + Image string `json:"image,omitempty"` + + // Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. + // +kubebuilder:validation:Optional + // +kubebuilder:pruning:PreserveUnknownFields + Config *commonv1.Config `json:"config,omitempty"` + + // ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. + // Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] + // can be specified. + // +kubebuilder:validation:Optional + ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"` + + // PodTemplate provides customisation options for the Logstash pods. + PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` + + // SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. + // Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of + // each SecureSetting. + // +kubebuilder:validation:Optional + SecureSettings []commonv1.SecretSource `json:"secureSettings,omitempty"` + + // ServiceAccountName is used to check access from the current resource to Elasticsearch resource in a different namespace. + // Can only be used if ECK is enforcing RBAC on references. + // +kubebuilder:validation:Optional + ServiceAccountName string `json:"serviceAccountName,omitempty"` + + // RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. + RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` + + // HTTP holds the HTTP layer configuration for the Agent in Fleet mode with Fleet Server enabled. + // +kubebuilder:validation:Optional + HTTP commonv1.HTTPConfig `json:"http,omitempty"` +} + +// LogstashStatus defines the observed state of Logstash +type LogstashStatus struct { + // Version of the stack resource currently running. During version upgrades, multiple versions may run + // in parallel: this value specifies the lowest version currently running. + Version string `json:"version,omitempty"` + + // +kubebuilder:validation:Optional + ExpectedNodes int32 `json:"expectedNodes,omitempty"` + // +kubebuilder:validation:Optional + AvailableNodes int32 `json:"availableNodes,omitempty"` + + // ObservedGeneration is the most recent generation observed for this Logstash instance. + // It corresponds to the metadata generation, which is updated on mutation by the API Server. + // If the generation observed in status diverges from the generation in metadata, the Logstash + // controller has not yet processed the changes contained in the Logstash specification. + ObservedGeneration int64 `json:"observedGeneration,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Logstash is the Schema for the logstashes API +// +k8s:openapi-gen=true +// +kubebuilder:resource:categories=elastic,shortName=ls +// +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="available",type="integer",JSONPath=".status.availableNodes",description="Available nodes" +// +kubebuilder:printcolumn:name="expected",type="integer",JSONPath=".status.expectedNodes",description="Expected nodes" +// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Logstash version" +// +kubebuilder:storageversion +type Logstash struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec LogstashSpec `json:"spec,omitempty"` + Status LogstashStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// LogstashList contains a list of Logstash +type LogstashList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Logstash `json:"items"` +} + + +func (l *Logstash) ServiceAccountName() string { + return l.Spec.ServiceAccountName +} + +func (l *Logstash) SecureSettings() []commonv1.SecretSource { + return l.Spec.SecureSettings +} + +// IsMarkedForDeletion returns true if the Logstash is going to be deleted +func (l *Logstash) IsMarkedForDeletion() bool { + return !l.DeletionTimestamp.IsZero() +} + +// GetObservedGeneration will return the observedGeneration from the Elastic Logstash's status. +func (l *Logstash) GetObservedGeneration() int64 { + return l.Status.ObservedGeneration +} + +func init() { + SchemeBuilder.Register(&Logstash{}, &LogstashList{}) +} diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go new file mode 100644 index 0000000000..84a9692840 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -0,0 +1,36 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + common_name "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/name" +) + +const ( + httpServiceSuffix = "http" + configSuffix = "config" +) + +// Namer is a Namer that is configured with the defaults for resources related to an Agent resource. +var Namer = common_name.NewNamer("ls") + +// ConfigSecretName returns the name of a secret used to storage Logstash configuration data. +func ConfigSecretName(name string) string { + return Namer.Suffix(name, configSuffix) +} + +func ConfigMapName(name string) string { + return Namer.Suffix(name, "configmap") +} + +// Name returns the name of Logstash. +func Name(name string) string { + return Namer.Suffix(name) +} + +// HTTPServiceName returns the name of the HTTP service for a given Logstash name. +func HTTPServiceName(name string) string { + return Namer.Suffix(name, httpServiceSuffix) +} diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go new file mode 100644 index 0000000000..019b482c04 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -0,0 +1,56 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/util/validation/field" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" +) + +var ( + defaultChecks = []func(*Logstash) field.ErrorList{ + checkNoUnknownFields, + checkNameLength, + checkSupportedVersion, + checkSingleConfigSource, + } + + updateChecks = []func(old, curr *Logstash) field.ErrorList{ + checkNoDowngrade, + } +) + +func checkNoUnknownFields(a *Logstash) field.ErrorList { + return commonv1.NoUnknownFields(a, a.ObjectMeta) +} + +func checkNameLength(a *Logstash) field.ErrorList { + return commonv1.CheckNameLength(a) +} + +func checkSupportedVersion(a *Logstash) field.ErrorList { + return commonv1.CheckSupportedStackVersion(a.Spec.Version, version.SupportedLogstashVersions) +} + +func checkNoDowngrade(prev, curr *Logstash) field.ErrorList { + if commonv1.IsConfiguredToAllowDowngrades(curr) { + return nil + } + return commonv1.CheckNoDowngrade(prev.Spec.Version, curr.Spec.Version) +} + +func checkSingleConfigSource(a *Logstash) field.ErrorList { + if a.Spec.Config != nil && a.Spec.ConfigRef != nil { + msg := "Specify at most one of [`config`, `configRef`], not both" + return field.ErrorList{ + field.Forbidden(field.NewPath("spec").Child("config"), msg), + field.Forbidden(field.NewPath("spec").Child("configRef"), msg), + } + } + + return nil +} \ No newline at end of file diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go new file mode 100644 index 0000000000..1f9bed70b4 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -0,0 +1,88 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "errors" + + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" + "sigs.k8s.io/controller-runtime/pkg/webhook" + + ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" +) + +const ( + // webhookPath is the HTTP path for the Elastic Logstash validating webhook. + webhookPath = "/validate-logstash-k8s-elastic-co-v1alpha1-logstash" +) + +var ( + groupKind = schema.GroupKind{Group: SchemeGroupVersion.Group, Kind: Kind} + validationLog = ulog.Log.WithName("logstash-v1alpha1-validation") +) + +// +kubebuilder:webhook:path=/validate-logstash-k8s-elastic-co-v1alpha1-logstash,mutating=false,failurePolicy=ignore,groups=logstash.k8s.elastic.co,resources=logstashs,verbs=create;update,versions=v1alpha1,name=elastic-logstash-validation-v1alpha1.k8s.elastic.co,sideEffects=None,admissionReviewVersions=v1;v1beta1,matchPolicy=Exact + +var _ webhook.Validator = &Logstash{} + +// ValidateCreate is called by the validating webhook to validate the create operation. +// Satisfies the webhook.Validator interface. +func (a *Logstash) ValidateCreate() error { + validationLog.V(1).Info("Validate create", "name", a.Name) + return a.validate(nil) +} + +// ValidateDelete is called by the validating webhook to validate the delete operation. +// Satisfies the webhook.Validator interface. +func (a *Logstash) ValidateDelete() error { + validationLog.V(1).Info("Validate delete", "name", a.Name) + return nil +} + +// ValidateUpdate is called by the validating webhook to validate the update operation. +// Satisfies the webhook.Validator interface. +func (a *Logstash) ValidateUpdate(old runtime.Object) error { + validationLog.V(1).Info("Validate update", "name", a.Name) + oldObj, ok := old.(*Logstash) + if !ok { + return errors.New("cannot cast old object to Logstash type") + } + + return a.validate(oldObj) +} + +// WebhookPath returns the HTTP path used by the validating webhook. +func (a *Logstash) WebhookPath() string { + return webhookPath +} + +func (a *Logstash) validate(old *Logstash) error { + var errors field.ErrorList + if old != nil { + for _, uc := range updateChecks { + if err := uc(old, a); err != nil { + errors = append(errors, err...) + } + } + + if len(errors) > 0 { + return apierrors.NewInvalid(groupKind, a.Name, errors) + } + } + + for _, dc := range defaultChecks { + if err := dc(a); err != nil { + errors = append(errors, err...) + } + } + + if len(errors) > 0 { + return apierrors.NewInvalid(groupKind, a.Name, errors) + } + return nil +} diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 0000000000..cf5c388da8 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,127 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Logstash) DeepCopyInto(out *Logstash) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Logstash. +func (in *Logstash) DeepCopy() *Logstash { + if in == nil { + return nil + } + out := new(Logstash) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Logstash) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashList) DeepCopyInto(out *LogstashList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Logstash, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashList. +func (in *LogstashList) DeepCopy() *LogstashList { + if in == nil { + return nil + } + out := new(LogstashList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *LogstashList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { + *out = *in + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = (*in).DeepCopy() + } + if in.ConfigRef != nil { + in, out := &in.ConfigRef, &out.ConfigRef + *out = new(v1.ConfigSource) + **out = **in + } + in.PodTemplate.DeepCopyInto(&out.PodTemplate) + if in.SecureSettings != nil { + in, out := &in.SecureSettings, &out.SecureSettings + *out = make([]v1.SecretSource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.RevisionHistoryLimit != nil { + in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit + *out = new(int32) + **out = **in + } + in.HTTP.DeepCopyInto(&out.HTTP) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashSpec. +func (in *LogstashSpec) DeepCopy() *LogstashSpec { + if in == nil { + return nil + } + out := new(LogstashSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashStatus) DeepCopyInto(out *LogstashStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashStatus. +func (in *LogstashStatus) DeepCopy() *LogstashStatus { + if in == nil { + return nil + } + out := new(LogstashStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/controller/common/container/container.go b/pkg/controller/common/container/container.go index 1730738122..5056dcc4cc 100644 --- a/pkg/controller/common/container/container.go +++ b/pkg/controller/common/container/container.go @@ -40,6 +40,7 @@ const ( PacketbeatImage Image = "beats/packetbeat" AgentImage Image = "beats/elastic-agent" MapsImage Image = "elastic-maps-service/elastic-maps-server-ubi8" + LogstashImage Image = "logstash/logstash" ) // ImageRepository returns the full container image name by concatenating the current container registry and the image path with the given version. diff --git a/pkg/controller/common/container/defaulter.go b/pkg/controller/common/container/defaulter.go index c007b0be79..0b03d42aa0 100644 --- a/pkg/controller/common/container/defaulter.go +++ b/pkg/controller/common/container/defaulter.go @@ -96,6 +96,13 @@ func (d Defaulter) WithReadinessProbe(readinessProbe *corev1.Probe) Defaulter { return d } +func (d Defaulter) WithLivenessProbe(livenessProbe *corev1.Probe) Defaulter { + if d.base.LivenessProbe == nil { + d.base.LivenessProbe = livenessProbe + } + return d +} + // envExists checks if an env var with the given name already exists in the provided slice. func (d Defaulter) envExists(name string) bool { for _, v := range d.base.Env { diff --git a/pkg/controller/common/defaults/pod_template.go b/pkg/controller/common/defaults/pod_template.go index 81cfea9331..073223a0c0 100644 --- a/pkg/controller/common/defaults/pod_template.go +++ b/pkg/controller/common/defaults/pod_template.go @@ -121,6 +121,12 @@ func (b *PodTemplateBuilder) WithReadinessProbe(readinessProbe corev1.Probe) *Po return b } +// WithLivenessProbe sets up the given liveness probe, unless already provided in the template. +func (b *PodTemplateBuilder) WithLivenessProbe(livenessProbe corev1.Probe) *PodTemplateBuilder { + b.containerDefaulter.WithLivenessProbe(&livenessProbe) + return b +} + // WithAffinity sets a default affinity, unless already provided in the template. // An empty affinity in the spec is not overridden. func (b *PodTemplateBuilder) WithAffinity(affinity *corev1.Affinity) *PodTemplateBuilder { diff --git a/pkg/controller/common/scheme/scheme.go b/pkg/controller/common/scheme/scheme.go index fb51fe2d66..69b4706966 100644 --- a/pkg/controller/common/scheme/scheme.go +++ b/pkg/controller/common/scheme/scheme.go @@ -5,6 +5,7 @@ package scheme import ( + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "sync" "k8s.io/apimachinery/pkg/runtime" @@ -55,6 +56,7 @@ func SetupScheme() { agentv1alpha1.AddToScheme, emsv1alpha1.AddToScheme, policyv1alpha1.AddToScheme, + logstashv1alpha1.AddToScheme, } mustAddSchemeOnce(&addToScheme, schemes) } @@ -72,6 +74,7 @@ func SetupV1beta1Scheme() { entv1beta1.AddToScheme, beatv1beta1.AddToScheme, agentv1alpha1.AddToScheme, + logstashv1alpha1.AddToScheme, } mustAddSchemeOnce(&addToSchemeV1beta1, schemes) } diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index 0b9e379a4f..9258310a74 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,6 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 3, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. diff --git a/pkg/controller/elasticsearch/user/roles.go b/pkg/controller/elasticsearch/user/roles.go index 4688dea3b1..dded5f09ce 100644 --- a/pkg/controller/elasticsearch/user/roles.go +++ b/pkg/controller/elasticsearch/user/roles.go @@ -42,6 +42,8 @@ const ( FleetAdminUserRole = "eck_fleet_admin_user_role" + LogstashUserRole = "eck_logstash_user_role_v80" + // V70 indicates version 7.0 V70 = "v70" @@ -147,6 +149,15 @@ var ( }, }, }, + LogstashUserRole: esclient.Role{ + Cluster: []string{"monitor", "manage_ilm", "manage_ml", "read_ilm", "cluster:admin/ingest/pipeline/get"}, + Indices: []esclient.IndexRole{ + { + Names: []string{"logstash-*"}, + Privileges: []string{"manage", "read", "create_doc", "view_index_metadata", "create_index"}, + }, + }, + }, } ) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go new file mode 100644 index 0000000000..c27b754c25 --- /dev/null +++ b/pkg/controller/logstash/config.go @@ -0,0 +1,123 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" + ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" + "hash" + apierrors "k8s.io/apimachinery/pkg/api/errors" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + +func reconcileConfig(params Params, configHash hash.Hash) *reconciler.Results { + defer tracing.Span(¶ms.Context)() + results := reconciler.NewResult(params.Context) + + cfgBytes, err := buildConfig(params) + if err != nil { + return results.WithError(err) + } + + expected := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: params.Logstash.Namespace, + Name: logstashv1alpha1.ConfigSecretName(params.Logstash.Name), + Labels: labels.AddCredentialsLabel(params.Logstash.GetIdentityLabels()), + }, + Data: map[string][]byte{ + LogstashConfigFileName: cfgBytes, + }, + } + + if _, err = reconciler.ReconcileSecret(params.Context, params.Client, expected, ¶ms.Logstash); err != nil { + return results.WithError(err) + } + + _, _ = configHash.Write(cfgBytes) + + return results +} + +func buildConfig(params Params) ([]byte, error) { + existingCfg, err := getExistingConfig(params.Context, params.Client, params.Logstash) + if err != nil { + return nil, err + } + + userProvidedCfg, err := getUserConfig(params) + if err != nil { + return nil, err + } + + cfg, err := defaultConfig() + if err != nil { + return nil, err + } + + // merge with user settings last so they take precedence + if err = cfg.MergeWith(existingCfg, userProvidedCfg); err != nil { + return nil, err + } + + return cfg.Render() +} + +// getExistingConfig retrieves the canonical config, if one exists +func getExistingConfig(ctx context.Context, client k8s.Client, logstash logstashv1alpha1.Logstash) (*settings.CanonicalConfig, error) { + var secret corev1.Secret + key := types.NamespacedName{ + Namespace: logstash.Namespace, + Name: logstashv1alpha1.ConfigSecretName(logstash.Name), + } + err := client.Get(context.Background(), key, &secret) + if err != nil && apierrors.IsNotFound(err) { + ulog.FromContext(ctx).V(1).Info("Logstash config secret does not exist", "namespace", logstash.Namespace, "name", logstash.Name) + return nil, nil + } else if err != nil { + return nil, err + } + + rawCfg, exists := secret.Data[LogstashConfigFileName] + if !exists { + return nil, nil + } + + cfg, err := settings.ParseConfig(rawCfg) + if err != nil { + return nil, err + } + + return cfg, nil +} + +// getUserConfig extracts the config either from the spec `config` field or from the Secret referenced by spec +// `configRef` field. +func getUserConfig(params Params) (*settings.CanonicalConfig, error) { + if params.Logstash.Spec.Config != nil { + return settings.NewCanonicalConfigFrom(params.Logstash.Spec.Config.Data) + } + return common.ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.ConfigRef, LogstashConfigFileName) +} + +// TODO: remove testing value +func defaultConfig() (*settings.CanonicalConfig, error) { + settingsMap := map[string]interface{}{ + "node.name": "test", + } + + return settings.MustCanonicalConfig(settingsMap), nil +} \ No newline at end of file diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go new file mode 100644 index 0000000000..250473644b --- /dev/null +++ b/pkg/controller/logstash/driver.go @@ -0,0 +1,133 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + "hash/fnv" + + "github.com/go-logr/logr" + corev1 "k8s.io/api/core/v1" + "k8s.io/client-go/tools/record" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" +) + +// Params are a set of parameters used during internal reconciliation of Logstash. +type Params struct { + Context context.Context + + Client k8s.Client + EventRecorder record.EventRecorder + Watches watches.DynamicWatches + + Logstash logstashv1alpha1.Logstash + Status logstashv1alpha1.LogstashStatus + + OperatorParams operator.Parameters +} + +// K8sClient returns the Kubernetes client. +func (p Params) K8sClient() k8s.Client { + return p.Client +} + +// Recorder returns the Kubernetes event recorder. +func (p Params) Recorder() record.EventRecorder { + return p.EventRecorder +} + +// DynamicWatches returns the set of stateful dynamic watches used during reconciliation. +func (p Params) DynamicWatches() watches.DynamicWatches { + return p.Watches +} + +// GetPodTemplate returns the configured pod template for the associated Elastic Logstash. +func (p *Params) GetPodTemplate() corev1.PodTemplateSpec { + return p.Logstash.Spec.PodTemplate +} + +// Logger returns the configured logger for use during reconciliation. +func (p *Params) Logger() logr.Logger { + return log.FromContext(p.Context) +} + +func newStatus(logstash logstashv1alpha1.Logstash) logstashv1alpha1.LogstashStatus { + status := logstash.Status + status.ObservedGeneration = logstash.Generation + return status +} + +func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.LogstashStatus) { + defer tracing.Span(¶ms.Context)() + results := reconciler.NewResult(params.Context) + + svc, err := common.ReconcileService(params.Context, params.Client, newService(params.Logstash), ¶ms.Logstash) + if err != nil { + return results.WithError(err), params.Status + } + + _, results = certificates.Reconciler{ + K8sClient: params.Client, + DynamicWatches: params.Watches, + Owner: ¶ms.Logstash, + TLSOptions: params.Logstash.Spec.HTTP.TLS, + Namer: logstashv1alpha1.Namer, + Labels: params.Logstash.GetIdentityLabels(), + Services: []corev1.Service{*svc}, + GlobalCA: params.OperatorParams.GlobalCA, + CACertRotation: params.OperatorParams.CACertRotation, + CertRotation: params.OperatorParams.CertRotation, + GarbageCollectSecrets: true, + }.ReconcileCAAndHTTPCerts(params.Context) + if results.HasError() { + _, err := results.Aggregate() + k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + return results, params.Status + } + + configHash := fnv.New32a() + + if res := reconcileConfig(params, configHash); res.HasError() { + return results.WithResults(res), params.Status + } + + podTemplate, err := buildPodTemplate(params, configHash) + if err != nil { + return results.WithError(err), params.Status + } + return reconcileStatefulSet(params, podTemplate) +} + +func newService(logstash logstashv1alpha1.Logstash) *corev1.Service { + svc := corev1.Service{ + ObjectMeta: logstash.Spec.HTTP.Service.ObjectMeta, + Spec: logstash.Spec.HTTP.Service.Spec, + } + + svc.ObjectMeta.Namespace = logstash.Namespace + svc.ObjectMeta.Name = logstashv1alpha1.HTTPServiceName(logstash.Name) + + labels := logstash.GetIdentityLabels() + ports := []corev1.ServicePort{ + { + Name: logstash.Spec.HTTP.Protocol(), + Protocol: corev1.ProtocolTCP, + Port: network.HTTPPort, + }, + } + return defaults.SetServiceDefaults(&svc, labels, labels, ports) +} diff --git a/pkg/controller/logstash/init_configuration.go b/pkg/controller/logstash/init_configuration.go new file mode 100644 index 0000000000..a85b118568 --- /dev/null +++ b/pkg/controller/logstash/init_configuration.go @@ -0,0 +1,75 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" +) + +const ( + InitContainerConfigVolumeMountPath = "/mnt/elastic-internal/logstash-config-local" + InitConfigContainerName = "elastic-internal-init-config" + + // InitConfigScript is a small bash script to prepare the logstash configuration directory + InitConfigScript = `#!/usr/bin/env bash +set -eux + +init_config_initialized_flag=` + InitContainerConfigVolumeMountPath + `/elastic-internal-init-config.ok + +if [[ -f "${init_config_initialized_flag}" ]]; then + echo "Logstash configuration already initialized." + exit 0 +fi + +echo "Setup Logstash configuration" + +mount_path=` + InitContainerConfigVolumeMountPath + ` + +for f in /usr/share/logstash/config/*.*; do + filename=$(basename $f) + if [[ ! -f "$mount_path/$filename" ]]; then + cp $f $mount_path + fi +done + +touch "${init_config_initialized_flag}" +echo "Logstash configuration successfully prepared." +` +) + +// initConfigContainer returns an init container that executes a bash script to prepare the logstash config directory. +// The script copy config files from /use/share/logstash/config to /mnt/elastic-internal/logstash-config/ +// TODO may be able to solve env2yaml permission issue with initContainer +func initConfigContainer() corev1.Container { + privileged := false + + return corev1.Container{ + // Image will be inherited from pod template defaults + ImagePullPolicy: corev1.PullIfNotPresent, + Name: InitConfigContainerName, + SecurityContext: &corev1.SecurityContext{ + Privileged: &privileged, + }, + Command: []string{"/usr/bin/env", "bash", "-c", InitConfigScript}, + VolumeMounts: []corev1.VolumeMount{ + { + MountPath: InitContainerConfigVolumeMountPath, + Name: ConfigVolumeName, + }, + }, + Resources: corev1.ResourceRequirements{ + Requests: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("50Mi"), + corev1.ResourceCPU: resource.MustParse("0.1"), + }, + Limits: map[corev1.ResourceName]resource.Quantity{ + // Memory limit should be at least 12582912 when running with CRI-O + corev1.ResourceMemory: resource.MustParse("50Mi"), + corev1.ResourceCPU: resource.MustParse("0.1"), + }, + }, + } +} diff --git a/pkg/controller/logstash/labels.go b/pkg/controller/logstash/labels.go new file mode 100644 index 0000000000..f69c95902b --- /dev/null +++ b/pkg/controller/logstash/labels.go @@ -0,0 +1,16 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +const ( + // TypeLabelValue represents the Logstash type. + TypeLabelValue = "logstash" + + // NameLabelName used to represent an Logstash in k8s resources + NameLabelName = "logstash.k8s.elastic.co/name" + + // NamespaceLabelName used to represent an Logstash in k8s resources + NamespaceLabelName = "logstash.k8s.elastic.co/namespace" +) diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go new file mode 100644 index 0000000000..9660517915 --- /dev/null +++ b/pkg/controller/logstash/logstash_controller.go @@ -0,0 +1,199 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/tools/record" + "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/source" + + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/keystore" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + logconf "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" +) + +const ( + controllerName = "logstash-controller" +) + +// Add creates a new Logstash Controller and adds it to the Manager with default RBAC. +// The Manager will set fields on the Controller and Start it when the Manager is Started. +func Add(mgr manager.Manager, params operator.Parameters) error { + r := newReconciler(mgr, params) + c, err := common.NewController(mgr, controllerName, r, params) + if err != nil { + return err + } + return addWatches(c, r) +} + +// newReconciler returns a new reconcile.Reconciler. +func newReconciler(mgr manager.Manager, params operator.Parameters) *ReconcileLogstash { + client := mgr.GetClient() + return &ReconcileLogstash{ + Client: client, + recorder: mgr.GetEventRecorderFor(controllerName), + dynamicWatches: watches.NewDynamicWatches(), + Parameters: params, + } +} + +// addWatches adds watches for all resources this controller cares about +func addWatches(c controller.Controller, r *ReconcileLogstash) error { + // Watch for changes to Logstash + if err := c.Watch(&source.Kind{Type: &logstashv1alpha1.Logstash{}}, &handler.EnqueueRequestForObject{}); err != nil { + return err + } + + // Watch StatefulSets + if err := c.Watch( + &source.Kind{Type: &appsv1.StatefulSet{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &logstashv1alpha1.Logstash{}, + }, + ); err != nil { + return err + } + + // Watch Pods, to ensure `status.version` is correctly reconciled on any change. + // Watching StatefulSets only may lead to missing some events. + if err := watches.WatchPods(c, NameLabelName); err != nil { + return err + } + + // Watch services + if err := c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &logstashv1alpha1.Logstash{}, + }); err != nil { + return err + } + + // Watch owned and soft-owned secrets + if err := c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &logstashv1alpha1.Logstash{}, + }); err != nil { + return err + } + if err := watches.WatchSoftOwnedSecrets(c, logstashv1alpha1.Kind); err != nil { + return err + } + + // Watch dynamically referenced Secrets + return c.Watch(&source.Kind{Type: &corev1.Secret{}}, r.dynamicWatches.Secrets) +} + +var _ reconcile.Reconciler = &ReconcileLogstash{} + +// ReconcileLogstash reconciles a Logstash object +type ReconcileLogstash struct { + k8s.Client + recorder record.EventRecorder + dynamicWatches watches.DynamicWatches + operator.Parameters + // iteration is the number of times this controller has run its Reconcile method + iteration uint64 +} + +// Reconcile reads that state of the cluster for a Logstash object and makes changes based on the state read +// and what is in the Logstash.Spec +// Automatically generate RBAC rules to allow the Controller to read and write StatefulSets +// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=apps,resources=statefulsets/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=logstash.k8s.elastic.co,resources=logstashes,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=logstash.k8s.elastic.co,resources=logstashes/status,verbs=get;update;patch +func (r *ReconcileLogstash) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { + ctx = common.NewReconciliationContext(ctx, &r.iteration, r.Tracer, controllerName, "logstash_name", request) + defer common.LogReconciliationRun(logconf.FromContext(ctx))() + defer tracing.EndContextTransaction(ctx) + + logstash := &logstashv1alpha1.Logstash{} + if err := r.Client.Get(ctx, request.NamespacedName, logstash); err != nil { + if apierrors.IsNotFound(err) { + return reconcile.Result{}, r.onDelete(ctx, request.NamespacedName) + } + return reconcile.Result{}, tracing.CaptureError(ctx, err) + } + + if common.IsUnmanaged(ctx, logstash) { + logconf.FromContext(ctx).Info("Object is currently not managed by this controller. Skipping reconciliation") + return reconcile.Result{}, nil + } + + if logstash.IsMarkedForDeletion() { + return reconcile.Result{}, nil + } + + results, status := r.doReconcile(ctx, *logstash) + + if err := updateStatus(ctx, *logstash, r.Client, status); err != nil { + if apierrors.IsConflict(err) { + return results.WithResult(reconcile.Result{Requeue: true}).Aggregate() + } + results = results.WithError(err) + } + + result, err := results.Aggregate() + k8s.EmitErrorEvent(r.recorder, err, logstash, events.EventReconciliationError, "Reconciliation error: %v", err) + + return result, err +} + +func (r *ReconcileLogstash) doReconcile(ctx context.Context, logstash logstashv1alpha1.Logstash) (*reconciler.Results, logstashv1alpha1.LogstashStatus) { + defer tracing.Span(&ctx)() + results := reconciler.NewResult(ctx) + status := newStatus(logstash) + + // Run basic validations as a fallback in case webhook is disabled. + if err := r.validate(ctx, logstash); err != nil { + results = results.WithError(err) + return results, status + } + + return internalReconcile(Params{ + Context: ctx, + Client: r.Client, + EventRecorder: r.recorder, + Watches: r.dynamicWatches, + Logstash: logstash, + Status: status, + OperatorParams: r.Parameters, + }) +} + +func (r *ReconcileLogstash) validate(ctx context.Context, logstash logstashv1alpha1.Logstash) error { + defer tracing.Span(&ctx)() + + // Run create validations only as update validations require old object which we don't have here. + if err := logstash.ValidateCreate(); err != nil { + logconf.FromContext(ctx).Error(err, "Validation failed") + k8s.EmitErrorEvent(r.recorder, err, &logstash, events.EventReasonValidation, err.Error()) + return tracing.CaptureError(ctx, err) + } + return nil +} + +func (r *ReconcileLogstash) onDelete(ctx context.Context, obj types.NamespacedName) error { + r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj)) + r.dynamicWatches.Secrets.RemoveHandlerForKey(common.ConfigRefWatchName(obj)) + return reconciler.GarbageCollectSoftOwnedSecrets(ctx, r.Client, obj, logstashv1alpha1.Kind) +} diff --git a/pkg/controller/logstash/network/ports.go b/pkg/controller/logstash/network/ports.go new file mode 100644 index 0000000000..197dae5249 --- /dev/null +++ b/pkg/controller/logstash/network/ports.go @@ -0,0 +1,10 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package network + +const ( + // HTTPPort is the (default) API port used by Logstash + HTTPPort = 9600 +) diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go new file mode 100644 index 0000000000..1cc1c589d5 --- /dev/null +++ b/pkg/controller/logstash/pod.go @@ -0,0 +1,147 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "fmt" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/volume" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/maps" + "hash" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/intstr" + "path" +) + +const ( + ContainerName = "logstash" + + ConfigVolumeName = "config" + ConfigMountPath = "/usr/share/logstash/config" + + LogstashConfigVolumeName = "logstash" + LogstashConfigFileName = "logstash.yml" + + // ConfigHashAnnotationName is an annotation used to store the Logstash config hash. + ConfigHashAnnotationName = "logstash.k8s.elastic.co/config-hash" + + // VersionLabelName is a label used to track the version of a Logstash Pod. + VersionLabelName = "logstash.k8s.elastic.co/version" +) + +var ( + DefaultResources = corev1.ResourceRequirements{ + Limits: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("2Gi"), + corev1.ResourceCPU: resource.MustParse("2000m"), + }, + Requests: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("2Gi"), + corev1.ResourceCPU: resource.MustParse("1000m"), + }, + } +) + +func buildPodTemplate(params Params, configHash hash.Hash32) (corev1.PodTemplateSpec, error) { + defer tracing.Span(¶ms.Context)() + spec := ¶ms.Logstash.Spec + builder := defaults.NewPodTemplateBuilder(params.GetPodTemplate(), ContainerName) + vols := []volume.VolumeLike{ + // volume with logstash configuration file + volume.NewSecretVolume( + logstashv1alpha1.ConfigSecretName(params.Logstash.Name), + LogstashConfigVolumeName, + path.Join(ConfigMountPath, LogstashConfigFileName), + LogstashConfigFileName, + 0644), + } + + labels := maps.Merge(params.Logstash.GetIdentityLabels(), map[string]string{ + VersionLabelName: spec.Version}) + + annotations := map[string]string{ + ConfigHashAnnotationName: fmt.Sprint(configHash.Sum32()), + } + + ports := getDefaultContainerPorts(params.Logstash) + + builder = builder. + WithResources(DefaultResources). + WithLabels(labels). + WithAnnotations(annotations). + WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). + WithAutomountServiceAccountToken(). + WithPorts(ports). + WithReadinessProbe(readinessProbe(false)). + WithLivenessProbe(livenessProbe(false)). + WithVolumeLikes(vols...) + + //TODO integrate with api.ssl.enabled + if params.Logstash.Spec.HTTP.TLS.Enabled() { + httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) + builder. + WithVolumes(httpVol.Volume()). + WithVolumeMounts(httpVol.VolumeMount()) + } + + return builder.PodTemplate, nil +} + + +func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.ContainerPort { + return []corev1.ContainerPort{ + {Name: logstash.Spec.HTTP.Protocol(), ContainerPort: int32(network.HTTPPort), Protocol: corev1.ProtocolTCP}, + } +} + +// readinessProbe is the readiness probe for the Logstash container +func readinessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 30, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} + +// livenessProbe is the liveness probe for the Logstash container +func livenessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 60, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go new file mode 100644 index 0000000000..edc31631bb --- /dev/null +++ b/pkg/controller/logstash/reconcile.go @@ -0,0 +1,90 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/sset" + "reflect" + + corev1 "k8s.io/api/core/v1" + "k8s.io/client-go/kubernetes/scheme" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + + "github.com/pkg/errors" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + + +func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*reconciler.Results, logstashv1alpha1.LogstashStatus){ + defer tracing.Span(¶ms.Context)() + results := reconciler.NewResult(params.Context) + + s, _ := sset.New(sset.Params{ + Name: logstashv1alpha1.Name(params.Logstash.Name), + Namespace: params.Logstash.Namespace, + ServiceName: logstashv1alpha1.HTTPServiceName(params.Logstash.Name), + Selector: params.Logstash.GetIdentityLabels(), + Labels: params.Logstash.GetIdentityLabels(), + PodTemplateSpec: podTemplate, + Replicas: params.Logstash.Spec.Count, + RevisionHistoryLimit: params.Logstash.Spec.RevisionHistoryLimit, + }) + if err := controllerutil.SetControllerReference(¶ms.Logstash, &s, scheme.Scheme); err != nil { + return results.WithError(err), params.Status + } + + reconciled, err := sset.Reconcile(params.Context, params.Client, s, ¶ms.Logstash) + if err != nil { + return results.WithError(err), params.Status + } + + var status logstashv1alpha1.LogstashStatus + if status, err = calculateStatus(¶ms, reconciled.Status.ReadyReplicas, reconciled.Status.Replicas); err != nil { + err = errors.Wrap(err, "while calculating status") + } + + return results.WithError(err), status +} + +// ReconciliationParams are the parameters used during an Elastic Logstash's reconciliation. +type ReconciliationParams struct { + ctx context.Context + client k8s.Client + logstash logstashv1alpha1.Logstash + podTemplate corev1.PodTemplateSpec +} + +// calculateStatus will calculate a new status from the state of the pods within the k8s cluster +// and will return any error encountered. +func calculateStatus(params *Params, ready, desired int32) (logstashv1alpha1.LogstashStatus, error) { + logstash := params.Logstash + status := params.Status + + pods, err := k8s.PodsMatchingLabels(params.Client, logstash.Namespace, map[string]string{NameLabelName: logstash.Name}) + if err != nil { + return status, err + } + + status.Version = common.LowestVersionFromPods(params.Context, status.Version, pods, VersionLabelName) + status.AvailableNodes = ready + status.ExpectedNodes = desired + return status, nil +} + +// updateStatus will update the Elastic Logstash's status within the k8s cluster, using the given Elastic Logstash and status. +func updateStatus(ctx context.Context, logstash logstashv1alpha1.Logstash, client client.Client, status logstashv1alpha1.LogstashStatus) error { + if reflect.DeepEqual(logstash.Status, status) { + return nil + } + logstash.Status = status + return common.UpdateStatus(ctx, client, &logstash) +} diff --git a/pkg/controller/logstash/sset/sset.go b/pkg/controller/logstash/sset/sset.go new file mode 100644 index 0000000000..935ec1ed34 --- /dev/null +++ b/pkg/controller/logstash/sset/sset.go @@ -0,0 +1,93 @@ +package sset + +import ( + "context" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" + + appsv1 "k8s.io/api/apps/v1" + + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/hash" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/maps" +) + +type Params struct { + Name string + Namespace string + ServiceName string + Selector map[string]string + Labels map[string]string + PodTemplateSpec corev1.PodTemplateSpec + Replicas int32 + RevisionHistoryLimit *int32 +} + +func New(params Params) (appsv1.StatefulSet, error) { + + sset := appsv1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: params.Name, + Namespace: params.Namespace, + Labels: params.Labels, + }, + Spec: appsv1.StatefulSetSpec{ + UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ + Type: appsv1.RollingUpdateStatefulSetStrategyType, + }, + // we don't care much about pods creation ordering, and manage deletion ordering ourselves, + // so we're fine with the StatefulSet controller spawning all pods in parallel + PodManagementPolicy: appsv1.ParallelPodManagement, + RevisionHistoryLimit: params.RevisionHistoryLimit, + // build a headless service per StatefulSet, matching the StatefulSet labels + ServiceName: params.ServiceName, + Selector: &metav1.LabelSelector{ + MatchLabels: params.Selector, + }, + + Replicas: ¶ms.Replicas, + Template: params.PodTemplateSpec, + }, + } + + // store a hash of the sset resource in its labels for comparison purposes + sset.Labels = hash.SetTemplateHashLabel(sset.Labels, sset.Spec) + + return sset, nil +} + +// Reconcile creates or updates the expected StatefulSet. +func Reconcile(ctx context.Context, c k8s.Client, expected appsv1.StatefulSet, owner client.Object) (appsv1.StatefulSet, error) { + var reconciled appsv1.StatefulSet + + err := reconciler.ReconcileResource(reconciler.Params{ + Context: ctx, + Client: c, + Owner: owner, + Expected: &expected, + Reconciled: &reconciled, + NeedsUpdate: func() bool { + // expected labels or annotations not there + return !maps.IsSubset(expected.Labels, reconciled.Labels) || + !maps.IsSubset(expected.Annotations, reconciled.Annotations) || + // different spec + !EqualTemplateHashLabels(expected, reconciled) + }, + UpdateReconciled: func() { + // override annotations and labels with expected ones + // don't remove additional values in reconciled that may have been defaulted or + // manually set by the user on the existing resource + reconciled.Labels = maps.Merge(reconciled.Labels, expected.Labels) + reconciled.Annotations = maps.Merge(reconciled.Annotations, expected.Annotations) + reconciled.Spec = expected.Spec + }, + }) + return reconciled, err +} + +// EqualTemplateHashLabels reports whether actual and expected StatefulSets have the same template hash label value. +func EqualTemplateHashLabels(expected, actual appsv1.StatefulSet) bool { + return expected.Labels[hash.TemplateHashLabelName] == actual.Labels[hash.TemplateHashLabelName] +} From 02a545133076a8df9df602b960dd7c579433c4ad Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Fri, 10 Feb 2023 14:19:12 -0500 Subject: [PATCH 036/160] Comment out certs for HTTPS for now --- config/crds/v1/all-crds.yaml | 4 +- .../logstash.k8s.elastic.co_logstashes.yaml | 4 +- .../eck-operator-crds/templates/all-crds.yaml | 4 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 13 +++--- .../v1alpha1/zz_generated.deepcopy.go | 12 +++--- pkg/controller/logstash/driver.go | 43 ++++++++++--------- pkg/controller/logstash/pod.go | 14 +++--- pkg/controller/logstash/sset/sset.go | 1 - 8 files changed, 48 insertions(+), 47 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index ab495fab43..d6a285a6dc 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9118,8 +9118,8 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Agent - in Fleet mode with Fleet Server enabled. + description: HTTP holds the HTTP layer configuration for the Logstash + Metrics API properties: service: description: Service defines the template for the associated Kubernetes diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 861b378eb4..1d86f803e1 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -74,8 +74,8 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Agent - in Fleet mode with Fleet Server enabled. + description: HTTP holds the HTTP layer configuration for the Logstash + Metrics API properties: service: description: Service defines the template for the associated Kubernetes diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index b9fab1fb80..347de6c534 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9172,8 +9172,8 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Agent - in Fleet mode with Fleet Server enabled. + description: HTTP holds the HTTP layer configuration for the Logstash + Metrics API properties: service: description: Service defines the template for the associated Kubernetes diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index d948fd2b96..239f0348cc 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -38,9 +38,16 @@ type LogstashSpec struct { // +kubebuilder:validation:Optional ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"` + // HTTP holds the HTTP layer configuration for the Logstash Metrics API + // +kubebuilder:validation:Optional + HTTP commonv1.HTTPConfig `json:"http,omitempty"` + // PodTemplate provides customisation options for the Logstash pods. PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` + // RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. + RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` + // SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. // Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of // each SecureSetting. @@ -52,12 +59,6 @@ type LogstashSpec struct { // +kubebuilder:validation:Optional ServiceAccountName string `json:"serviceAccountName,omitempty"` - // RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. - RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` - - // HTTP holds the HTTP layer configuration for the Agent in Fleet mode with Fleet Server enabled. - // +kubebuilder:validation:Optional - HTTP commonv1.HTTPConfig `json:"http,omitempty"` } // LogstashStatus defines the observed state of Logstash diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index cf5c388da8..42ca5a613e 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -85,7 +85,13 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { *out = new(v1.ConfigSource) **out = **in } + in.HTTP.DeepCopyInto(&out.HTTP) in.PodTemplate.DeepCopyInto(&out.PodTemplate) + if in.RevisionHistoryLimit != nil { + in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit + *out = new(int32) + **out = **in + } if in.SecureSettings != nil { in, out := &in.SecureSettings, &out.SecureSettings *out = make([]v1.SecretSource, len(*in)) @@ -93,12 +99,6 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.RevisionHistoryLimit != nil { - in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit - *out = new(int32) - **out = **in - } - in.HTTP.DeepCopyInto(&out.HTTP) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashSpec. diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 250473644b..b0270bff24 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -7,9 +7,9 @@ package logstash import ( "context" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" "hash/fnv" "github.com/go-logr/logr" @@ -75,29 +75,30 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log defer tracing.Span(¶ms.Context)() results := reconciler.NewResult(params.Context) - svc, err := common.ReconcileService(params.Context, params.Client, newService(params.Logstash), ¶ms.Logstash) + _, err := common.ReconcileService(params.Context, params.Client, newService(params.Logstash), ¶ms.Logstash) if err != nil { return results.WithError(err), params.Status } - _, results = certificates.Reconciler{ - K8sClient: params.Client, - DynamicWatches: params.Watches, - Owner: ¶ms.Logstash, - TLSOptions: params.Logstash.Spec.HTTP.TLS, - Namer: logstashv1alpha1.Namer, - Labels: params.Logstash.GetIdentityLabels(), - Services: []corev1.Service{*svc}, - GlobalCA: params.OperatorParams.GlobalCA, - CACertRotation: params.OperatorParams.CACertRotation, - CertRotation: params.OperatorParams.CertRotation, - GarbageCollectSecrets: true, - }.ReconcileCAAndHTTPCerts(params.Context) - if results.HasError() { - _, err := results.Aggregate() - k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) - return results, params.Status - } + //_, results = certificates.Reconciler{ + // K8sClient: params.Client, + // DynamicWatches: params.Watches, + // Owner: ¶ms.Logstash, + // TLSOptions: params.Logstash.Spec.HTTP.TLS, + // Namer: logstashv1alpha1.Namer, + // Labels: params.Logstash.GetIdentityLabels(), + // Services: []corev1.Service{*svc}, + // GlobalCA: params.OperatorParams.GlobalCA, + // CACertRotation: params.OperatorParams.CACertRotation, + // CertRotation: params.OperatorParams.CertRotation, + // GarbageCollectSecrets: true, + //}.ReconcileCAAndHTTPCerts(params.Context) + // + //if results.HasError() { + // _, err := results.Aggregate() + // k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + // return results, params.Status + //} configHash := fnv.New32a() diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 1cc1c589d5..aba2483c7d 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -7,7 +7,7 @@ package logstash import ( "fmt" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" @@ -85,12 +85,12 @@ func buildPodTemplate(params Params, configHash hash.Hash32) (corev1.PodTemplate WithVolumeLikes(vols...) //TODO integrate with api.ssl.enabled - if params.Logstash.Spec.HTTP.TLS.Enabled() { - httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) - builder. - WithVolumes(httpVol.Volume()). - WithVolumeMounts(httpVol.VolumeMount()) - } + //if params.Logstash.Spec.HTTP.TLS.Enabled() { + // httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) + // builder. + // WithVolumes(httpVol.Volume()). + // WithVolumeMounts(httpVol.VolumeMount()) + //} return builder.PodTemplate, nil } diff --git a/pkg/controller/logstash/sset/sset.go b/pkg/controller/logstash/sset/sset.go index 935ec1ed34..650ad14f8a 100644 --- a/pkg/controller/logstash/sset/sset.go +++ b/pkg/controller/logstash/sset/sset.go @@ -26,7 +26,6 @@ type Params struct { } func New(params Params) (appsv1.StatefulSet, error) { - sset := appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ Name: params.Name, From b72182f3192b5a092e3149789c039b2ca7326d9a Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Fri, 10 Feb 2023 17:25:35 -0500 Subject: [PATCH 037/160] Fix up linter issus --- cmd/manager/main.go | 5 +- pkg/apis/logstash/v1alpha1/labels.go | 6 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 11 ++- pkg/controller/common/scheme/scheme.go | 3 +- pkg/controller/elasticsearch/user/roles.go | 11 --- pkg/controller/logstash/config.go | 14 ++-- pkg/controller/logstash/driver.go | 17 ++--- pkg/controller/logstash/init_configuration.go | 75 ------------------- .../logstash/logstash_controller.go | 3 +- pkg/controller/logstash/pod.go | 22 +++--- pkg/controller/logstash/reconcile.go | 14 +--- pkg/controller/logstash/sset/sset.go | 9 ++- 12 files changed, 52 insertions(+), 138 deletions(-) delete mode 100644 pkg/controller/logstash/init_configuration.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 16cf2c55cb..fa6cc484a8 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -8,8 +8,6 @@ import ( "context" "errors" "fmt" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "net/http" "net/http/pprof" "os" @@ -18,6 +16,9 @@ import ( "strings" "time" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + "github.com/go-logr/logr" "github.com/spf13/cobra" "github.com/spf13/viper" diff --git a/pkg/apis/logstash/v1alpha1/labels.go b/pkg/apis/logstash/v1alpha1/labels.go index 70e5fa8cf5..9d4a22f515 100644 --- a/pkg/apis/logstash/v1alpha1/labels.go +++ b/pkg/apis/logstash/v1alpha1/labels.go @@ -9,9 +9,9 @@ import ( ) // GetIdentityLabels will return the common Elastic assigned labels for Logstash -func (logstash* Logstash) GetIdentityLabels() map[string]string { +func (logstash *Logstash) GetIdentityLabels() map[string]string { return map[string]string{ - commonv1.TypeLabelName: "logstash", - "logstash.k8s.elastic.co/name": logstash.Name, + commonv1.TypeLabelName: "logstash", + "logstash.k8s.elastic.co/name": logstash.Name, } } diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 239f0348cc..47c12f4a87 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -5,9 +5,10 @@ package v1alpha1 import ( - commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) const ( @@ -21,7 +22,7 @@ type LogstashSpec struct { // Version of the Logstash. Version string `json:"version"` - Count int32 `json:"count,omitempty"` + Count int32 `json:"count,omitempty"` // Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. // +kubebuilder:validation:Optional @@ -58,7 +59,6 @@ type LogstashSpec struct { // Can only be used if ECK is enforcing RBAC on references. // +kubebuilder:validation:Optional ServiceAccountName string `json:"serviceAccountName,omitempty"` - } // LogstashStatus defines the observed state of Logstash @@ -94,8 +94,8 @@ type Logstash struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec LogstashSpec `json:"spec,omitempty"` - Status LogstashStatus `json:"status,omitempty"` + Spec LogstashSpec `json:"spec,omitempty"` + Status LogstashStatus `json:"status,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -107,7 +107,6 @@ type LogstashList struct { Items []Logstash `json:"items"` } - func (l *Logstash) ServiceAccountName() string { return l.Spec.ServiceAccountName } diff --git a/pkg/controller/common/scheme/scheme.go b/pkg/controller/common/scheme/scheme.go index 69b4706966..51ce53cdd3 100644 --- a/pkg/controller/common/scheme/scheme.go +++ b/pkg/controller/common/scheme/scheme.go @@ -5,9 +5,10 @@ package scheme import ( - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "sync" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" diff --git a/pkg/controller/elasticsearch/user/roles.go b/pkg/controller/elasticsearch/user/roles.go index dded5f09ce..4688dea3b1 100644 --- a/pkg/controller/elasticsearch/user/roles.go +++ b/pkg/controller/elasticsearch/user/roles.go @@ -42,8 +42,6 @@ const ( FleetAdminUserRole = "eck_fleet_admin_user_role" - LogstashUserRole = "eck_logstash_user_role_v80" - // V70 indicates version 7.0 V70 = "v70" @@ -149,15 +147,6 @@ var ( }, }, }, - LogstashUserRole: esclient.Role{ - Cluster: []string{"monitor", "manage_ilm", "manage_ml", "read_ilm", "cluster:admin/ingest/pipeline/get"}, - Indices: []esclient.IndexRole{ - { - Names: []string{"logstash-*"}, - Privileges: []string{"manage", "read", "create_doc", "view_index_metadata", "create_index"}, - }, - }, - }, } ) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index c27b754c25..6c00a6eeee 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -6,11 +6,13 @@ package logstash import ( "context" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" - ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" "hash" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" + ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -63,13 +65,13 @@ func buildConfig(params Params) ([]byte, error) { return nil, err } - cfg, err := defaultConfig() + cfg := defaultConfig() if err != nil { return nil, err } // merge with user settings last so they take precedence - if err = cfg.MergeWith(existingCfg, userProvidedCfg); err != nil { + if err := cfg.MergeWith(existingCfg, userProvidedCfg); err != nil { return nil, err } @@ -114,10 +116,10 @@ func getUserConfig(params Params) (*settings.CanonicalConfig, error) { } // TODO: remove testing value -func defaultConfig() (*settings.CanonicalConfig, error) { +func defaultConfig() *settings.CanonicalConfig { settingsMap := map[string]interface{}{ "node.name": "test", } - return settings.MustCanonicalConfig(settingsMap), nil + return settings.MustCanonicalConfig(settingsMap) } \ No newline at end of file diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index b0270bff24..54372a4701 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -6,10 +6,12 @@ package logstash import ( "context" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" "hash/fnv" "github.com/go-logr/logr" @@ -80,7 +82,7 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log return results.WithError(err), params.Status } - //_, results = certificates.Reconciler{ + // _, results = certificates.Reconciler{ // K8sClient: params.Client, // DynamicWatches: params.Watches, // Owner: ¶ms.Logstash, @@ -92,9 +94,9 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log // CACertRotation: params.OperatorParams.CACertRotation, // CertRotation: params.OperatorParams.CertRotation, // GarbageCollectSecrets: true, - //}.ReconcileCAAndHTTPCerts(params.Context) + // }.ReconcileCAAndHTTPCerts(params.Context) // - //if results.HasError() { + // if results.HasError() { // _, err := results.Aggregate() // k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) // return results, params.Status @@ -106,10 +108,7 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log return results.WithResults(res), params.Status } - podTemplate, err := buildPodTemplate(params, configHash) - if err != nil { - return results.WithError(err), params.Status - } + podTemplate := buildPodTemplate(params, configHash) return reconcileStatefulSet(params, podTemplate) } diff --git a/pkg/controller/logstash/init_configuration.go b/pkg/controller/logstash/init_configuration.go deleted file mode 100644 index a85b118568..0000000000 --- a/pkg/controller/logstash/init_configuration.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" -) - -const ( - InitContainerConfigVolumeMountPath = "/mnt/elastic-internal/logstash-config-local" - InitConfigContainerName = "elastic-internal-init-config" - - // InitConfigScript is a small bash script to prepare the logstash configuration directory - InitConfigScript = `#!/usr/bin/env bash -set -eux - -init_config_initialized_flag=` + InitContainerConfigVolumeMountPath + `/elastic-internal-init-config.ok - -if [[ -f "${init_config_initialized_flag}" ]]; then - echo "Logstash configuration already initialized." - exit 0 -fi - -echo "Setup Logstash configuration" - -mount_path=` + InitContainerConfigVolumeMountPath + ` - -for f in /usr/share/logstash/config/*.*; do - filename=$(basename $f) - if [[ ! -f "$mount_path/$filename" ]]; then - cp $f $mount_path - fi -done - -touch "${init_config_initialized_flag}" -echo "Logstash configuration successfully prepared." -` -) - -// initConfigContainer returns an init container that executes a bash script to prepare the logstash config directory. -// The script copy config files from /use/share/logstash/config to /mnt/elastic-internal/logstash-config/ -// TODO may be able to solve env2yaml permission issue with initContainer -func initConfigContainer() corev1.Container { - privileged := false - - return corev1.Container{ - // Image will be inherited from pod template defaults - ImagePullPolicy: corev1.PullIfNotPresent, - Name: InitConfigContainerName, - SecurityContext: &corev1.SecurityContext{ - Privileged: &privileged, - }, - Command: []string{"/usr/bin/env", "bash", "-c", InitConfigScript}, - VolumeMounts: []corev1.VolumeMount{ - { - MountPath: InitContainerConfigVolumeMountPath, - Name: ConfigVolumeName, - }, - }, - Resources: corev1.ResourceRequirements{ - Requests: map[corev1.ResourceName]resource.Quantity{ - corev1.ResourceMemory: resource.MustParse("50Mi"), - corev1.ResourceCPU: resource.MustParse("0.1"), - }, - Limits: map[corev1.ResourceName]resource.Quantity{ - // Memory limit should be at least 12582912 when running with CRI-O - corev1.ResourceMemory: resource.MustParse("50Mi"), - corev1.ResourceCPU: resource.MustParse("0.1"), - }, - }, - } -} diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go index 9660517915..5c0c6816b0 100644 --- a/pkg/controller/logstash/logstash_controller.go +++ b/pkg/controller/logstash/logstash_controller.go @@ -6,6 +6,7 @@ package logstash import ( "context" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" appsv1 "k8s.io/api/apps/v1" @@ -20,8 +21,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/source" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/keystore" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/keystore" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index aba2483c7d..958923b9b7 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -6,19 +6,20 @@ package logstash import ( "fmt" + "hash" + "path" + + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/intstr" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/maps" - "hash" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/apimachinery/pkg/util/intstr" - "path" ) const ( @@ -50,7 +51,7 @@ var ( } ) -func buildPodTemplate(params Params, configHash hash.Hash32) (corev1.PodTemplateSpec, error) { +func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateSpec { defer tracing.Span(¶ms.Context)() spec := ¶ms.Logstash.Spec builder := defaults.NewPodTemplateBuilder(params.GetPodTemplate(), ContainerName) @@ -84,18 +85,17 @@ func buildPodTemplate(params Params, configHash hash.Hash32) (corev1.PodTemplate WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) - //TODO integrate with api.ssl.enabled - //if params.Logstash.Spec.HTTP.TLS.Enabled() { + // TODO integrate with api.ssl.enabled + // if params.Logstash.Spec.HTTP.TLS.Enabled() { // httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) // builder. // WithVolumes(httpVol.Volume()). // WithVolumeMounts(httpVol.VolumeMount()) //} - return builder.PodTemplate, nil + return builder.PodTemplate } - func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.ContainerPort { return []corev1.ContainerPort{ {Name: logstash.Spec.HTTP.Protocol(), ContainerPort: int32(network.HTTPPort), Protocol: corev1.ProtocolTCP}, diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go index edc31631bb..c74149a1dd 100644 --- a/pkg/controller/logstash/reconcile.go +++ b/pkg/controller/logstash/reconcile.go @@ -6,9 +6,10 @@ package logstash import ( "context" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/sset" "reflect" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/sset" + corev1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client" @@ -23,8 +24,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) - -func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*reconciler.Results, logstashv1alpha1.LogstashStatus){ +func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*reconciler.Results, logstashv1alpha1.LogstashStatus) { defer tracing.Span(¶ms.Context)() results := reconciler.NewResult(params.Context) @@ -55,14 +55,6 @@ func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (* return results.WithError(err), status } -// ReconciliationParams are the parameters used during an Elastic Logstash's reconciliation. -type ReconciliationParams struct { - ctx context.Context - client k8s.Client - logstash logstashv1alpha1.Logstash - podTemplate corev1.PodTemplateSpec -} - // calculateStatus will calculate a new status from the state of the pods within the k8s cluster // and will return any error encountered. func calculateStatus(params *Params, ready, desired int32) (logstashv1alpha1.LogstashStatus, error) { diff --git a/pkg/controller/logstash/sset/sset.go b/pkg/controller/logstash/sset/sset.go index 650ad14f8a..39bc56e26d 100644 --- a/pkg/controller/logstash/sset/sset.go +++ b/pkg/controller/logstash/sset/sset.go @@ -1,7 +1,12 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + package sset import ( "context" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -46,8 +51,8 @@ func New(params Params) (appsv1.StatefulSet, error) { MatchLabels: params.Selector, }, - Replicas: ¶ms.Replicas, - Template: params.PodTemplateSpec, + Replicas: ¶ms.Replicas, + Template: params.PodTemplateSpec, }, } From 9cf0a4542d75295dfe4f064b8504976a9a14e741 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Fri, 10 Feb 2023 17:52:55 -0500 Subject: [PATCH 038/160] Generate API docs ` --- docs/reference/api-docs.asciidoc | 52 ++--------------------- pkg/apis/logstash/v1alpha1/validations.go | 2 +- pkg/controller/logstash/config.go | 2 +- pkg/controller/logstash/pod.go | 6 +-- 4 files changed, 9 insertions(+), 53 deletions(-) diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index a06cf4cb7f..c1a58e4930 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -591,7 +591,6 @@ Monitoring holds references to both the metrics, and logs Elasticsearch clusters - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-elasticsearchspec[$$ElasticsearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] **** [cols="25a,75a", options="header"] @@ -616,7 +615,6 @@ ObjectSelector defines a reference to a Kubernetes object which can be an Elasti - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-logsmonitoring[$$LogsMonitoring$$] -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-metricsmonitoring[$$MetricsMonitoring$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-agent-v1alpha1-output[$$Output$$] @@ -1838,25 +1836,6 @@ Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API g -[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-deploymentspec"] -=== DeploymentSpec - - - -.Appears In: -**** -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] -**** - -[cols="25a,75a", options="header"] -|=== -| Field | Description -| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | -| *`replicas`* __integer__ | -| *`strategy`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#deploymentstrategy-v1-apps[$$DeploymentStrategy$$]__ | -|=== - - [id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash"] === Logstash @@ -1893,19 +1872,15 @@ LogstashSpec defines the desired state of Logstash |=== | Field | Description | *`version`* __string__ | Version of the Logstash. -| *`elasticsearchRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-objectselector[$$ObjectSelector$$]__ | ElasticsearchRef is a reference to an Elasticsearch cluster running in the same Kubernetes cluster. +| *`count`* __integer__ | | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. -| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelineRef`] can be specified. -| *`pipelineRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelineRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipeline must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelineRef`] can be specified. +| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API +| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. +| *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. | *`serviceAccountName`* __string__ | ServiceAccountName is used to check access from the current resource to Elasticsearch resource in a different namespace. Can only be used if ECK is enforcing RBAC on references. -| *`deployment`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-deploymentspec[$$DeploymentSpec$$]__ | Deployment specifies the Logstash should be deployed as a Deployment, and allows providing its spec. Cannot be used along with `StatefulSet`. -| *`statefulSet`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-statefulsetspec[$$StatefulSetSpec$$]__ | StatefulSet specifies the Logstash should be deployed as a StatefulSet, and allows providing its spec. Cannot be used along with `Deployment`. -| *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying DaemonSet or Deployment. -| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Agent in Fleet mode with Fleet Server enabled. -| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. See https://www.elastic.co/guide/en/kibana/current/xpack-monitoring.html. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. |=== @@ -1929,25 +1904,6 @@ LogstashStatus defines the observed state of Logstash |=== -[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-statefulsetspec"] -=== StatefulSetSpec - - - -.Appears In: -**** -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] -**** - -[cols="25a,75a", options="header"] -|=== -| Field | Description -| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | -| *`replicas`* __integer__ | -| *`volumeClaimTemplates`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#persistentvolumeclaim-v1-core[$$PersistentVolumeClaim$$] array__ | VolumeClaimTemplates is a list of persistent volume claims to be used by each Pod in this NodeSet. Every claim in this list must have a matching volumeMount in one of the containers defined in the PodTemplate. Items defined here take precedence over any default claims added by the operator with the same name. -|=== - - [id="{anchor_prefix}-maps-k8s-elastic-co-v1alpha1"] == maps.k8s.elastic.co/v1alpha1 diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go index 019b482c04..1f70d2783a 100644 --- a/pkg/apis/logstash/v1alpha1/validations.go +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -53,4 +53,4 @@ func checkSingleConfigSource(a *Logstash) field.ErrorList { } return nil -} \ No newline at end of file +} diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index 6c00a6eeee..4a3fc0ed63 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -122,4 +122,4 @@ func defaultConfig() *settings.CanonicalConfig { } return settings.MustCanonicalConfig(settingsMap) -} \ No newline at end of file +} diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 958923b9b7..f6a4af0146 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -85,13 +85,13 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) - // TODO integrate with api.ssl.enabled - // if params.Logstash.Spec.HTTP.TLS.Enabled() { + // TODO integrate with api.ssl.enabled + // if params.Logstash.Spec.HTTP.TLS.Enabled() { // httpVol := certificates.HTTPCertSecretVolume(logstashv1alpha1.Namer, params.Logstash.Name) // builder. // WithVolumes(httpVol.Volume()). // WithVolumeMounts(httpVol.VolumeMount()) - //} + // } return builder.PodTemplate } From 4d62ab5cd950d94dc8a9b5043bca6ca24fb602cb Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 13 Feb 2023 10:20:59 -0500 Subject: [PATCH 039/160] First set of unit tests Rudimentary tests for validation and naming --- pkg/apis/logstash/v1alpha1/name_test.go | 105 ++++++++++++++++++ .../logstash/v1alpha1/validations_test.go | 47 ++++++++ 2 files changed, 152 insertions(+) create mode 100644 pkg/apis/logstash/v1alpha1/name_test.go create mode 100644 pkg/apis/logstash/v1alpha1/validations_test.go diff --git a/pkg/apis/logstash/v1alpha1/name_test.go b/pkg/apis/logstash/v1alpha1/name_test.go new file mode 100644 index 0000000000..38f3983d02 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/name_test.go @@ -0,0 +1,105 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "testing" +) + +func TestHTTPService(t *testing.T) { + type args struct { + logstashName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "sample", + args: args{logstashName: "sample"}, + want: "sample-ls-http", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := HTTPServiceName(tt.args.logstashName); got != tt.want { + t.Errorf("HTTPService() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestConfigSecretName(t *testing.T) { + type args struct { + logstashName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "sample", + args: args{logstashName: "sample"}, + want: "sample-ls-config", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ConfigSecretName(tt.args.logstashName); got != tt.want { + t.Errorf("ConfigSecret() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestLogstashName(t *testing.T) { + type args struct { + logstashName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "sample", + args: args{logstashName: "sample"}, + want: "sample-ls", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Name(tt.args.logstashName); got != tt.want { + t.Errorf("Logstash Name() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestConfigMapName(t *testing.T) { + type args struct { + logstashName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "sample", + args: args{logstashName: "sample"}, + want: "sample-ls-configmap", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ConfigMapName(tt.args.logstashName); got != tt.want { + t.Errorf("ConfigMap() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go new file mode 100644 index 0000000000..8cede16dcf --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -0,0 +1,47 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1 + +import ( + "testing" + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestCheckNameLength(t *testing.T) { + testCases := []struct { + name string + logstashName string + wantErr bool + wantErrMsg string + }{ + { + name: "valid configuration", + logstashName: "test-logstash", + wantErr: false, + }, + { + name: "long Logstash name", + logstashName: "extremely-long-winded-and-unnecessary-name-for-logstash", + wantErr: true, + wantErrMsg: "name exceeds maximum allowed length", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + ls := Logstash{ + ObjectMeta: metav1.ObjectMeta{ + Name: tc.logstashName, + Namespace: "test", + }, + Spec: LogstashSpec{}, + } + + errList := checkNameLength(&ls) + assert.Equal(t, tc.wantErr, len(errList) > 0) + }) + } +} From cf1379c755bbd155e969a7f0349005bf4074497f Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 13 Feb 2023 12:13:59 -0500 Subject: [PATCH 040/160] Fix goimports --- .../logstash/v1alpha1/validations_test.go | 23 ++++++++++--------- .../v1alpha1/zz_generated.deepcopy.go | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 8cede16dcf..0fb20a4036 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -6,27 +6,28 @@ package v1alpha1 import ( "testing" + "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestCheckNameLength(t *testing.T) { testCases := []struct { - name string - logstashName string - wantErr bool - wantErrMsg string + name string + logstashName string + wantErr bool + wantErrMsg string }{ { - name: "valid configuration", - logstashName: "test-logstash", - wantErr: false, + name: "valid configuration", + logstashName: "test-logstash", + wantErr: false, }, { - name: "long Logstash name", - logstashName: "extremely-long-winded-and-unnecessary-name-for-logstash", - wantErr: true, - wantErrMsg: "name exceeds maximum allowed length", + name: "long Logstash name", + logstashName: "extremely-long-winded-and-unnecessary-name-for-logstash", + wantErr: true, + wantErrMsg: "name exceeds maximum allowed length", }, } diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index 42ca5a613e..cb78272400 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -10,8 +10,9 @@ package v1alpha1 import ( - "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "k8s.io/apimachinery/pkg/runtime" + + v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. From e5a46213732b381e7139790418c530eb14f5ae20 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 13 Feb 2023 14:09:49 -0500 Subject: [PATCH 041/160] Add version check --- .../logstash/v1alpha1/validations_test.go | 137 ++++++++++++++++++ pkg/controller/common/version/version.go | 2 +- 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 0fb20a4036..4b9f1ebe91 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -9,6 +9,9 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/validation/field" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) func TestCheckNameLength(t *testing.T) { @@ -46,3 +49,137 @@ func TestCheckNameLength(t *testing.T) { }) } } + +func TestCheckNoUnknownFields(t *testing.T) { + type args struct { + prev *Logstash + curr *Logstash + } + tests := []struct { + name string + args args + want field.ErrorList + }{ + { + name: "No downgrade", + args: args{ + prev: &Logstash{Spec: LogstashSpec{Version: "7.17.0"}}, + curr: &Logstash{Spec: LogstashSpec{Version: "8.6.1"}}, + }, + want: nil, + }, + { + name: "Downgrade NOK", + args: args{ + prev: &Logstash{Spec: LogstashSpec{Version: "8.6.1"}}, + curr: &Logstash{Spec: LogstashSpec{Version: "8.5.0"}}, + }, + want: field.ErrorList{&field.Error{Type: field.ErrorTypeForbidden, Field: "spec.version", BadValue: "", Detail: "Version downgrades are not supported"}}, + }, + { + name: "Downgrade with override OK", + args: args{ + prev: &Logstash{Spec: LogstashSpec{Version: "8.6.1"}}, + curr: &Logstash{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{ + commonv1.DisableDowngradeValidationAnnotation: "true", + }}, Spec: LogstashSpec{Version: "8.5.0"}}, + }, + want: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, checkNoDowngrade(tt.args.prev, tt.args.curr), "checkNoDowngrade(%v, %v)", tt.args.prev, tt.args.curr) + }) + } +} + +func Test_checkSingleConfigSource(t *testing.T) { + tests := []struct { + name string + logstash Logstash + wantErr bool + }{ + { + name: "configRef absent, config present", + logstash: Logstash{ + Spec: LogstashSpec{ + Config: &commonv1.Config{}, + }, + }, + wantErr: false, + }, + { + name: "config absent, configRef present", + logstash: Logstash{ + Spec: LogstashSpec{ + ConfigRef: &commonv1.ConfigSource{}, + }, + }, + wantErr: false, + }, + { + name: "neither present", + logstash: Logstash{ + Spec: LogstashSpec{}, + }, + wantErr: false, + }, + { + name: "both present", + logstash: Logstash{ + Spec: LogstashSpec{ + Config: &commonv1.Config{}, + ConfigRef: &commonv1.ConfigSource{}, + }, + }, + wantErr: true, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + got := checkSingleConfigSource(&tc.logstash) + assert.Equal(t, tc.wantErr, len(got) > 0) + }) + } +} + +func Test_checkSupportedVersion(t *testing.T) { + for _, tt := range []struct { + name string + version string + wantErr bool + }{ + { + name: "below min supported", + version: "8.5.0", + wantErr: true, + }, + { + name: "above max supported", + version: "9.0.0", + wantErr: true, + }, + { + name: "above min supported", + version: "8.7.1", + wantErr: false, + }, + { + name: "at min supported", + version: "8.7.0", + wantErr: false, + }, + } { + t.Run(tt.name, func(t *testing.T) { + a := Logstash{ + Spec: LogstashSpec{ + Version: tt.version, + }, + } + got := checkSupportedVersion(&a) + assert.Equal(t, tt.wantErr, len(got) > 0) + }) + } +} diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index 9258310a74..d359f18371 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,7 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} - SupportedLogstashVersions = MinMaxVersion{Min: From(8, 3, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 7, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. From a74da1de814534d28082f7a2531d05997ecbf709 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Tue, 14 Feb 2023 18:39:30 -0500 Subject: [PATCH 042/160] Add e2e tests --- config/crds/v1/all-crds.yaml | 4 + .../logstash.k8s.elastic.co_logstashes.yaml | 4 + .../eck-operator-crds/templates/all-crds.yaml | 4 + pkg/apis/logstash/v1alpha1/logstash_types.go | 1 + .../logstash/v1alpha1/validations_test.go | 5 - .../v1alpha1/zz_generated.deepcopy.go | 3 +- pkg/controller/common/version/version.go | 2 +- pkg/controller/logstash/pod.go | 4 +- test/e2e/logstash/logstash_test.go | 36 ++++ test/e2e/test/k8s_client.go | 14 ++ test/e2e/test/logstash/builder.go | 146 +++++++++++++++++ test/e2e/test/logstash/checks.go | 64 ++++++++ test/e2e/test/logstash/steps.go | 155 ++++++++++++++++++ 13 files changed, 432 insertions(+), 10 deletions(-) create mode 100644 test/e2e/logstash/logstash_test.go create mode 100644 test/e2e/test/logstash/builder.go create mode 100644 test/e2e/test/logstash/checks.go create mode 100644 test/e2e/test/logstash/steps.go diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index d6a285a6dc..968393ef3d 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9631,6 +9631,10 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 1d86f803e1..b652b0ed80 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -7994,4 +7994,8 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 347de6c534..24afce4ccd 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9685,6 +9685,10 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 47c12f4a87..c0e97542fd 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -89,6 +89,7 @@ type LogstashStatus struct { // +kubebuilder:printcolumn:name="expected",type="integer",JSONPath=".status.expectedNodes",description="Expected nodes" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Logstash version" +// +kubebuilder:subresource:scale:specpath=.spec.count,statuspath=.status.count,selectorpath=.status.selector // +kubebuilder:storageversion type Logstash struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 4b9f1ebe91..08cd574aa4 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -166,11 +166,6 @@ func Test_checkSupportedVersion(t *testing.T) { version: "8.7.1", wantErr: false, }, - { - name: "at min supported", - version: "8.7.0", - wantErr: false, - }, } { t.Run(tt.name, func(t *testing.T) { a := Logstash{ diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index cb78272400..42ca5a613e 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -10,9 +10,8 @@ package v1alpha1 import ( + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "k8s.io/apimachinery/pkg/runtime" - - v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index d359f18371..0959920647 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,7 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} - SupportedLogstashVersions = MinMaxVersion{Min: From(8, 7, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 6, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index f6a4af0146..d6c139b83a 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -81,8 +81,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - WithReadinessProbe(readinessProbe(false)). - WithLivenessProbe(livenessProbe(false)). + //WithReadinessProbe(readinessProbe(false)). + //WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go new file mode 100644 index 0000000000..d994ad81e2 --- /dev/null +++ b/test/e2e/logstash/logstash_test.go @@ -0,0 +1,36 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +//go:build logstash || e2e + +package logstash + +import ( + "testing" + + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" +) + +func TestSingleLogstash(t *testing.T) { + name := "test-single-logstash" + logstashBuilder := logstash.NewBuilder(name). + WithNodeCount(1) + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + +func TestLogstashServerVersionUpgradeToLatest8x(t *testing.T) { + srcVersion, dstVersion := test.GetUpgradePathTo8x(test.Ctx().ElasticStackVersion) + + name := "test-ls-version-upgrade-8x" + + logstash := logstash.NewBuilder(name). + WithNodeCount(2). + WithVersion(srcVersion). + WithRestrictedSecurityContext() + + logstashUpgraded := logstash.WithVersion(dstVersion).WithMutatedFrom(&logstash) + + test.RunMutations(t, []test.Builder{logstash}, []test.Builder{logstashUpgraded}) +} diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index 8989fc2e82..f3b4d13ddf 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -33,6 +33,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/agent" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/apmserver" beatcommon "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/common" @@ -42,6 +43,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/kibana" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/maps" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) @@ -92,6 +94,9 @@ func CreateClient() (k8s.Client, error) { if err := agentv1alpha1.AddToScheme(scheme.Scheme); err != nil { return nil, err } + if err := logstashv1alpha1.AddToScheme(scheme.Scheme); err != nil { + return nil, err + } client, err := k8sclient.New(cfg, k8sclient.Options{Scheme: scheme.Scheme}) if err != nil { return nil, err @@ -431,6 +436,15 @@ func AgentPodListOptions(agentNamespace, agentName string) []k8sclient.ListOptio return []k8sclient.ListOption{ns, matchLabels} } +func LogstashPodListOptions(logstashNamespace, logstashName string) []k8sclient.ListOption { + ns := k8sclient.InNamespace(logstashNamespace) + matchLabels := k8sclient.MatchingLabels(map[string]string{ + commonv1.TypeLabelName: logstash.TypeLabelValue, + logstash.NameLabelName: logstashName, + }) + return []k8sclient.ListOption{ns, matchLabels} +} + func BeatPodListOptions(beatNamespace, beatName, beatType string) []k8sclient.ListOption { ns := k8sclient.InNamespace(beatNamespace) matchLabels := k8sclient.MatchingLabels(map[string]string{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go new file mode 100644 index 0000000000..8b08b9119d --- /dev/null +++ b/test/e2e/test/logstash/builder.go @@ -0,0 +1,146 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + +type Builder struct { + Logstash v1alpha1.Logstash + MutatedFrom *Builder +} + +func NewBuilder(name string) Builder { + return newBuilder(name, rand.String(4)) +} + +func NewBuilderWithoutSuffix(name string) Builder { + return newBuilder(name, "") +} + +func newBuilder(name, randSuffix string) Builder { + meta := metav1.ObjectMeta{ + Name: name, + Namespace: test.Ctx().ManagedNamespace(0), + } + def := test.Ctx().ImageDefinitionFor(v1alpha1.Kind) + return Builder{ + Logstash: v1alpha1.Logstash{ + ObjectMeta: meta, + Spec: v1alpha1.LogstashSpec{ + Count: 1, + Version: def.Version, + }, + }, + }. + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) +} + +func (b Builder) WithImage(image string) Builder { + b.Logstash.Spec.Image = image + return b +} + +func (b Builder) WithSuffix(suffix string) Builder { + if suffix != "" { + b.Logstash.ObjectMeta.Name = b.Logstash.ObjectMeta.Name + "-" + suffix + } + return b +} + +func (b Builder) WithLabel(key, value string) Builder { + if b.Logstash.Labels == nil { + b.Logstash.Labels = make(map[string]string) + } + b.Logstash.Labels[key] = value + + return b +} + +// WithRestrictedSecurityContext helps to enforce a restricted security context on the objects. +func (b Builder) WithRestrictedSecurityContext() Builder { + b.Logstash.Spec.PodTemplate.Spec.SecurityContext = test.DefaultSecurityContext() + return b +} + +func (b Builder) WithNamespace(namespace string) Builder { + b.Logstash.ObjectMeta.Namespace = namespace + return b +} + +func (b Builder) WithVersion(version string) Builder { + b.Logstash.Spec.Version = version + return b +} + +func (b Builder) WithNodeCount(count int) Builder { + b.Logstash.Spec.Count = int32(count) + return b +} + +// WithPodLabel sets the label in the pod template. All invocations can be removed when +// https://github.com/elastic/cloud-on-k8s/issues/2652 is implemented. +func (b Builder) WithPodLabel(key, value string) Builder { + labels := b.Logstash.Spec.PodTemplate.Labels + if labels == nil { + labels = make(map[string]string) + } + labels[key] = value + b.Logstash.Spec.PodTemplate.Labels = labels + return b +} + +func (b Builder) WithMutatedFrom(mutatedFrom *Builder) Builder { + b.MutatedFrom = mutatedFrom + return b +} + +func (b Builder) NSN() types.NamespacedName { + return k8s.ExtractNamespacedName(&b.Logstash) +} + +func (b Builder) Kind() string { + return v1alpha1.Kind +} + +func (b Builder) Spec() interface{} { + return b.Logstash.Spec +} + +func (b Builder) Count() int32 { + return b.Logstash.Spec.Count +} + +func (b Builder) ServiceName() string { + return b.Logstash.Name + "-ls-http" +} + +func (b Builder) ListOptions() []client.ListOption { + return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) +} + + +func (b Builder) SkipTest() bool { + supportedVersions := version.SupportedLogstashVersions + + ver := version.MustParse(b.Logstash.Spec.Version) + return supportedVersions.WithinRange(ver) != nil +} + +var _ test.Builder = Builder{} +var _ test.Subject = Builder{} diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go new file mode 100644 index 0000000000..2e50f486d2 --- /dev/null +++ b/test/e2e/test/logstash/checks.go @@ -0,0 +1,64 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + + +// CheckSecrets checks that expected secrets have been created. +func CheckSecrets(b Builder, k *test.K8sClient) test.Step { + return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { + logstashName := b.Logstash.Name + // hardcode all secret names and keys to catch any breaking change + expected := []test.ExpectedSecret{ + { + Name: logstashName + "-ls-config", + Keys: []string{"logstash.yml"}, + Labels: map[string]string{ + "eck.k8s.elastic.co/credentials": "true", + "logstash.k8s.elastic.co/name": logstashName, + }, + }, + } + return expected + }) +} + +func CheckStatus(b Builder, k *test.K8sClient) test.Step { + return test.Step{ + Name: "Logstash status should have the correct status", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { + return err + } + + logstash.Status.ObservedGeneration = 0 + + expected := logstashv1alpha1.LogstashStatus{ + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, + Version: b.Logstash.Spec.Version, + } + if logstash.Status != expected { + return fmt.Errorf("expected status %+v but got %+v", expected, logstash.Status) + } + return nil + }), + } +} + +func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { + println(test.Ctx().TestTimeout) + // TODO: Add stack checks + return test.StepList{} +} diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go new file mode 100644 index 0000000000..2c66762429 --- /dev/null +++ b/test/e2e/test/logstash/steps.go @@ -0,0 +1,155 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + //"k8s.io/apimachinery/pkg/types" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/generation" +) + +func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { + return []test.Step{ + { + Name: "K8S should be accessible", + Test: test.Eventually(func() error { + pods := corev1.PodList{} + return k.Client.List(context.Background(), &pods) + }), + }, + { + Name: "Label test pods", + Test: test.Eventually(func() error { + return test.LabelTestPods( + k.Client, + test.Ctx(), + run.TestNameLabel, + b.Logstash.Labels[run.TestNameLabel]) + }), + Skip: func() bool { + return test.Ctx().Local + }, + }, + { + Name: "Logstash CRDs should exist", + Test: test.Eventually(func() error { + crd := &logstashv1alpha1.LogstashList{} + return k.Client.List(context.Background(), crd) + }), + }, + { + Name: "Remove Logstash if it already exists", + Test: test.Eventually(func() error { + err := k.Client.Delete(context.Background(), &b.Logstash) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + // wait for pods to disappear + return k.CheckPodCount(0, test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name)...) + }), + }, + } +} + +func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Submitting the Logstash resource should succeed", + Test: test.Eventually(func() error { + return k.CreateOrUpdate(&b.Logstash) + }), + }, + { + Name: "Logstash should be created", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + return k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash) + }), + }, + } +} + +func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + CheckSecrets(b, k), + CheckStatus(b, k), + checks.CheckServices(b, k), + checks.CheckServicesEndpoints(b, k), + checks.CheckPods(b, k), + } +} + +func (b Builder) UpgradeTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Updating the Logstash spec succeed", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { + return err + } + logstash.Spec = b.Logstash.Spec + return k.Client.Update(context.Background(), &logstash) + }), + }} +} + +func (b Builder) MutationTestSteps(k *test.K8sClient) test.StepList { + var entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation int64 + isMutated := b.MutatedFrom != nil + + return test.StepList{ + generation.RetrieveGenerationsStep(&b.Logstash, k, &entSearchGenerationBeforeMutation, &entSearchObservedGenerationBeforeMutation), + }.WithSteps(test.AnnotatePodsWithBuilderHash(b, b.MutatedFrom, k)). + WithSteps(b.UpgradeTestSteps(k)). + WithSteps(b.CheckK8sTestSteps(k)). + WithSteps(b.CheckStackTestSteps(k)). + WithStep(generation.CompareObjectGenerationsStep(&b.Logstash, k, isMutated, entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation)) +} + +func (b Builder) DeletionTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Deleting Logstash should return no error", + Test: test.Eventually(func() error { + err := k.Client.Delete(context.Background(), &b.Logstash) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + return nil + }), + }, + { + Name: "Logstash should not be there anymore", + Test: test.Eventually(func() error { + objCopy := k8s.DeepCopyObject(&b.Logstash) + err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), objCopy) + if err != nil && apierrors.IsNotFound(err) { + return nil + } + return fmt.Errorf("expected 404 not found API error here. got: %w", err) + }), + }, + { + Name: "Logstash pods should eventually be removed", + Test: test.Eventually(func() error { + return k.CheckPodCount(0, b.ListOptions()...) + }), + }, + } +} From d3878a590950290c7c7ab53dda5301c7afea6445 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Tue, 14 Feb 2023 18:50:49 -0500 Subject: [PATCH 043/160] Temporarily take out probes --- pkg/controller/common/container/defaulter.go | 7 -- .../common/defaults/pod_template.go | 6 -- pkg/controller/logstash/pod.go | 93 ++++++++++--------- test/e2e/test/logstash/builder.go | 13 ++- test/e2e/test/logstash/checks.go | 7 +- test/e2e/test/logstash/steps.go | 11 ++- 6 files changed, 62 insertions(+), 75 deletions(-) diff --git a/pkg/controller/common/container/defaulter.go b/pkg/controller/common/container/defaulter.go index 0b03d42aa0..c007b0be79 100644 --- a/pkg/controller/common/container/defaulter.go +++ b/pkg/controller/common/container/defaulter.go @@ -96,13 +96,6 @@ func (d Defaulter) WithReadinessProbe(readinessProbe *corev1.Probe) Defaulter { return d } -func (d Defaulter) WithLivenessProbe(livenessProbe *corev1.Probe) Defaulter { - if d.base.LivenessProbe == nil { - d.base.LivenessProbe = livenessProbe - } - return d -} - // envExists checks if an env var with the given name already exists in the provided slice. func (d Defaulter) envExists(name string) bool { for _, v := range d.base.Env { diff --git a/pkg/controller/common/defaults/pod_template.go b/pkg/controller/common/defaults/pod_template.go index 073223a0c0..81cfea9331 100644 --- a/pkg/controller/common/defaults/pod_template.go +++ b/pkg/controller/common/defaults/pod_template.go @@ -121,12 +121,6 @@ func (b *PodTemplateBuilder) WithReadinessProbe(readinessProbe corev1.Probe) *Po return b } -// WithLivenessProbe sets up the given liveness probe, unless already provided in the template. -func (b *PodTemplateBuilder) WithLivenessProbe(livenessProbe corev1.Probe) *PodTemplateBuilder { - b.containerDefaulter.WithLivenessProbe(&livenessProbe) - return b -} - // WithAffinity sets a default affinity, unless already provided in the template. // An empty affinity in the spec is not overridden. func (b *PodTemplateBuilder) WithAffinity(affinity *corev1.Affinity) *PodTemplateBuilder { diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index d6c139b83a..281757d135 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -11,7 +11,8 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/apimachinery/pkg/util/intstr" + + // "k8s.io/apimachinery/pkg/util/intstr" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" @@ -81,8 +82,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - //WithReadinessProbe(readinessProbe(false)). - //WithLivenessProbe(livenessProbe(false)). + // WithReadinessProbe(readinessProbe(false)). + // WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled @@ -102,46 +103,46 @@ func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.Conta } } -// readinessProbe is the readiness probe for the Logstash container -func readinessProbe(useTLS bool) corev1.Probe { - scheme := corev1.URISchemeHTTP - if useTLS { - scheme = corev1.URISchemeHTTPS - } - return corev1.Probe{ - FailureThreshold: 3, - InitialDelaySeconds: 30, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Port: intstr.FromInt(network.HTTPPort), - Path: "/", - Scheme: scheme, - }, - }, - } -} - -// livenessProbe is the liveness probe for the Logstash container -func livenessProbe(useTLS bool) corev1.Probe { - scheme := corev1.URISchemeHTTP - if useTLS { - scheme = corev1.URISchemeHTTPS - } - return corev1.Probe{ - FailureThreshold: 3, - InitialDelaySeconds: 60, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Port: intstr.FromInt(network.HTTPPort), - Path: "/", - Scheme: scheme, - }, - }, - } -} +//// readinessProbe is the readiness probe for the Logstash container +// func readinessProbe(useTLS bool) corev1.Probe { +// scheme := corev1.URISchemeHTTP +// if useTLS { +// scheme = corev1.URISchemeHTTPS +// } +// return corev1.Probe{ +// FailureThreshold: 3, +// InitialDelaySeconds: 30, +// PeriodSeconds: 10, +// SuccessThreshold: 1, +// TimeoutSeconds: 5, +// ProbeHandler: corev1.ProbeHandler{ +// HTTPGet: &corev1.HTTPGetAction{ +// Port: intstr.FromInt(network.HTTPPort), +// Path: "/", +// Scheme: scheme, +// }, +// }, +// } +//} +// +//// livenessProbe is the liveness probe for the Logstash container +// func livenessProbe(useTLS bool) corev1.Probe { +// scheme := corev1.URISchemeHTTP +// if useTLS { +// scheme = corev1.URISchemeHTTPS +// } +// return corev1.Probe{ +// FailureThreshold: 3, +// InitialDelaySeconds: 60, +// PeriodSeconds: 10, +// SuccessThreshold: 1, +// TimeoutSeconds: 5, +// ProbeHandler: corev1.ProbeHandler{ +// HTTPGet: &corev1.HTTPGetAction{ +// Port: intstr.FromInt(network.HTTPPort), +// Path: "/", +// Scheme: scheme, +// }, +// }, +// } +//} diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 8b08b9119d..8ae6cd1678 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -18,7 +18,7 @@ import ( ) type Builder struct { - Logstash v1alpha1.Logstash + Logstash v1alpha1.Logstash MutatedFrom *Builder } @@ -40,15 +40,15 @@ func newBuilder(name, randSuffix string) Builder { Logstash: v1alpha1.Logstash{ ObjectMeta: meta, Spec: v1alpha1.LogstashSpec{ - Count: 1, + Count: 1, Version: def.Version, }, }, }. - WithImage(def.Image). - WithSuffix(randSuffix). - WithLabel(run.TestNameLabel, name). - WithPodLabel(run.TestNameLabel, name) + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) } func (b Builder) WithImage(image string) Builder { @@ -134,7 +134,6 @@ func (b Builder) ListOptions() []client.ListOption { return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) } - func (b Builder) SkipTest() bool { supportedVersions := version.SupportedLogstashVersions diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 2e50f486d2..6c8ed2d188 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -13,7 +13,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) - // CheckSecrets checks that expected secrets have been created. func CheckSecrets(b Builder, k *test.K8sClient) test.Step { return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { @@ -25,7 +24,7 @@ func CheckSecrets(b Builder, k *test.K8sClient) test.Step { Keys: []string{"logstash.yml"}, Labels: map[string]string{ "eck.k8s.elastic.co/credentials": "true", - "logstash.k8s.elastic.co/name": logstashName, + "logstash.k8s.elastic.co/name": logstashName, }, }, } @@ -45,8 +44,8 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { logstash.Status.ObservedGeneration = 0 expected := logstashv1alpha1.LogstashStatus{ - ExpectedNodes: b.Logstash.Spec.Count, - AvailableNodes: b.Logstash.Spec.Count, + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, Version: b.Logstash.Spec.Version, } if logstash.Status != expected { diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index 2c66762429..44f2a5f4e0 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -10,12 +10,13 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - //"k8s.io/apimachinery/pkg/types" + + // "k8s.io/apimachinery/pkg/types" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + // mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -52,7 +53,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { return k.Client.List(context.Background(), crd) }), }, - { + { Name: "Remove Logstash if it already exists", Test: test.Eventually(func() error { err := k.Client.Delete(context.Background(), &b.Logstash) From cd7f8f6985391d992325d1eb6a62f003e09dcf16 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 15:20:43 -0500 Subject: [PATCH 044/160] Revert "Temporarily take out probes" This reverts commit 6eabf4c0796a4d54c12882a850744ff464300ea5. --- pkg/controller/common/container/defaulter.go | 7 ++ .../common/defaults/pod_template.go | 6 ++ pkg/controller/logstash/pod.go | 93 +++++++++---------- test/e2e/test/logstash/builder.go | 13 +-- test/e2e/test/logstash/checks.go | 7 +- test/e2e/test/logstash/steps.go | 11 +-- 6 files changed, 75 insertions(+), 62 deletions(-) diff --git a/pkg/controller/common/container/defaulter.go b/pkg/controller/common/container/defaulter.go index c007b0be79..0b03d42aa0 100644 --- a/pkg/controller/common/container/defaulter.go +++ b/pkg/controller/common/container/defaulter.go @@ -96,6 +96,13 @@ func (d Defaulter) WithReadinessProbe(readinessProbe *corev1.Probe) Defaulter { return d } +func (d Defaulter) WithLivenessProbe(livenessProbe *corev1.Probe) Defaulter { + if d.base.LivenessProbe == nil { + d.base.LivenessProbe = livenessProbe + } + return d +} + // envExists checks if an env var with the given name already exists in the provided slice. func (d Defaulter) envExists(name string) bool { for _, v := range d.base.Env { diff --git a/pkg/controller/common/defaults/pod_template.go b/pkg/controller/common/defaults/pod_template.go index 81cfea9331..073223a0c0 100644 --- a/pkg/controller/common/defaults/pod_template.go +++ b/pkg/controller/common/defaults/pod_template.go @@ -121,6 +121,12 @@ func (b *PodTemplateBuilder) WithReadinessProbe(readinessProbe corev1.Probe) *Po return b } +// WithLivenessProbe sets up the given liveness probe, unless already provided in the template. +func (b *PodTemplateBuilder) WithLivenessProbe(livenessProbe corev1.Probe) *PodTemplateBuilder { + b.containerDefaulter.WithLivenessProbe(&livenessProbe) + return b +} + // WithAffinity sets a default affinity, unless already provided in the template. // An empty affinity in the spec is not overridden. func (b *PodTemplateBuilder) WithAffinity(affinity *corev1.Affinity) *PodTemplateBuilder { diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 281757d135..d6c139b83a 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -11,8 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - - // "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/apimachinery/pkg/util/intstr" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" @@ -82,8 +81,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - // WithReadinessProbe(readinessProbe(false)). - // WithLivenessProbe(livenessProbe(false)). + //WithReadinessProbe(readinessProbe(false)). + //WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled @@ -103,46 +102,46 @@ func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.Conta } } -//// readinessProbe is the readiness probe for the Logstash container -// func readinessProbe(useTLS bool) corev1.Probe { -// scheme := corev1.URISchemeHTTP -// if useTLS { -// scheme = corev1.URISchemeHTTPS -// } -// return corev1.Probe{ -// FailureThreshold: 3, -// InitialDelaySeconds: 30, -// PeriodSeconds: 10, -// SuccessThreshold: 1, -// TimeoutSeconds: 5, -// ProbeHandler: corev1.ProbeHandler{ -// HTTPGet: &corev1.HTTPGetAction{ -// Port: intstr.FromInt(network.HTTPPort), -// Path: "/", -// Scheme: scheme, -// }, -// }, -// } -//} -// -//// livenessProbe is the liveness probe for the Logstash container -// func livenessProbe(useTLS bool) corev1.Probe { -// scheme := corev1.URISchemeHTTP -// if useTLS { -// scheme = corev1.URISchemeHTTPS -// } -// return corev1.Probe{ -// FailureThreshold: 3, -// InitialDelaySeconds: 60, -// PeriodSeconds: 10, -// SuccessThreshold: 1, -// TimeoutSeconds: 5, -// ProbeHandler: corev1.ProbeHandler{ -// HTTPGet: &corev1.HTTPGetAction{ -// Port: intstr.FromInt(network.HTTPPort), -// Path: "/", -// Scheme: scheme, -// }, -// }, -// } -//} +// readinessProbe is the readiness probe for the Logstash container +func readinessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 30, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} + +// livenessProbe is the liveness probe for the Logstash container +func livenessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 60, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 8ae6cd1678..8b08b9119d 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -18,7 +18,7 @@ import ( ) type Builder struct { - Logstash v1alpha1.Logstash + Logstash v1alpha1.Logstash MutatedFrom *Builder } @@ -40,15 +40,15 @@ func newBuilder(name, randSuffix string) Builder { Logstash: v1alpha1.Logstash{ ObjectMeta: meta, Spec: v1alpha1.LogstashSpec{ - Count: 1, + Count: 1, Version: def.Version, }, }, }. - WithImage(def.Image). - WithSuffix(randSuffix). - WithLabel(run.TestNameLabel, name). - WithPodLabel(run.TestNameLabel, name) + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) } func (b Builder) WithImage(image string) Builder { @@ -134,6 +134,7 @@ func (b Builder) ListOptions() []client.ListOption { return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) } + func (b Builder) SkipTest() bool { supportedVersions := version.SupportedLogstashVersions diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 6c8ed2d188..2e50f486d2 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -13,6 +13,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) + // CheckSecrets checks that expected secrets have been created. func CheckSecrets(b Builder, k *test.K8sClient) test.Step { return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { @@ -24,7 +25,7 @@ func CheckSecrets(b Builder, k *test.K8sClient) test.Step { Keys: []string{"logstash.yml"}, Labels: map[string]string{ "eck.k8s.elastic.co/credentials": "true", - "logstash.k8s.elastic.co/name": logstashName, + "logstash.k8s.elastic.co/name": logstashName, }, }, } @@ -44,8 +45,8 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { logstash.Status.ObservedGeneration = 0 expected := logstashv1alpha1.LogstashStatus{ - ExpectedNodes: b.Logstash.Spec.Count, - AvailableNodes: b.Logstash.Spec.Count, + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, Version: b.Logstash.Spec.Version, } if logstash.Status != expected { diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index 44f2a5f4e0..2c66762429 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -10,13 +10,12 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - - // "k8s.io/apimachinery/pkg/types" + //"k8s.io/apimachinery/pkg/types" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - // mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -53,7 +52,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { return k.Client.List(context.Background(), crd) }), }, - { + { Name: "Remove Logstash if it already exists", Test: test.Eventually(func() error { err := k.Client.Delete(context.Background(), &b.Logstash) From 793ff2896316e4404a3ea9e79578a0db4e5f4ec1 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 15:20:55 -0500 Subject: [PATCH 045/160] Revert "Add e2e tests" This reverts commit 8016b7b414be3bd098d4e8371d3465e866d6f95b. Remving e2e tests to get e2e tests prior to logstash working --- config/crds/v1/all-crds.yaml | 4 - .../logstash.k8s.elastic.co_logstashes.yaml | 4 - .../eck-operator-crds/templates/all-crds.yaml | 4 - pkg/apis/logstash/v1alpha1/logstash_types.go | 1 - .../logstash/v1alpha1/validations_test.go | 5 + .../v1alpha1/zz_generated.deepcopy.go | 3 +- pkg/controller/common/version/version.go | 2 +- pkg/controller/logstash/pod.go | 4 +- test/e2e/logstash/logstash_test.go | 36 ---- test/e2e/test/k8s_client.go | 14 -- test/e2e/test/logstash/builder.go | 146 ----------------- test/e2e/test/logstash/checks.go | 64 -------- test/e2e/test/logstash/steps.go | 155 ------------------ 13 files changed, 10 insertions(+), 432 deletions(-) delete mode 100644 test/e2e/logstash/logstash_test.go delete mode 100644 test/e2e/test/logstash/builder.go delete mode 100644 test/e2e/test/logstash/checks.go delete mode 100644 test/e2e/test/logstash/steps.go diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 968393ef3d..d6a285a6dc 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9631,10 +9631,6 @@ spec: served: true storage: true subresources: - scale: - labelSelectorPath: .status.selector - specReplicasPath: .spec.count - statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index b652b0ed80..1d86f803e1 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -7994,8 +7994,4 @@ spec: served: true storage: true subresources: - scale: - labelSelectorPath: .status.selector - specReplicasPath: .spec.count - statusReplicasPath: .status.count status: {} diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 24afce4ccd..347de6c534 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9685,10 +9685,6 @@ spec: served: true storage: true subresources: - scale: - labelSelectorPath: .status.selector - specReplicasPath: .spec.count - statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index c0e97542fd..47c12f4a87 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -89,7 +89,6 @@ type LogstashStatus struct { // +kubebuilder:printcolumn:name="expected",type="integer",JSONPath=".status.expectedNodes",description="Expected nodes" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Logstash version" -// +kubebuilder:subresource:scale:specpath=.spec.count,statuspath=.status.count,selectorpath=.status.selector // +kubebuilder:storageversion type Logstash struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 08cd574aa4..4b9f1ebe91 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -166,6 +166,11 @@ func Test_checkSupportedVersion(t *testing.T) { version: "8.7.1", wantErr: false, }, + { + name: "at min supported", + version: "8.7.0", + wantErr: false, + }, } { t.Run(tt.name, func(t *testing.T) { a := Logstash{ diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index 42ca5a613e..cb78272400 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -10,8 +10,9 @@ package v1alpha1 import ( - "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "k8s.io/apimachinery/pkg/runtime" + + v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index 0959920647..d359f18371 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,7 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} - SupportedLogstashVersions = MinMaxVersion{Min: From(8, 6, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 7, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index d6c139b83a..f6a4af0146 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -81,8 +81,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - //WithReadinessProbe(readinessProbe(false)). - //WithLivenessProbe(livenessProbe(false)). + WithReadinessProbe(readinessProbe(false)). + WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go deleted file mode 100644 index d994ad81e2..0000000000 --- a/test/e2e/logstash/logstash_test.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -//go:build logstash || e2e - -package logstash - -import ( - "testing" - - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" -) - -func TestSingleLogstash(t *testing.T) { - name := "test-single-logstash" - logstashBuilder := logstash.NewBuilder(name). - WithNodeCount(1) - test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) -} - -func TestLogstashServerVersionUpgradeToLatest8x(t *testing.T) { - srcVersion, dstVersion := test.GetUpgradePathTo8x(test.Ctx().ElasticStackVersion) - - name := "test-ls-version-upgrade-8x" - - logstash := logstash.NewBuilder(name). - WithNodeCount(2). - WithVersion(srcVersion). - WithRestrictedSecurityContext() - - logstashUpgraded := logstash.WithVersion(dstVersion).WithMutatedFrom(&logstash) - - test.RunMutations(t, []test.Builder{logstash}, []test.Builder{logstashUpgraded}) -} diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index f3b4d13ddf..8989fc2e82 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -33,7 +33,6 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/agent" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/apmserver" beatcommon "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/common" @@ -43,7 +42,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/kibana" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/maps" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) @@ -94,9 +92,6 @@ func CreateClient() (k8s.Client, error) { if err := agentv1alpha1.AddToScheme(scheme.Scheme); err != nil { return nil, err } - if err := logstashv1alpha1.AddToScheme(scheme.Scheme); err != nil { - return nil, err - } client, err := k8sclient.New(cfg, k8sclient.Options{Scheme: scheme.Scheme}) if err != nil { return nil, err @@ -436,15 +431,6 @@ func AgentPodListOptions(agentNamespace, agentName string) []k8sclient.ListOptio return []k8sclient.ListOption{ns, matchLabels} } -func LogstashPodListOptions(logstashNamespace, logstashName string) []k8sclient.ListOption { - ns := k8sclient.InNamespace(logstashNamespace) - matchLabels := k8sclient.MatchingLabels(map[string]string{ - commonv1.TypeLabelName: logstash.TypeLabelValue, - logstash.NameLabelName: logstashName, - }) - return []k8sclient.ListOption{ns, matchLabels} -} - func BeatPodListOptions(beatNamespace, beatName, beatType string) []k8sclient.ListOption { ns := k8sclient.InNamespace(beatNamespace) matchLabels := k8sclient.MatchingLabels(map[string]string{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go deleted file mode 100644 index 8b08b9119d..0000000000 --- a/test/e2e/test/logstash/builder.go +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/rand" - "sigs.k8s.io/controller-runtime/pkg/client" - - "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" -) - -type Builder struct { - Logstash v1alpha1.Logstash - MutatedFrom *Builder -} - -func NewBuilder(name string) Builder { - return newBuilder(name, rand.String(4)) -} - -func NewBuilderWithoutSuffix(name string) Builder { - return newBuilder(name, "") -} - -func newBuilder(name, randSuffix string) Builder { - meta := metav1.ObjectMeta{ - Name: name, - Namespace: test.Ctx().ManagedNamespace(0), - } - def := test.Ctx().ImageDefinitionFor(v1alpha1.Kind) - return Builder{ - Logstash: v1alpha1.Logstash{ - ObjectMeta: meta, - Spec: v1alpha1.LogstashSpec{ - Count: 1, - Version: def.Version, - }, - }, - }. - WithImage(def.Image). - WithSuffix(randSuffix). - WithLabel(run.TestNameLabel, name). - WithPodLabel(run.TestNameLabel, name) -} - -func (b Builder) WithImage(image string) Builder { - b.Logstash.Spec.Image = image - return b -} - -func (b Builder) WithSuffix(suffix string) Builder { - if suffix != "" { - b.Logstash.ObjectMeta.Name = b.Logstash.ObjectMeta.Name + "-" + suffix - } - return b -} - -func (b Builder) WithLabel(key, value string) Builder { - if b.Logstash.Labels == nil { - b.Logstash.Labels = make(map[string]string) - } - b.Logstash.Labels[key] = value - - return b -} - -// WithRestrictedSecurityContext helps to enforce a restricted security context on the objects. -func (b Builder) WithRestrictedSecurityContext() Builder { - b.Logstash.Spec.PodTemplate.Spec.SecurityContext = test.DefaultSecurityContext() - return b -} - -func (b Builder) WithNamespace(namespace string) Builder { - b.Logstash.ObjectMeta.Namespace = namespace - return b -} - -func (b Builder) WithVersion(version string) Builder { - b.Logstash.Spec.Version = version - return b -} - -func (b Builder) WithNodeCount(count int) Builder { - b.Logstash.Spec.Count = int32(count) - return b -} - -// WithPodLabel sets the label in the pod template. All invocations can be removed when -// https://github.com/elastic/cloud-on-k8s/issues/2652 is implemented. -func (b Builder) WithPodLabel(key, value string) Builder { - labels := b.Logstash.Spec.PodTemplate.Labels - if labels == nil { - labels = make(map[string]string) - } - labels[key] = value - b.Logstash.Spec.PodTemplate.Labels = labels - return b -} - -func (b Builder) WithMutatedFrom(mutatedFrom *Builder) Builder { - b.MutatedFrom = mutatedFrom - return b -} - -func (b Builder) NSN() types.NamespacedName { - return k8s.ExtractNamespacedName(&b.Logstash) -} - -func (b Builder) Kind() string { - return v1alpha1.Kind -} - -func (b Builder) Spec() interface{} { - return b.Logstash.Spec -} - -func (b Builder) Count() int32 { - return b.Logstash.Spec.Count -} - -func (b Builder) ServiceName() string { - return b.Logstash.Name + "-ls-http" -} - -func (b Builder) ListOptions() []client.ListOption { - return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) -} - - -func (b Builder) SkipTest() bool { - supportedVersions := version.SupportedLogstashVersions - - ver := version.MustParse(b.Logstash.Spec.Version) - return supportedVersions.WithinRange(ver) != nil -} - -var _ test.Builder = Builder{} -var _ test.Subject = Builder{} diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go deleted file mode 100644 index 2e50f486d2..0000000000 --- a/test/e2e/test/logstash/checks.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - "context" - "fmt" - - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" -) - - -// CheckSecrets checks that expected secrets have been created. -func CheckSecrets(b Builder, k *test.K8sClient) test.Step { - return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { - logstashName := b.Logstash.Name - // hardcode all secret names and keys to catch any breaking change - expected := []test.ExpectedSecret{ - { - Name: logstashName + "-ls-config", - Keys: []string{"logstash.yml"}, - Labels: map[string]string{ - "eck.k8s.elastic.co/credentials": "true", - "logstash.k8s.elastic.co/name": logstashName, - }, - }, - } - return expected - }) -} - -func CheckStatus(b Builder, k *test.K8sClient) test.Step { - return test.Step{ - Name: "Logstash status should have the correct status", - Test: test.Eventually(func() error { - var logstash logstashv1alpha1.Logstash - if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { - return err - } - - logstash.Status.ObservedGeneration = 0 - - expected := logstashv1alpha1.LogstashStatus{ - ExpectedNodes: b.Logstash.Spec.Count, - AvailableNodes: b.Logstash.Spec.Count, - Version: b.Logstash.Spec.Version, - } - if logstash.Status != expected { - return fmt.Errorf("expected status %+v but got %+v", expected, logstash.Status) - } - return nil - }), - } -} - -func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { - println(test.Ctx().TestTimeout) - // TODO: Add stack checks - return test.StepList{} -} diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go deleted file mode 100644 index 2c66762429..0000000000 --- a/test/e2e/test/logstash/steps.go +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - "context" - "fmt" - - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - //"k8s.io/apimachinery/pkg/types" - - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" - "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/generation" -) - -func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { - return []test.Step{ - { - Name: "K8S should be accessible", - Test: test.Eventually(func() error { - pods := corev1.PodList{} - return k.Client.List(context.Background(), &pods) - }), - }, - { - Name: "Label test pods", - Test: test.Eventually(func() error { - return test.LabelTestPods( - k.Client, - test.Ctx(), - run.TestNameLabel, - b.Logstash.Labels[run.TestNameLabel]) - }), - Skip: func() bool { - return test.Ctx().Local - }, - }, - { - Name: "Logstash CRDs should exist", - Test: test.Eventually(func() error { - crd := &logstashv1alpha1.LogstashList{} - return k.Client.List(context.Background(), crd) - }), - }, - { - Name: "Remove Logstash if it already exists", - Test: test.Eventually(func() error { - err := k.Client.Delete(context.Background(), &b.Logstash) - if err != nil && !apierrors.IsNotFound(err) { - return err - } - // wait for pods to disappear - return k.CheckPodCount(0, test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name)...) - }), - }, - } -} - -func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { - return test.StepList{ - { - Name: "Submitting the Logstash resource should succeed", - Test: test.Eventually(func() error { - return k.CreateOrUpdate(&b.Logstash) - }), - }, - { - Name: "Logstash should be created", - Test: test.Eventually(func() error { - var logstash logstashv1alpha1.Logstash - return k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash) - }), - }, - } -} - -func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { - return test.StepList{ - CheckSecrets(b, k), - CheckStatus(b, k), - checks.CheckServices(b, k), - checks.CheckServicesEndpoints(b, k), - checks.CheckPods(b, k), - } -} - -func (b Builder) UpgradeTestSteps(k *test.K8sClient) test.StepList { - return test.StepList{ - { - Name: "Updating the Logstash spec succeed", - Test: test.Eventually(func() error { - var logstash logstashv1alpha1.Logstash - if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { - return err - } - logstash.Spec = b.Logstash.Spec - return k.Client.Update(context.Background(), &logstash) - }), - }} -} - -func (b Builder) MutationTestSteps(k *test.K8sClient) test.StepList { - var entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation int64 - isMutated := b.MutatedFrom != nil - - return test.StepList{ - generation.RetrieveGenerationsStep(&b.Logstash, k, &entSearchGenerationBeforeMutation, &entSearchObservedGenerationBeforeMutation), - }.WithSteps(test.AnnotatePodsWithBuilderHash(b, b.MutatedFrom, k)). - WithSteps(b.UpgradeTestSteps(k)). - WithSteps(b.CheckK8sTestSteps(k)). - WithSteps(b.CheckStackTestSteps(k)). - WithStep(generation.CompareObjectGenerationsStep(&b.Logstash, k, isMutated, entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation)) -} - -func (b Builder) DeletionTestSteps(k *test.K8sClient) test.StepList { - return test.StepList{ - { - Name: "Deleting Logstash should return no error", - Test: test.Eventually(func() error { - err := k.Client.Delete(context.Background(), &b.Logstash) - if err != nil && !apierrors.IsNotFound(err) { - return err - } - return nil - }), - }, - { - Name: "Logstash should not be there anymore", - Test: test.Eventually(func() error { - objCopy := k8s.DeepCopyObject(&b.Logstash) - err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), objCopy) - if err != nil && apierrors.IsNotFound(err) { - return nil - } - return fmt.Errorf("expected 404 not found API error here. got: %w", err) - }), - }, - { - Name: "Logstash pods should eventually be removed", - Test: test.Eventually(func() error { - return k.CheckPodCount(0, b.ListOptions()...) - }), - }, - } -} From 1a83870db90376b20fd0706cff5ce733326ce0b0 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 16:02:10 -0500 Subject: [PATCH 046/160] Fix linter --- pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index cb78272400..42ca5a613e 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -10,9 +10,8 @@ package v1alpha1 import ( + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "k8s.io/apimachinery/pkg/runtime" - - v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. From d3edd1e7aefe0013462ceaeee12e105434c777ba Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 16:19:36 -0500 Subject: [PATCH 047/160] Add logstash config details --- config/e2e/rbac.yaml | 13 +++++++++++++ deploy/eck-operator/templates/cluster-roles.yaml | 6 ++++++ hack/operatorhub/config.yaml | 3 +++ test/e2e/test/elasticsearch/checks_k8s.go | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config/e2e/rbac.yaml b/config/e2e/rbac.yaml index d309317c88..00f86dea81 100644 --- a/config/e2e/rbac.yaml +++ b/config/e2e/rbac.yaml @@ -296,6 +296,19 @@ rules: - update - patch - delete + - apiGroups : + - logstash.k8s.elastic.co + resources: + - logstashes + - logstashes/status + verbs: + - get + - list + - watch + - create + - update + - patch + - delete - apiGroups: - storage.k8s.io resources: diff --git a/deploy/eck-operator/templates/cluster-roles.yaml b/deploy/eck-operator/templates/cluster-roles.yaml index c6fa56cf71..1b623f37fe 100644 --- a/deploy/eck-operator/templates/cluster-roles.yaml +++ b/deploy/eck-operator/templates/cluster-roles.yaml @@ -50,6 +50,9 @@ rules: - apiGroups: ["stackconfigpolicy.k8s.elastic.co"] resources: ["stackconfigpolicies"] verbs: ["get", "list", "watch"] + - apiGroups: ["logstash.k8s.elastic.co"] + resources: ["logstashes"] + verbs: ["get", "list", "watch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole @@ -87,4 +90,7 @@ rules: - apiGroups: ["stackconfigpolicy.k8s.elastic.co"] resources: ["stackconfigpolicies"] verbs: ["create", "delete", "deletecollection", "patch", "update"] + - apiGroups: ["logstash.k8s.elastic.co"] + resources: ["logstashes"] + verbs: ["create", "delete", "deletecollection", "patch", "update"] {{- end -}} diff --git a/hack/operatorhub/config.yaml b/hack/operatorhub/config.yaml index 0c46c4ec45..0c28f2c3f2 100644 --- a/hack/operatorhub/config.yaml +++ b/hack/operatorhub/config.yaml @@ -30,6 +30,9 @@ crds: - name: stackconfigpolicies.stackconfigpolicy.k8s.elastic.co displayName: Elastic Stack Config Policy description: Elastic Stack Config Policy + - name: logstashes.stackconfigpolicy.k8s.elastic.co + displayName: Logstash + description: Logstash instance packages: - outputPath: community-operators packageName: elastic-cloud-eck diff --git a/test/e2e/test/elasticsearch/checks_k8s.go b/test/e2e/test/elasticsearch/checks_k8s.go index b0cc7b114b..b6bbdede91 100644 --- a/test/e2e/test/elasticsearch/checks_k8s.go +++ b/test/e2e/test/elasticsearch/checks_k8s.go @@ -35,7 +35,7 @@ const ( // but it occasionally takes longer for various reasons (long Pod creation time, long volume binding, etc.). // We use a longer timeout here to not be impacted too much by those external factors, and only fail // if things seem to be stuck. - RollingUpgradeTimeout = 30 * time.Minute + RollingUpgradeTimeout = 10 * time.Minute ) func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { From 4e4303da061582fd0c03d79e7d8de24d97da3f17 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 18:12:18 -0500 Subject: [PATCH 048/160] Fix up typos --- config/webhook/manifests.yaml | 2 +- deploy/eck-operator/templates/_helpers.tpl | 13 +++++++++++++ pkg/apis/common/v1/association.go | 2 -- pkg/apis/logstash/v1alpha1/webhook.go | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 1870792dd2..b2a9dbc85d 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -223,7 +223,7 @@ webhooks: - CREATE - UPDATE resources: - - logstashs + - logstashes sideEffects: None - admissionReviewVersions: - v1alpha1 diff --git a/deploy/eck-operator/templates/_helpers.tpl b/deploy/eck-operator/templates/_helpers.tpl index 424dd0be1f..8c421f7b55 100644 --- a/deploy/eck-operator/templates/_helpers.tpl +++ b/deploy/eck-operator/templates/_helpers.tpl @@ -310,6 +310,19 @@ updating docs/operating-eck/eck-permissions.asciidoc file. - create - update - patch +- apiGroups: + - logstash.k8s.elastic.co + resources: + - logstashes + - logstashes/status + - logstashes/finalizers # needed for ownerReferences with blockOwnerDeletion on OCP + verbs: + - get + - list + - watch + - create + - update + - patch {{- end -}} {{/* diff --git a/pkg/apis/common/v1/association.go b/pkg/apis/common/v1/association.go index 8bcfaa2f23..721055c273 100644 --- a/pkg/apis/common/v1/association.go +++ b/pkg/apis/common/v1/association.go @@ -110,8 +110,6 @@ const ( BeatAssociationType = "beat" BeatMonitoringAssociationType = "beat-monitoring" - LogstashMonitoringAssociationType = "ls-monitoring" - AssociationUnknown AssociationStatus = "" AssociationPending AssociationStatus = "Pending" AssociationEstablished AssociationStatus = "Established" diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go index 1f9bed70b4..76b564678d 100644 --- a/pkg/apis/logstash/v1alpha1/webhook.go +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -26,7 +26,7 @@ var ( validationLog = ulog.Log.WithName("logstash-v1alpha1-validation") ) -// +kubebuilder:webhook:path=/validate-logstash-k8s-elastic-co-v1alpha1-logstash,mutating=false,failurePolicy=ignore,groups=logstash.k8s.elastic.co,resources=logstashs,verbs=create;update,versions=v1alpha1,name=elastic-logstash-validation-v1alpha1.k8s.elastic.co,sideEffects=None,admissionReviewVersions=v1;v1beta1,matchPolicy=Exact +// +kubebuilder:webhook:path=/validate-logstash-k8s-elastic-co-v1alpha1-logstash,mutating=false,failurePolicy=ignore,groups=logstash.k8s.elastic.co,resources=logstashes,verbs=create;update,versions=v1alpha1,name=elastic-logstash-validation-v1alpha1.k8s.elastic.co,sideEffects=None,admissionReviewVersions=v1;v1beta1,matchPolicy=Exact var _ webhook.Validator = &Logstash{} From 50e834eb9f573339cc4988de1cb5f80e4993f43f Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 18:36:23 -0500 Subject: [PATCH 049/160] Revert "Revert "Add e2e tests"" This reverts commit b5c775e58b7075f17b89e7f1a6388afb084269db. And re-adds the e2e tests --- config/crds/v1/all-crds.yaml | 4 + .../logstash.k8s.elastic.co_logstashes.yaml | 4 + .../eck-operator-crds/templates/all-crds.yaml | 4 + pkg/apis/logstash/v1alpha1/logstash_types.go | 1 + .../logstash/v1alpha1/validations_test.go | 5 - pkg/controller/common/version/version.go | 2 +- pkg/controller/logstash/pod.go | 4 +- test/e2e/logstash/logstash_test.go | 36 ++++ test/e2e/test/k8s_client.go | 14 ++ test/e2e/test/logstash/builder.go | 146 +++++++++++++++++ test/e2e/test/logstash/checks.go | 64 ++++++++ test/e2e/test/logstash/steps.go | 155 ++++++++++++++++++ 12 files changed, 431 insertions(+), 8 deletions(-) create mode 100644 test/e2e/logstash/logstash_test.go create mode 100644 test/e2e/test/logstash/builder.go create mode 100644 test/e2e/test/logstash/checks.go create mode 100644 test/e2e/test/logstash/steps.go diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index d6a285a6dc..968393ef3d 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9631,6 +9631,10 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 1d86f803e1..b652b0ed80 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -7994,4 +7994,8 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 347de6c534..24afce4ccd 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9685,6 +9685,10 @@ spec: served: true storage: true subresources: + scale: + labelSelectorPath: .status.selector + specReplicasPath: .spec.count + statusReplicasPath: .status.count status: {} --- apiVersion: apiextensions.k8s.io/v1 diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 47c12f4a87..c0e97542fd 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -89,6 +89,7 @@ type LogstashStatus struct { // +kubebuilder:printcolumn:name="expected",type="integer",JSONPath=".status.expectedNodes",description="Expected nodes" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".status.version",description="Logstash version" +// +kubebuilder:subresource:scale:specpath=.spec.count,statuspath=.status.count,selectorpath=.status.selector // +kubebuilder:storageversion type Logstash struct { metav1.TypeMeta `json:",inline"` diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 4b9f1ebe91..08cd574aa4 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -166,11 +166,6 @@ func Test_checkSupportedVersion(t *testing.T) { version: "8.7.1", wantErr: false, }, - { - name: "at min supported", - version: "8.7.0", - wantErr: false, - }, } { t.Run(tt.name, func(t *testing.T) { a := Logstash{ diff --git a/pkg/controller/common/version/version.go b/pkg/controller/common/version/version.go index d359f18371..0959920647 100644 --- a/pkg/controller/common/version/version.go +++ b/pkg/controller/common/version/version.go @@ -33,7 +33,7 @@ var ( // Due to bugfixes present in 7.14 that ECK depends on, this is the lowest version we support in Fleet mode. SupportedFleetModeAgentVersions = MinMaxVersion{Min: MustParse("7.14.0-SNAPSHOT"), Max: From(8, 99, 99)} SupportedMapsVersions = MinMaxVersion{Min: From(7, 11, 0), Max: From(8, 99, 99)} - SupportedLogstashVersions = MinMaxVersion{Min: From(8, 7, 0), Max: From(8, 99, 99)} + SupportedLogstashVersions = MinMaxVersion{Min: From(8, 6, 0), Max: From(8, 99, 99)} // minPreReleaseVersion is the lowest prerelease identifier as numeric prerelease takes precedence before // alphanumeric ones and it can't have leading zeros. diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index f6a4af0146..d6c139b83a 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -81,8 +81,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - WithReadinessProbe(readinessProbe(false)). - WithLivenessProbe(livenessProbe(false)). + //WithReadinessProbe(readinessProbe(false)). + //WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go new file mode 100644 index 0000000000..d994ad81e2 --- /dev/null +++ b/test/e2e/logstash/logstash_test.go @@ -0,0 +1,36 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +//go:build logstash || e2e + +package logstash + +import ( + "testing" + + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" +) + +func TestSingleLogstash(t *testing.T) { + name := "test-single-logstash" + logstashBuilder := logstash.NewBuilder(name). + WithNodeCount(1) + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + +func TestLogstashServerVersionUpgradeToLatest8x(t *testing.T) { + srcVersion, dstVersion := test.GetUpgradePathTo8x(test.Ctx().ElasticStackVersion) + + name := "test-ls-version-upgrade-8x" + + logstash := logstash.NewBuilder(name). + WithNodeCount(2). + WithVersion(srcVersion). + WithRestrictedSecurityContext() + + logstashUpgraded := logstash.WithVersion(dstVersion).WithMutatedFrom(&logstash) + + test.RunMutations(t, []test.Builder{logstash}, []test.Builder{logstashUpgraded}) +} diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index 8989fc2e82..f3b4d13ddf 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -33,6 +33,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/agent" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/apmserver" beatcommon "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/common" @@ -42,6 +43,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/kibana" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/maps" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) @@ -92,6 +94,9 @@ func CreateClient() (k8s.Client, error) { if err := agentv1alpha1.AddToScheme(scheme.Scheme); err != nil { return nil, err } + if err := logstashv1alpha1.AddToScheme(scheme.Scheme); err != nil { + return nil, err + } client, err := k8sclient.New(cfg, k8sclient.Options{Scheme: scheme.Scheme}) if err != nil { return nil, err @@ -431,6 +436,15 @@ func AgentPodListOptions(agentNamespace, agentName string) []k8sclient.ListOptio return []k8sclient.ListOption{ns, matchLabels} } +func LogstashPodListOptions(logstashNamespace, logstashName string) []k8sclient.ListOption { + ns := k8sclient.InNamespace(logstashNamespace) + matchLabels := k8sclient.MatchingLabels(map[string]string{ + commonv1.TypeLabelName: logstash.TypeLabelValue, + logstash.NameLabelName: logstashName, + }) + return []k8sclient.ListOption{ns, matchLabels} +} + func BeatPodListOptions(beatNamespace, beatName, beatType string) []k8sclient.ListOption { ns := k8sclient.InNamespace(beatNamespace) matchLabels := k8sclient.MatchingLabels(map[string]string{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go new file mode 100644 index 0000000000..8b08b9119d --- /dev/null +++ b/test/e2e/test/logstash/builder.go @@ -0,0 +1,146 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + +type Builder struct { + Logstash v1alpha1.Logstash + MutatedFrom *Builder +} + +func NewBuilder(name string) Builder { + return newBuilder(name, rand.String(4)) +} + +func NewBuilderWithoutSuffix(name string) Builder { + return newBuilder(name, "") +} + +func newBuilder(name, randSuffix string) Builder { + meta := metav1.ObjectMeta{ + Name: name, + Namespace: test.Ctx().ManagedNamespace(0), + } + def := test.Ctx().ImageDefinitionFor(v1alpha1.Kind) + return Builder{ + Logstash: v1alpha1.Logstash{ + ObjectMeta: meta, + Spec: v1alpha1.LogstashSpec{ + Count: 1, + Version: def.Version, + }, + }, + }. + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) +} + +func (b Builder) WithImage(image string) Builder { + b.Logstash.Spec.Image = image + return b +} + +func (b Builder) WithSuffix(suffix string) Builder { + if suffix != "" { + b.Logstash.ObjectMeta.Name = b.Logstash.ObjectMeta.Name + "-" + suffix + } + return b +} + +func (b Builder) WithLabel(key, value string) Builder { + if b.Logstash.Labels == nil { + b.Logstash.Labels = make(map[string]string) + } + b.Logstash.Labels[key] = value + + return b +} + +// WithRestrictedSecurityContext helps to enforce a restricted security context on the objects. +func (b Builder) WithRestrictedSecurityContext() Builder { + b.Logstash.Spec.PodTemplate.Spec.SecurityContext = test.DefaultSecurityContext() + return b +} + +func (b Builder) WithNamespace(namespace string) Builder { + b.Logstash.ObjectMeta.Namespace = namespace + return b +} + +func (b Builder) WithVersion(version string) Builder { + b.Logstash.Spec.Version = version + return b +} + +func (b Builder) WithNodeCount(count int) Builder { + b.Logstash.Spec.Count = int32(count) + return b +} + +// WithPodLabel sets the label in the pod template. All invocations can be removed when +// https://github.com/elastic/cloud-on-k8s/issues/2652 is implemented. +func (b Builder) WithPodLabel(key, value string) Builder { + labels := b.Logstash.Spec.PodTemplate.Labels + if labels == nil { + labels = make(map[string]string) + } + labels[key] = value + b.Logstash.Spec.PodTemplate.Labels = labels + return b +} + +func (b Builder) WithMutatedFrom(mutatedFrom *Builder) Builder { + b.MutatedFrom = mutatedFrom + return b +} + +func (b Builder) NSN() types.NamespacedName { + return k8s.ExtractNamespacedName(&b.Logstash) +} + +func (b Builder) Kind() string { + return v1alpha1.Kind +} + +func (b Builder) Spec() interface{} { + return b.Logstash.Spec +} + +func (b Builder) Count() int32 { + return b.Logstash.Spec.Count +} + +func (b Builder) ServiceName() string { + return b.Logstash.Name + "-ls-http" +} + +func (b Builder) ListOptions() []client.ListOption { + return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) +} + + +func (b Builder) SkipTest() bool { + supportedVersions := version.SupportedLogstashVersions + + ver := version.MustParse(b.Logstash.Spec.Version) + return supportedVersions.WithinRange(ver) != nil +} + +var _ test.Builder = Builder{} +var _ test.Subject = Builder{} diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go new file mode 100644 index 0000000000..2e50f486d2 --- /dev/null +++ b/test/e2e/test/logstash/checks.go @@ -0,0 +1,64 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + + +// CheckSecrets checks that expected secrets have been created. +func CheckSecrets(b Builder, k *test.K8sClient) test.Step { + return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { + logstashName := b.Logstash.Name + // hardcode all secret names and keys to catch any breaking change + expected := []test.ExpectedSecret{ + { + Name: logstashName + "-ls-config", + Keys: []string{"logstash.yml"}, + Labels: map[string]string{ + "eck.k8s.elastic.co/credentials": "true", + "logstash.k8s.elastic.co/name": logstashName, + }, + }, + } + return expected + }) +} + +func CheckStatus(b Builder, k *test.K8sClient) test.Step { + return test.Step{ + Name: "Logstash status should have the correct status", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { + return err + } + + logstash.Status.ObservedGeneration = 0 + + expected := logstashv1alpha1.LogstashStatus{ + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, + Version: b.Logstash.Spec.Version, + } + if logstash.Status != expected { + return fmt.Errorf("expected status %+v but got %+v", expected, logstash.Status) + } + return nil + }), + } +} + +func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { + println(test.Ctx().TestTimeout) + // TODO: Add stack checks + return test.StepList{} +} diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go new file mode 100644 index 0000000000..2c66762429 --- /dev/null +++ b/test/e2e/test/logstash/steps.go @@ -0,0 +1,155 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + //"k8s.io/apimachinery/pkg/types" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/generation" +) + +func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { + return []test.Step{ + { + Name: "K8S should be accessible", + Test: test.Eventually(func() error { + pods := corev1.PodList{} + return k.Client.List(context.Background(), &pods) + }), + }, + { + Name: "Label test pods", + Test: test.Eventually(func() error { + return test.LabelTestPods( + k.Client, + test.Ctx(), + run.TestNameLabel, + b.Logstash.Labels[run.TestNameLabel]) + }), + Skip: func() bool { + return test.Ctx().Local + }, + }, + { + Name: "Logstash CRDs should exist", + Test: test.Eventually(func() error { + crd := &logstashv1alpha1.LogstashList{} + return k.Client.List(context.Background(), crd) + }), + }, + { + Name: "Remove Logstash if it already exists", + Test: test.Eventually(func() error { + err := k.Client.Delete(context.Background(), &b.Logstash) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + // wait for pods to disappear + return k.CheckPodCount(0, test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name)...) + }), + }, + } +} + +func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Submitting the Logstash resource should succeed", + Test: test.Eventually(func() error { + return k.CreateOrUpdate(&b.Logstash) + }), + }, + { + Name: "Logstash should be created", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + return k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash) + }), + }, + } +} + +func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + CheckSecrets(b, k), + CheckStatus(b, k), + checks.CheckServices(b, k), + checks.CheckServicesEndpoints(b, k), + checks.CheckPods(b, k), + } +} + +func (b Builder) UpgradeTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Updating the Logstash spec succeed", + Test: test.Eventually(func() error { + var logstash logstashv1alpha1.Logstash + if err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), &logstash); err != nil { + return err + } + logstash.Spec = b.Logstash.Spec + return k.Client.Update(context.Background(), &logstash) + }), + }} +} + +func (b Builder) MutationTestSteps(k *test.K8sClient) test.StepList { + var entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation int64 + isMutated := b.MutatedFrom != nil + + return test.StepList{ + generation.RetrieveGenerationsStep(&b.Logstash, k, &entSearchGenerationBeforeMutation, &entSearchObservedGenerationBeforeMutation), + }.WithSteps(test.AnnotatePodsWithBuilderHash(b, b.MutatedFrom, k)). + WithSteps(b.UpgradeTestSteps(k)). + WithSteps(b.CheckK8sTestSteps(k)). + WithSteps(b.CheckStackTestSteps(k)). + WithStep(generation.CompareObjectGenerationsStep(&b.Logstash, k, isMutated, entSearchGenerationBeforeMutation, entSearchObservedGenerationBeforeMutation)) +} + +func (b Builder) DeletionTestSteps(k *test.K8sClient) test.StepList { + return test.StepList{ + { + Name: "Deleting Logstash should return no error", + Test: test.Eventually(func() error { + err := k.Client.Delete(context.Background(), &b.Logstash) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + return nil + }), + }, + { + Name: "Logstash should not be there anymore", + Test: test.Eventually(func() error { + objCopy := k8s.DeepCopyObject(&b.Logstash) + err := k.Client.Get(context.Background(), k8s.ExtractNamespacedName(&b.Logstash), objCopy) + if err != nil && apierrors.IsNotFound(err) { + return nil + } + return fmt.Errorf("expected 404 not found API error here. got: %w", err) + }), + }, + { + Name: "Logstash pods should eventually be removed", + Test: test.Eventually(func() error { + return k.CheckPodCount(0, b.ListOptions()...) + }), + }, + } +} From 26926616ca09d0747146eda82513a9027451f7fc Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 15 Feb 2023 18:36:56 -0500 Subject: [PATCH 050/160] Revert "Revert "Temporarily take out probes"" This reverts commit d4908b72314d9fd026f75be492674c3cd6407604. --- pkg/controller/common/container/defaulter.go | 7 -- .../common/defaults/pod_template.go | 6 -- pkg/controller/logstash/pod.go | 93 ++++++++++--------- test/e2e/test/logstash/builder.go | 13 ++- test/e2e/test/logstash/checks.go | 7 +- test/e2e/test/logstash/steps.go | 11 ++- 6 files changed, 62 insertions(+), 75 deletions(-) diff --git a/pkg/controller/common/container/defaulter.go b/pkg/controller/common/container/defaulter.go index 0b03d42aa0..c007b0be79 100644 --- a/pkg/controller/common/container/defaulter.go +++ b/pkg/controller/common/container/defaulter.go @@ -96,13 +96,6 @@ func (d Defaulter) WithReadinessProbe(readinessProbe *corev1.Probe) Defaulter { return d } -func (d Defaulter) WithLivenessProbe(livenessProbe *corev1.Probe) Defaulter { - if d.base.LivenessProbe == nil { - d.base.LivenessProbe = livenessProbe - } - return d -} - // envExists checks if an env var with the given name already exists in the provided slice. func (d Defaulter) envExists(name string) bool { for _, v := range d.base.Env { diff --git a/pkg/controller/common/defaults/pod_template.go b/pkg/controller/common/defaults/pod_template.go index 073223a0c0..81cfea9331 100644 --- a/pkg/controller/common/defaults/pod_template.go +++ b/pkg/controller/common/defaults/pod_template.go @@ -121,12 +121,6 @@ func (b *PodTemplateBuilder) WithReadinessProbe(readinessProbe corev1.Probe) *Po return b } -// WithLivenessProbe sets up the given liveness probe, unless already provided in the template. -func (b *PodTemplateBuilder) WithLivenessProbe(livenessProbe corev1.Probe) *PodTemplateBuilder { - b.containerDefaulter.WithLivenessProbe(&livenessProbe) - return b -} - // WithAffinity sets a default affinity, unless already provided in the template. // An empty affinity in the spec is not overridden. func (b *PodTemplateBuilder) WithAffinity(affinity *corev1.Affinity) *PodTemplateBuilder { diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index d6c139b83a..281757d135 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -11,7 +11,8 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/apimachinery/pkg/util/intstr" + + // "k8s.io/apimachinery/pkg/util/intstr" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" @@ -81,8 +82,8 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - //WithReadinessProbe(readinessProbe(false)). - //WithLivenessProbe(livenessProbe(false)). + // WithReadinessProbe(readinessProbe(false)). + // WithLivenessProbe(livenessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled @@ -102,46 +103,46 @@ func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.Conta } } -// readinessProbe is the readiness probe for the Logstash container -func readinessProbe(useTLS bool) corev1.Probe { - scheme := corev1.URISchemeHTTP - if useTLS { - scheme = corev1.URISchemeHTTPS - } - return corev1.Probe{ - FailureThreshold: 3, - InitialDelaySeconds: 30, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Port: intstr.FromInt(network.HTTPPort), - Path: "/", - Scheme: scheme, - }, - }, - } -} - -// livenessProbe is the liveness probe for the Logstash container -func livenessProbe(useTLS bool) corev1.Probe { - scheme := corev1.URISchemeHTTP - if useTLS { - scheme = corev1.URISchemeHTTPS - } - return corev1.Probe{ - FailureThreshold: 3, - InitialDelaySeconds: 60, - PeriodSeconds: 10, - SuccessThreshold: 1, - TimeoutSeconds: 5, - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Port: intstr.FromInt(network.HTTPPort), - Path: "/", - Scheme: scheme, - }, - }, - } -} +//// readinessProbe is the readiness probe for the Logstash container +// func readinessProbe(useTLS bool) corev1.Probe { +// scheme := corev1.URISchemeHTTP +// if useTLS { +// scheme = corev1.URISchemeHTTPS +// } +// return corev1.Probe{ +// FailureThreshold: 3, +// InitialDelaySeconds: 30, +// PeriodSeconds: 10, +// SuccessThreshold: 1, +// TimeoutSeconds: 5, +// ProbeHandler: corev1.ProbeHandler{ +// HTTPGet: &corev1.HTTPGetAction{ +// Port: intstr.FromInt(network.HTTPPort), +// Path: "/", +// Scheme: scheme, +// }, +// }, +// } +//} +// +//// livenessProbe is the liveness probe for the Logstash container +// func livenessProbe(useTLS bool) corev1.Probe { +// scheme := corev1.URISchemeHTTP +// if useTLS { +// scheme = corev1.URISchemeHTTPS +// } +// return corev1.Probe{ +// FailureThreshold: 3, +// InitialDelaySeconds: 60, +// PeriodSeconds: 10, +// SuccessThreshold: 1, +// TimeoutSeconds: 5, +// ProbeHandler: corev1.ProbeHandler{ +// HTTPGet: &corev1.HTTPGetAction{ +// Port: intstr.FromInt(network.HTTPPort), +// Path: "/", +// Scheme: scheme, +// }, +// }, +// } +//} diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 8b08b9119d..8ae6cd1678 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -18,7 +18,7 @@ import ( ) type Builder struct { - Logstash v1alpha1.Logstash + Logstash v1alpha1.Logstash MutatedFrom *Builder } @@ -40,15 +40,15 @@ func newBuilder(name, randSuffix string) Builder { Logstash: v1alpha1.Logstash{ ObjectMeta: meta, Spec: v1alpha1.LogstashSpec{ - Count: 1, + Count: 1, Version: def.Version, }, }, }. - WithImage(def.Image). - WithSuffix(randSuffix). - WithLabel(run.TestNameLabel, name). - WithPodLabel(run.TestNameLabel, name) + WithImage(def.Image). + WithSuffix(randSuffix). + WithLabel(run.TestNameLabel, name). + WithPodLabel(run.TestNameLabel, name) } func (b Builder) WithImage(image string) Builder { @@ -134,7 +134,6 @@ func (b Builder) ListOptions() []client.ListOption { return test.LogstashPodListOptions(b.Logstash.Namespace, b.Logstash.Name) } - func (b Builder) SkipTest() bool { supportedVersions := version.SupportedLogstashVersions diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 2e50f486d2..6c8ed2d188 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -13,7 +13,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) - // CheckSecrets checks that expected secrets have been created. func CheckSecrets(b Builder, k *test.K8sClient) test.Step { return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { @@ -25,7 +24,7 @@ func CheckSecrets(b Builder, k *test.K8sClient) test.Step { Keys: []string{"logstash.yml"}, Labels: map[string]string{ "eck.k8s.elastic.co/credentials": "true", - "logstash.k8s.elastic.co/name": logstashName, + "logstash.k8s.elastic.co/name": logstashName, }, }, } @@ -45,8 +44,8 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { logstash.Status.ObservedGeneration = 0 expected := logstashv1alpha1.LogstashStatus{ - ExpectedNodes: b.Logstash.Spec.Count, - AvailableNodes: b.Logstash.Spec.Count, + ExpectedNodes: b.Logstash.Spec.Count, + AvailableNodes: b.Logstash.Spec.Count, Version: b.Logstash.Spec.Version, } if logstash.Status != expected { diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index 2c66762429..44f2a5f4e0 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -10,12 +10,13 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - //"k8s.io/apimachinery/pkg/types" + + // "k8s.io/apimachinery/pkg/types" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - //mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - //"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + // mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -52,7 +53,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { return k.Client.List(context.Background(), crd) }), }, - { + { Name: "Remove Logstash if it already exists", Test: test.Eventually(func() error { err := k.Client.Delete(context.Background(), &b.Logstash) From 865d06a39254c3fe74446d703edad74e02693e65 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 09:22:19 -0500 Subject: [PATCH 051/160] Tidying up --- config/samples/logstash/logstash.yaml | 2 +- hack/operatorhub/config.yaml | 2 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 3 +++ pkg/controller/logstash/driver.go | 20 -------------------- test/e2e/test/elasticsearch/checks_k8s.go | 2 +- 5 files changed, 6 insertions(+), 23 deletions(-) diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml index 530891e91a..e6283a9568 100644 --- a/config/samples/logstash/logstash.yaml +++ b/config/samples/logstash/logstash.yaml @@ -6,7 +6,7 @@ spec: version: 8.6.1 nodeSets: - name: default - count: 1 + count: 3 config: node.store.allow_mmap: false --- diff --git a/hack/operatorhub/config.yaml b/hack/operatorhub/config.yaml index 0c28f2c3f2..d5caad1d3c 100644 --- a/hack/operatorhub/config.yaml +++ b/hack/operatorhub/config.yaml @@ -30,7 +30,7 @@ crds: - name: stackconfigpolicies.stackconfigpolicy.k8s.elastic.co displayName: Elastic Stack Config Policy description: Elastic Stack Config Policy - - name: logstashes.stackconfigpolicy.k8s.elastic.co + - name: logstashes.logstash.k8s.elastic.co displayName: Logstash description: Logstash instance packages: diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index c0e97542fd..0d10621327 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -40,6 +40,9 @@ type LogstashSpec struct { ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"` // HTTP holds the HTTP layer configuration for the Logstash Metrics API + // TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks + // a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to + // be opened up for other services: beats, TCP, UDP, etc, inputs // +kubebuilder:validation:Optional HTTP commonv1.HTTPConfig `json:"http,omitempty"` diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 54372a4701..4be3660336 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -82,26 +82,6 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log return results.WithError(err), params.Status } - // _, results = certificates.Reconciler{ - // K8sClient: params.Client, - // DynamicWatches: params.Watches, - // Owner: ¶ms.Logstash, - // TLSOptions: params.Logstash.Spec.HTTP.TLS, - // Namer: logstashv1alpha1.Namer, - // Labels: params.Logstash.GetIdentityLabels(), - // Services: []corev1.Service{*svc}, - // GlobalCA: params.OperatorParams.GlobalCA, - // CACertRotation: params.OperatorParams.CACertRotation, - // CertRotation: params.OperatorParams.CertRotation, - // GarbageCollectSecrets: true, - // }.ReconcileCAAndHTTPCerts(params.Context) - // - // if results.HasError() { - // _, err := results.Aggregate() - // k8s.EmitErrorEvent(params.Recorder(), err, ¶ms.Logstash, events.EventReconciliationError, "Certificate reconciliation error: %v", err) - // return results, params.Status - //} - configHash := fnv.New32a() if res := reconcileConfig(params, configHash); res.HasError() { diff --git a/test/e2e/test/elasticsearch/checks_k8s.go b/test/e2e/test/elasticsearch/checks_k8s.go index b6bbdede91..b0cc7b114b 100644 --- a/test/e2e/test/elasticsearch/checks_k8s.go +++ b/test/e2e/test/elasticsearch/checks_k8s.go @@ -35,7 +35,7 @@ const ( // but it occasionally takes longer for various reasons (long Pod creation time, long volume binding, etc.). // We use a longer timeout here to not be impacted too much by those external factors, and only fail // if things seem to be stuck. - RollingUpgradeTimeout = 10 * time.Minute + RollingUpgradeTimeout = 30 * time.Minute ) func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { From 84dd4899aef5619cee19c9ecf76c87a3b53828c5 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 11:43:27 -0500 Subject: [PATCH 052/160] Add Logstash to sample and stack tests --- config/crds/v1/all-crds.yaml | 8 +++++-- .../logstash.k8s.elastic.co_logstashes.yaml | 8 +++++-- .../eck-operator-crds/templates/all-crds.yaml | 8 +++++-- .../logstash/v1alpha1/groupversion_info.go | 6 ++--- pkg/apis/logstash/v1alpha1/webhook.go | 2 +- test/e2e/logstash/logstash_test.go | 7 ++++++ test/e2e/samples_test.go | 7 ++++++ test/e2e/stack_test.go | 24 +++++++++++++++---- test/e2e/test/helper/yaml.go | 16 ++++++++++++- 9 files changed, 71 insertions(+), 15 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 968393ef3d..4c8e3d228d 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9118,8 +9118,12 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Logstash - Metrics API + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' properties: service: description: Service defines the template for the associated Kubernetes diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index b652b0ed80..099a90ce2c 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -74,8 +74,12 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Logstash - Metrics API + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' properties: service: description: Service defines the template for the associated Kubernetes diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 24afce4ccd..b926b6c0de 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9172,8 +9172,12 @@ spec: format: int32 type: integer http: - description: HTTP holds the HTTP layer configuration for the Logstash - Metrics API + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' properties: service: description: Service defines the template for the associated Kubernetes diff --git a/pkg/apis/logstash/v1alpha1/groupversion_info.go b/pkg/apis/logstash/v1alpha1/groupversion_info.go index 5589c3a240..72425bd52a 100644 --- a/pkg/apis/logstash/v1alpha1/groupversion_info.go +++ b/pkg/apis/logstash/v1alpha1/groupversion_info.go @@ -10,11 +10,11 @@ import ( ) var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "logstash.k8s.elastic.co", Version: "v1alpha1"} + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "logstash.k8s.elastic.co", Version: "v1alpha1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} // AddToScheme is required by pkg/client/... AddToScheme = SchemeBuilder.AddToScheme diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go index 76b564678d..ab9f69de37 100644 --- a/pkg/apis/logstash/v1alpha1/webhook.go +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -22,7 +22,7 @@ const ( ) var ( - groupKind = schema.GroupKind{Group: SchemeGroupVersion.Group, Kind: Kind} + groupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: Kind} validationLog = ulog.Log.WithName("logstash-v1alpha1-validation") ) diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go index d994ad81e2..96c8cd93ce 100644 --- a/test/e2e/logstash/logstash_test.go +++ b/test/e2e/logstash/logstash_test.go @@ -20,6 +20,13 @@ func TestSingleLogstash(t *testing.T) { test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) } +func TestMultipleLogstashes(t *testing.T) { + name := "test-multiple-logstashes" + logstashBuilder := logstash.NewBuilder(name). + WithNodeCount(3) + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + func TestLogstashServerVersionUpgradeToLatest8x(t *testing.T) { srcVersion, dstVersion := test.GetUpgradePathTo8x(test.Ctx().ElasticStackVersion) diff --git a/test/e2e/samples_test.go b/test/e2e/samples_test.go index 058208bf25..c0ee2a3bdb 100644 --- a/test/e2e/samples_test.go +++ b/test/e2e/samples_test.go @@ -23,6 +23,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/helper" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/kibana" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" ) func TestSamples(t *testing.T) { @@ -81,6 +82,12 @@ func createBuilders(t *testing.T, decoder *helper.YAMLDecoder, sampleFile, testN WithRestrictedSecurityContext(). WithLabel(run.TestNameLabel, fullTestName). WithPodLabel(run.TestNameLabel, fullTestName) + case logstash.Builder: + return b.WithNamespace(namespace). + WithSuffix(suffix). + WithRestrictedSecurityContext(). + WithLabel(run.TestNameLabel, fullTestName). + WithPodLabel(run.TestNameLabel, fullTestName) default: return b } diff --git a/test/e2e/stack_test.go b/test/e2e/stack_test.go index c2e739b0c4..69faa4948a 100644 --- a/test/e2e/stack_test.go +++ b/test/e2e/stack_test.go @@ -19,6 +19,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/filebeat" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" @@ -28,6 +29,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/beat" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/enterprisesearch" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/kibana" ) @@ -72,6 +74,9 @@ func TestVersionUpgradeOrdering(t *testing.T) { WithElasticsearchRef(esRef). WithRestrictedSecurityContext() entUpdated := ent.WithVersion(updatedVersion) + logstash := logstash.NewBuilder("ls"). + WithVersion(initialVersion) // pre 8.x doesn't require any config, but we change the version after calling + logstashUpdated := logstash.WithVersion(updatedVersion) fb := beat.NewBuilder("fb"). WithType(filebeat.Type). WithRoles(beat.AutodiscoverClusterRoleName). @@ -81,8 +86,8 @@ func TestVersionUpgradeOrdering(t *testing.T) { fb = beat.ApplyYamls(t, fb, beattests.E2EFilebeatConfig, beattests.E2EFilebeatPodTemplate) fbUpdated := fb.WithVersion(updatedVersion) - initialBuilders := []test.Builder{es, kb, apm, ent, fb} - updatedBuilders := []test.Builder{esUpdated, kbUpdated, apmUpdated, entUpdated, fbUpdated} + initialBuilders := []test.Builder{es, kb, apm, ent, fb, logstash} + updatedBuilders := []test.Builder{esUpdated, kbUpdated, apmUpdated, entUpdated, fbUpdated, logstashUpdated} versionUpgrade := func(k *test.K8sClient) test.StepList { steps := test.StepList{} @@ -101,6 +106,7 @@ func TestVersionUpgradeOrdering(t *testing.T) { ApmServer: ref(k8s.ExtractNamespacedName(&apm.ApmServer)), EnterpriseSearch: ref(k8s.ExtractNamespacedName(&ent.EnterpriseSearch)), Beat: ref(k8s.ExtractNamespacedName(&fb.Beat)), + Logstash: ref(k8s.ExtractNamespacedName(&logstash.Logstash)), } err := stackVersions.Retrieve(k.Client) // check the retrieved versions first (before returning on err) @@ -128,6 +134,7 @@ type StackResourceVersions struct { ApmServer refVersion EnterpriseSearch refVersion Beat refVersion + Logstash refVersion } func (s StackResourceVersions) IsValid() bool { @@ -140,7 +147,7 @@ func (s StackResourceVersions) IsValid() bool { } func (s StackResourceVersions) AllSetTo(version string) bool { - for _, ref := range []refVersion{s.Elasticsearch, s.Kibana, s.ApmServer, s.EnterpriseSearch, s.Beat} { + for _, ref := range []refVersion{s.Elasticsearch, s.Kibana, s.ApmServer, s.EnterpriseSearch, s.Beat, s.Logstash} { if ref.version != version { return false } @@ -149,7 +156,7 @@ func (s StackResourceVersions) AllSetTo(version string) bool { } func (s *StackResourceVersions) Retrieve(client k8s.Client) error { - calls := []func(c k8s.Client) error{s.retrieveBeat, s.retrieveApmServer, s.retrieveKibana, s.retrieveEnterpriseSearch, s.retrieveElasticsearch} + calls := []func(c k8s.Client) error{s.retrieveBeat, s.retrieveApmServer, s.retrieveKibana, s.retrieveEnterpriseSearch, s.retrieveElasticsearch, s.retrieveLogstash} // grab at least one error if multiple occur var callsErr error for _, f := range calls { @@ -223,3 +230,12 @@ func (s *StackResourceVersions) retrieveBeat(c k8s.Client) error { s.Beat.version = beat.Status.Version return nil } + +func (s *StackResourceVersions) retrieveLogstash(c k8s.Client) error { + var logstash logstashv1alpha1.Logstash + if err := c.Get(context.Background(), s.Logstash.ref, &logstash); err != nil { + return err + } + s.Logstash.version = logstash.Status.Version + return nil +} diff --git a/test/e2e/test/helper/yaml.go b/test/e2e/test/helper/yaml.go index 0a035aa340..a567e1c0a5 100644 --- a/test/e2e/test/helper/yaml.go +++ b/test/e2e/test/helper/yaml.go @@ -33,6 +33,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" entv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/enterprisesearch/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" beatcommon "github.com/elastic/cloud-on-k8s/v2/pkg/controller/beat/common" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -42,6 +43,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/enterprisesearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/kibana" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" ) type BuilderTransform func(test.Builder) test.Builder @@ -59,7 +61,7 @@ func NewYAMLDecoder() *YAMLDecoder { scheme.AddKnownTypes(beatv1beta1.GroupVersion, &beatv1beta1.Beat{}, &beatv1beta1.BeatList{}) scheme.AddKnownTypes(entv1.GroupVersion, &entv1.EnterpriseSearch{}, &entv1.EnterpriseSearchList{}) scheme.AddKnownTypes(agentv1alpha1.GroupVersion, &agentv1alpha1.Agent{}, &agentv1alpha1.AgentList{}) - + scheme.AddKnownTypes(logstashv1alpha1.GroupVersion, &logstashv1alpha1.Logstash{}, &logstashv1alpha1.LogstashList{}) scheme.AddKnownTypes(rbacv1.SchemeGroupVersion, &rbacv1.ClusterRoleBinding{}, &rbacv1.ClusterRoleBindingList{}) scheme.AddKnownTypes(rbacv1.SchemeGroupVersion, &rbacv1.ClusterRole{}, &rbacv1.ClusterRoleList{}) scheme.AddKnownTypes(corev1.SchemeGroupVersion, &corev1.ServiceAccount{}, &corev1.ServiceAccountList{}) @@ -108,6 +110,10 @@ func (yd *YAMLDecoder) ToBuilders(reader *bufio.Reader, transform BuilderTransfo b := enterprisesearch.NewBuilderWithoutSuffix(decodedObj.Name) b.EnterpriseSearch = *decodedObj builder = transform(b) + case *logstashv1alpha1.Logstash: + b := logstash.NewBuilderWithoutSuffix(decodedObj.Name) + b.Logstash = *decodedObj + builder = transform(b) default: return builders, fmt.Errorf("unexpected object type: %t", decodedObj) } @@ -304,6 +310,14 @@ func transformToE2E(namespace, fullTestName, suffix string, transformers []Build b = b.WithPodTemplateServiceAccount(b.PodTemplate.Spec.ServiceAccountName + "-" + suffix) } + builder = b + case *logstashv1alpha1.Logstash: + b := logstash.NewBuilderWithoutSuffix(decodedObj.Name) + b = b.WithNamespace(namespace). + WithSuffix(suffix). + WithLabel(run.TestNameLabel, fullTestName). + WithPodLabel(run.TestNameLabel, fullTestName) + builder = b case *corev1.ServiceAccount: decodedObj.Namespace = namespace From 12430d943d66893d1adab19d3f077c0c3f94a91e Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 12:45:37 -0500 Subject: [PATCH 053/160] Added basic logstash verification Add a test to make sure that Logstash is running, by testing the metrics API endpoint and checking that the value of status is "green" --- docs/reference/api-docs.asciidoc | 2 +- test/e2e/test/logstash/checks.go | 32 ++++++++++++- test/e2e/test/logstash/http_client.go | 67 +++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 test/e2e/test/logstash/http_client.go diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index c1a58e4930..781b519f72 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1876,7 +1876,7 @@ LogstashSpec defines the desired state of Logstash | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. -| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API +| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 6c8ed2d188..e98540c6fc 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -6,6 +6,7 @@ package logstash import ( "context" + "encoding/json" "fmt" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" @@ -13,6 +14,11 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) +type logstashStatus struct { + Version string `json:"version"` + Status string `json:"status"` +} + // CheckSecrets checks that expected secrets have been created. func CheckSecrets(b Builder, k *test.K8sClient) test.Step { return test.CheckSecretsContent(k, b.Logstash.Namespace, func() []test.ExpectedSecret { @@ -58,6 +64,28 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { println(test.Ctx().TestTimeout) - // TODO: Add stack checks - return test.StepList{} + return test.StepList{ + { + Name: "Logstash should respond to requests", + Test: test.Eventually(func() error { + client, err := NewLogstashClient(b.Logstash, k) + if err != nil { + return err + } + bytes, err := DoRequest(client, b.Logstash, "GET", "/") + if err != nil { + return err + } + var status logstashStatus + if err := json.Unmarshal(bytes, &status); err != nil { + return err + } + + if status.Status != "green" { + return fmt.Errorf("expected green but got %s", status.Status) + } + return nil + }), + }, + } } diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go new file mode 100644 index 0000000000..d36519624e --- /dev/null +++ b/test/e2e/test/logstash/http_client.go @@ -0,0 +1,67 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "crypto/x509" + "fmt" + "io" + "net/http" + "net/url" + + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" +) + +type APIError struct { + StatusCode int + msg string +} + +func (e *APIError) Error() string { + return e.msg +} + +// TODO refactor identical to Kibana client +func NewLogstashClient(logstash v1alpha1.Logstash, k *test.K8sClient) (*http.Client, error) { + var caCerts []*x509.Certificate + // if ems.Spec.HTTP.TLS.Enabled() { + // crts, err := k.GetHTTPCerts(maps.EMSNamer, ems.Namespace, ems.Name) + // if err != nil { + // return nil, err + // } + // caCerts = crts + //} + return test.NewHTTPClient(caCerts), nil +} + +func DoRequest(client *http.Client, logstash v1alpha1.Logstash, method, path string) ([]byte, error) { + scheme := "http" + + url, err := url.Parse(fmt.Sprintf("%s://%s.%s.svc:9600%s", scheme, v1alpha1.HTTPServiceName(logstash.Name), logstash.Namespace, path)) + if err != nil { + return nil, fmt.Errorf("while parsing URL: %w", err) + } + + request, err := http.NewRequestWithContext(context.Background(), method, url.String(), nil) + if err != nil { + return nil, fmt.Errorf("while constructing request: %w", err) + } + + resp, err := client.Do(request) + if err != nil { + return nil, fmt.Errorf("while making request: %w", err) + } + defer resp.Body.Close() + if resp.StatusCode < 200 || resp.StatusCode > 299 { + return nil, &APIError{ + StatusCode: resp.StatusCode, + msg: fmt.Sprintf("fail to request %s, status is %d)", path, resp.StatusCode), + } + } + return io.ReadAll(resp.Body) +} From d2ac277b1db4e2400614a4b1c479ec8353a8b55d Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 16:28:55 -0500 Subject: [PATCH 054/160] Fix readiness probe This commit fixes the readiness probe, by setting the default visibility of the logstash API to 0.0.0.0, allowing access to the metrics API to the probe --- pkg/controller/logstash/config.go | 4 +- pkg/controller/logstash/pod.go | 69 +++++++++++-------------------- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index 4a3fc0ed63..2536c6c70d 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -115,10 +115,10 @@ func getUserConfig(params Params) (*settings.CanonicalConfig, error) { return common.ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.ConfigRef, LogstashConfigFileName) } -// TODO: remove testing value func defaultConfig() *settings.CanonicalConfig { settingsMap := map[string]interface{}{ - "node.name": "test", + // Set 'api.http.host' by defaut to `0.0.0.0` for readiness probe to work. + "api.http.host": "0.0.0.0", } return settings.MustCanonicalConfig(settingsMap) diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 281757d135..077547de38 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -12,7 +12,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - // "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/apimachinery/pkg/util/intstr" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" @@ -82,8 +82,7 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS WithDockerImage(spec.Image, container.ImageRepository(container.LogstashImage, spec.Version)). WithAutomountServiceAccountToken(). WithPorts(ports). - // WithReadinessProbe(readinessProbe(false)). - // WithLivenessProbe(livenessProbe(false)). + WithReadinessProbe(readinessProbe(false)). WithVolumeLikes(vols...) // TODO integrate with api.ssl.enabled @@ -103,46 +102,24 @@ func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.Conta } } -//// readinessProbe is the readiness probe for the Logstash container -// func readinessProbe(useTLS bool) corev1.Probe { -// scheme := corev1.URISchemeHTTP -// if useTLS { -// scheme = corev1.URISchemeHTTPS -// } -// return corev1.Probe{ -// FailureThreshold: 3, -// InitialDelaySeconds: 30, -// PeriodSeconds: 10, -// SuccessThreshold: 1, -// TimeoutSeconds: 5, -// ProbeHandler: corev1.ProbeHandler{ -// HTTPGet: &corev1.HTTPGetAction{ -// Port: intstr.FromInt(network.HTTPPort), -// Path: "/", -// Scheme: scheme, -// }, -// }, -// } -//} -// -//// livenessProbe is the liveness probe for the Logstash container -// func livenessProbe(useTLS bool) corev1.Probe { -// scheme := corev1.URISchemeHTTP -// if useTLS { -// scheme = corev1.URISchemeHTTPS -// } -// return corev1.Probe{ -// FailureThreshold: 3, -// InitialDelaySeconds: 60, -// PeriodSeconds: 10, -// SuccessThreshold: 1, -// TimeoutSeconds: 5, -// ProbeHandler: corev1.ProbeHandler{ -// HTTPGet: &corev1.HTTPGetAction{ -// Port: intstr.FromInt(network.HTTPPort), -// Path: "/", -// Scheme: scheme, -// }, -// }, -// } -//} +// readinessProbe is the readiness probe for the Logstash container +func readinessProbe(useTLS bool) corev1.Probe { + scheme := corev1.URISchemeHTTP + if useTLS { + scheme = corev1.URISchemeHTTPS + } + return corev1.Probe{ + FailureThreshold: 3, + InitialDelaySeconds: 30, + PeriodSeconds: 10, + SuccessThreshold: 1, + TimeoutSeconds: 5, + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Port: intstr.FromInt(network.HTTPPort), + Path: "/", + Scheme: scheme, + }, + }, + } +} From 214f63de26fb221e6a8c6c95040e550e9ae346b3 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 16 Feb 2023 17:14:32 -0500 Subject: [PATCH 055/160] Tidy up --- pkg/controller/logstash/driver.go | 5 ++--- test/e2e/stack_test.go | 2 +- test/e2e/test/logstash/http_client.go | 2 +- test/e2e/test/logstash/steps.go | 5 ----- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 4be3660336..7c432ffb0f 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -9,11 +9,10 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" "hash/fnv" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" "k8s.io/client-go/tools/record" diff --git a/test/e2e/stack_test.go b/test/e2e/stack_test.go index 69faa4948a..620d1655e4 100644 --- a/test/e2e/stack_test.go +++ b/test/e2e/stack_test.go @@ -106,7 +106,7 @@ func TestVersionUpgradeOrdering(t *testing.T) { ApmServer: ref(k8s.ExtractNamespacedName(&apm.ApmServer)), EnterpriseSearch: ref(k8s.ExtractNamespacedName(&ent.EnterpriseSearch)), Beat: ref(k8s.ExtractNamespacedName(&fb.Beat)), - Logstash: ref(k8s.ExtractNamespacedName(&logstash.Logstash)), + Logstash: ref(k8s.ExtractNamespacedName(&logstash.Logstash)), } err := stackVersions.Retrieve(k.Client) // check the retrieved versions first (before returning on err) diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go index d36519624e..2aea4ce8bf 100644 --- a/test/e2e/test/logstash/http_client.go +++ b/test/e2e/test/logstash/http_client.go @@ -13,7 +13,6 @@ import ( "net/url" "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) @@ -29,6 +28,7 @@ func (e *APIError) Error() string { // TODO refactor identical to Kibana client func NewLogstashClient(logstash v1alpha1.Logstash, k *test.K8sClient) (*http.Client, error) { var caCerts []*x509.Certificate + // TODO: Integrate with TLS on metrics API // if ems.Spec.HTTP.TLS.Enabled() { // crts, err := k.GetHTTPCerts(maps.EMSNamer, ems.Namespace, ems.Name) // if err != nil { diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index 44f2a5f4e0..a9a324a621 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -11,12 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - // "k8s.io/apimachinery/pkg/types" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - // mapsv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/maps/v1alpha1" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates" - // "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" From b9cb06ad4b15c56e0bae2257a0796fe4da7912c0 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Wed, 22 Feb 2023 18:41:41 +0000 Subject: [PATCH 056/160] Update config/crds/v1/patches/kustomization.yaml Co-authored-by: Peter Brachwitz --- config/crds/v1/patches/kustomization.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/crds/v1/patches/kustomization.yaml b/config/crds/v1/patches/kustomization.yaml index 60556c047d..3769976ec2 100644 --- a/config/crds/v1/patches/kustomization.yaml +++ b/config/crds/v1/patches/kustomization.yaml @@ -70,7 +70,7 @@ patchesJson6902: kind: CustomResourceDefinition name: elasticmapsservers.maps.k8s.elastic.co path: maps-patches.yaml - # custom patches for Beat + # custom patches for Logstash - target: group: apiextensions.k8s.io version: v1 From 51f2bad3ebf5c48e654015e3491d82b9bbc1109b Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Wed, 22 Feb 2023 18:41:49 +0000 Subject: [PATCH 057/160] Update pkg/apis/logstash/v1alpha1/name.go Co-authored-by: Peter Brachwitz --- pkg/apis/logstash/v1alpha1/name.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go index 84a9692840..c038173b2e 100644 --- a/pkg/apis/logstash/v1alpha1/name.go +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -13,7 +13,7 @@ const ( configSuffix = "config" ) -// Namer is a Namer that is configured with the defaults for resources related to an Agent resource. +// Namer is a Namer that is configured with the defaults for resources related to a Logstash resource. var Namer = common_name.NewNamer("ls") // ConfigSecretName returns the name of a secret used to storage Logstash configuration data. From b52d9ee240d9deb5cbc704423138ccf6a69f09a9 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 19:24:22 +0000 Subject: [PATCH 058/160] change HTTPConfig to []LogstashService --- config/crds/v1/all-crds.yaml | 869 +++++++++--------- .../logstash.k8s.elastic.co_logstashes.yaml | 869 +++++++++--------- config/samples/logstash/logstash.yaml | 6 +- config/samples/logstash/logstash_svc.yaml | 42 + .../eck-operator-crds/templates/all-crds.yaml | 869 +++++++++--------- docs/reference/api-docs.asciidoc | 24 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 10 +- pkg/apis/logstash/v1alpha1/name.go | 4 + .../v1alpha1/zz_generated.deepcopy.go | 25 +- pkg/controller/logstash/driver.go | 27 +- pkg/controller/logstash/labels.go | 17 +- pkg/controller/logstash/pod.go | 2 +- pkg/controller/logstash/service.go | 87 ++ 13 files changed, 1531 insertions(+), 1320 deletions(-) create mode 100644 config/samples/logstash/logstash_svc.yaml create mode 100644 pkg/controller/logstash/service.go diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 4c8e3d228d..982dba9809 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9117,434 +9117,6 @@ spec: count: format: int32 type: integer - http: - description: 'HTTP holds the HTTP layer configuration for the Logstash - Metrics API TODO: This should likely be changed to a more general - `Services LogstashService[]`, where `LogstashService` looks a lot - like `HTTPConfig`, but is applicable for more than just an HTTP - endpoint, as logstash may need to be opened up for other services: - beats, TCP, UDP, etc, inputs' - properties: - service: - description: Service defines the template for the associated Kubernetes - Service object. - properties: - metadata: - description: ObjectMeta is the metadata of the service. The - name and namespace provided here are managed by ECK and - will be ignored. - properties: - annotations: - additionalProperties: - type: string - type: object - finalizers: - items: - type: string - type: array - labels: - additionalProperties: - type: string - type: object - name: - type: string - namespace: - type: string - type: object - spec: - description: Spec is the specification of the service. - properties: - allocateLoadBalancerNodePorts: - description: allocateLoadBalancerNodePorts defines if - NodePorts will be automatically allocated for services - with type LoadBalancer. Default is "true". It may be - set to "false" if the cluster load-balancer does not - rely on NodePorts. If the caller requests specific - NodePorts (by specifying a value), those requests will - be respected, regardless of this field. This field may - only be set for services with type LoadBalancer and - will be cleared if the type is changed to any other - type. - type: boolean - clusterIP: - description: 'clusterIP is the IP address of the service - and is usually assigned randomly. If an address is specified - manually, is in-range (as per system configuration), - and is not in use, it will be allocated to the service; - otherwise creation of the service will fail. This field - may not be changed through updates unless the type field - is also being changed to ExternalName (which requires - this field to be blank) or the type field is being changed - from ExternalName (in which case this field may optionally - be specified, as describe above). Valid values are - "None", empty string (""), or a valid IP address. Setting - this to "None" makes a "headless service" (no virtual - IP), which is useful when direct endpoint connections - are preferred and proxying is not required. Only applies - to types ClusterIP, NodePort, and LoadBalancer. If this - field is specified when creating a Service of type ExternalName, - creation will fail. This field will be wiped when updating - a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - type: string - clusterIPs: - description: "ClusterIPs is a list of IP addresses assigned - to this service, and are usually assigned randomly. - \ If an address is specified manually, is in-range (as - per system configuration), and is not in use, it will - be allocated to the service; otherwise creation of the - service will fail. This field may not be changed through - updates unless the type field is also being changed - to ExternalName (which requires this field to be empty) - or the type field is being changed from ExternalName - (in which case this field may optionally be specified, - as describe above). Valid values are \"None\", empty - string (\"\"), or a valid IP address. Setting this - to \"None\" makes a \"headless service\" (no virtual - IP), which is useful when direct endpoint connections - are preferred and proxying is not required. Only applies - to types ClusterIP, NodePort, and LoadBalancer. If this - field is specified when creating a Service of type ExternalName, - creation will fail. This field will be wiped when updating - a Service to type ExternalName. If this field is not - specified, it will be initialized from the clusterIP - field. If this field is specified, clients must ensure - that clusterIPs[0] and clusterIP have the same value. - \n This field may hold a maximum of two entries (dual-stack - IPs, in either order). These IPs must correspond to - the values of the ipFamilies field. Both clusterIPs - and ipFamilies are governed by the ipFamilyPolicy field. - More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" - items: - type: string - type: array - x-kubernetes-list-type: atomic - externalIPs: - description: externalIPs is a list of IP addresses for - which nodes in the cluster will also accept traffic - for this service. These IPs are not managed by Kubernetes. The - user is responsible for ensuring that traffic arrives - at a node with this IP. A common example is external - load-balancers that are not part of the Kubernetes system. - items: - type: string - type: array - externalName: - description: externalName is the external reference that - discovery mechanisms will return as an alias for this - service (e.g. a DNS CNAME record). No proxying will - be involved. Must be a lowercase RFC-1123 hostname - (https://tools.ietf.org/html/rfc1123) and requires `type` - to be "ExternalName". - type: string - externalTrafficPolicy: - description: externalTrafficPolicy describes how nodes - distribute service traffic they receive on one of the - Service's "externally-facing" addresses (NodePorts, - ExternalIPs, and LoadBalancer IPs). If set to "Local", - the proxy will configure the service in a way that assumes - that external load balancers will take care of balancing - the service traffic between nodes, and so each node - will deliver traffic only to the node-local endpoints - of the service, without masquerading the client source - IP. (Traffic mistakenly sent to a node with no endpoints - will be dropped.) The default value, "Cluster", uses - the standard behavior of routing to all endpoints evenly - (possibly modified by topology and other features). - Note that traffic sent to an External IP or LoadBalancer - IP from within the cluster will always get "Cluster" - semantics, but clients sending to a NodePort from within - the cluster may need to take traffic policy into account - when picking a node. - type: string - healthCheckNodePort: - description: healthCheckNodePort specifies the healthcheck - nodePort for the service. This only applies when type - is set to LoadBalancer and externalTrafficPolicy is - set to Local. If a value is specified, is in-range, - and is not in use, it will be used. If not specified, - a value will be automatically allocated. External systems - (e.g. load-balancers) can use this port to determine - if a given node holds endpoints for this service or - not. If this field is specified when creating a Service - which does not need it, creation will fail. This field - will be wiped when updating a Service to no longer need - it (e.g. changing type). This field cannot be updated - once set. - format: int32 - type: integer - internalTrafficPolicy: - description: InternalTrafficPolicy describes how nodes - distribute service traffic they receive on the ClusterIP. - If set to "Local", the proxy will assume that pods only - want to talk to endpoints of the service on the same - node as the pod, dropping the traffic if there are no - local endpoints. The default value, "Cluster", uses - the standard behavior of routing to all endpoints evenly - (possibly modified by topology and other features). - type: string - ipFamilies: - description: "IPFamilies is a list of IP families (e.g. - IPv4, IPv6) assigned to this service. This field is - usually assigned automatically based on cluster configuration - and the ipFamilyPolicy field. If this field is specified - manually, the requested family is available in the cluster, - and ipFamilyPolicy allows it, it will be used; otherwise - creation of the service will fail. This field is conditionally - mutable: it allows for adding or removing a secondary - IP family, but it does not allow changing the primary - IP family of the Service. Valid values are \"IPv4\" - and \"IPv6\". This field only applies to Services of - types ClusterIP, NodePort, and LoadBalancer, and does - apply to \"headless\" services. This field will be wiped - when updating a Service to type ExternalName. \n This - field may hold a maximum of two entries (dual-stack - families, in either order). These families must correspond - to the values of the clusterIPs field, if specified. - Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy - field." - items: - description: IPFamily represents the IP Family (IPv4 - or IPv6). This type is used to express the family - of an IP expressed by a type (e.g. service.spec.ipFamilies). - type: string - type: array - x-kubernetes-list-type: atomic - ipFamilyPolicy: - description: IPFamilyPolicy represents the dual-stack-ness - requested or required by this Service. If there is no - value provided, then this field will be set to SingleStack. - Services can be "SingleStack" (a single IP family), - "PreferDualStack" (two IP families on dual-stack configured - clusters or a single IP family on single-stack clusters), - or "RequireDualStack" (two IP families on dual-stack - configured clusters, otherwise fail). The ipFamilies - and clusterIPs fields depend on the value of this field. - This field will be wiped when updating a service to - type ExternalName. - type: string - loadBalancerClass: - description: loadBalancerClass is the class of the load - balancer implementation this Service belongs to. If - specified, the value of this field must be a label-style - identifier, with an optional prefix, e.g. "internal-vip" - or "example.com/internal-vip". Unprefixed names are - reserved for end-users. This field can only be set when - the Service type is 'LoadBalancer'. If not set, the - default load balancer implementation is used, today - this is typically done through the cloud provider integration, - but should apply for any default implementation. If - set, it is assumed that a load balancer implementation - is watching for Services with a matching class. Any - default load balancer implementation (e.g. cloud providers) - should ignore Services that set this field. This field - can only be set when creating or updating a Service - to type 'LoadBalancer'. Once set, it can not be changed. - This field will be wiped when a service is updated to - a non 'LoadBalancer' type. - type: string - loadBalancerIP: - description: 'Only applies to Service Type: LoadBalancer. - This feature depends on whether the underlying cloud-provider - supports specifying the loadBalancerIP when a load balancer - is created. This field will be ignored if the cloud-provider - does not support the feature. Deprecated: This field - was under-specified and its meaning varies across implementations, - and it cannot support dual-stack. As of Kubernetes v1.24, - users are encouraged to use implementation-specific - annotations when available. This field may be removed - in a future API version.' - type: string - loadBalancerSourceRanges: - description: 'If specified and supported by the platform, - this will restrict traffic through the cloud-provider - load-balancer will be restricted to the specified client - IPs. This field will be ignored if the cloud-provider - does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' - items: - type: string - type: array - ports: - description: 'The list of ports that are exposed by this - service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - items: - description: ServicePort contains information on service's - port. - properties: - appProtocol: - description: The application protocol for this port. - This field follows standard Kubernetes label syntax. - Un-prefixed names are reserved for IANA standard - service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). - Non-standard protocols should use prefixed names - such as mycompany.com/my-custom-protocol. - type: string - name: - description: The name of this port within the service. - This must be a DNS_LABEL. All ports within a ServiceSpec - must have unique names. When considering the endpoints - for a Service, this must match the 'name' field - in the EndpointPort. Optional if only one ServicePort - is defined on this service. - type: string - nodePort: - description: 'The port on each node on which this - service is exposed when type is NodePort or LoadBalancer. Usually - assigned by the system. If a value is specified, - in-range, and not in use it will be used, otherwise - the operation will fail. If not specified, a - port will be allocated if this Service requires - one. If this field is specified when creating - a Service which does not need it, creation will - fail. This field will be wiped when updating a - Service to no longer need it (e.g. changing type - from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' - format: int32 - type: integer - port: - description: The port that will be exposed by this - service. - format: int32 - type: integer - protocol: - default: TCP - description: The IP protocol for this port. Supports - "TCP", "UDP", and "SCTP". Default is TCP. - type: string - targetPort: - anyOf: - - type: integer - - type: string - description: 'Number or name of the port to access - on the pods targeted by the service. Number must - be in the range 1 to 65535. Name must be an IANA_SVC_NAME. - If this is a string, it will be looked up as a - named port in the target Pod''s container ports. - If this is not specified, the value of the ''port'' - field is used (an identity map). This field is - ignored for services with clusterIP=None, and - should be omitted or set equal to the ''port'' - field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' - x-kubernetes-int-or-string: true - required: - - port - type: object - type: array - x-kubernetes-list-map-keys: - - port - - protocol - x-kubernetes-list-type: map - publishNotReadyAddresses: - description: publishNotReadyAddresses indicates that any - agent which deals with endpoints for this Service should - disregard any indications of ready/not-ready. The primary - use case for setting this field is for a StatefulSet's - Headless Service to propagate SRV DNS records for its - Pods for the purpose of peer discovery. The Kubernetes - controllers that generate Endpoints and EndpointSlice - resources for Services interpret this to mean that all - endpoints are considered "ready" even if the Pods themselves - are not. Agents which consume only Kubernetes generated - endpoints through the Endpoints or EndpointSlice resources - can safely assume this behavior. - type: boolean - selector: - additionalProperties: - type: string - description: 'Route service traffic to pods with label - keys and values matching this selector. If empty or - not present, the service is assumed to have an external - process managing its endpoints, which Kubernetes will - not modify. Only applies to types ClusterIP, NodePort, - and LoadBalancer. Ignored if type is ExternalName. More - info: https://kubernetes.io/docs/concepts/services-networking/service/' - type: object - x-kubernetes-map-type: atomic - sessionAffinity: - description: 'Supports "ClientIP" and "None". Used to - maintain session affinity. Enable client IP based session - affinity. Must be ClientIP or None. Defaults to None. - More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - type: string - sessionAffinityConfig: - description: sessionAffinityConfig contains the configurations - of session affinity. - properties: - clientIP: - description: clientIP contains the configurations - of Client IP based session affinity. - properties: - timeoutSeconds: - description: timeoutSeconds specifies the seconds - of ClientIP type session sticky time. The value - must be >0 && <=86400(for 1 day) if ServiceAffinity - == "ClientIP". Default value is 10800(for 3 - hours). - format: int32 - type: integer - type: object - type: object - type: - description: 'type determines how the Service is exposed. - Defaults to ClusterIP. Valid options are ExternalName, - ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates - a cluster-internal IP address for load-balancing to - endpoints. Endpoints are determined by the selector - or if that is not specified, by manual construction - of an Endpoints object or EndpointSlice objects. If - clusterIP is "None", no virtual IP is allocated and - the endpoints are published as a set of endpoints rather - than a virtual IP. "NodePort" builds on ClusterIP and - allocates a port on every node which routes to the same - endpoints as the clusterIP. "LoadBalancer" builds on - NodePort and creates an external load-balancer (if supported - in the current cloud) which routes to the same endpoints - as the clusterIP. "ExternalName" aliases this service - to the specified externalName. Several other fields - do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' - type: string - type: object - type: object - tls: - description: TLS defines options for configuring TLS for HTTP. - properties: - certificate: - description: "Certificate is a reference to a Kubernetes secret - that contains the certificate and private key for enabling - TLS. The referenced secret should contain the following: - \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: - The certificate (or a chain). - `tls.key`: The private key - to the first certificate in the certificate chain." - properties: - secretName: - description: SecretName is the name of the secret. - type: string - type: object - selfSignedCertificate: - description: SelfSignedCertificate allows configuring the - self-signed certificate generated by the operator. - properties: - disabled: - description: Disabled indicates that the provisioning - of the self-signed certifcate should be disabled. - type: boolean - subjectAltNames: - description: SubjectAlternativeNames is a list of SANs - to include in the generated HTTP TLS certificate. - items: - description: SubjectAlternativeName represents a SAN - entry in a x509 certificate. - properties: - dns: - description: DNS is the DNS name of the subject. - type: string - ip: - description: IP is the IP address of the subject. - type: string - type: object - type: array - type: object - type: object - type: object image: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. @@ -9601,6 +9173,447 @@ spec: resource to Elasticsearch resource in a different namespace. Can only be used if ECK is enforcing RBAC on references. type: string + services: + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' + items: + properties: + name: + type: string + service: + description: Service defines the template for the associated + Kubernetes Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. + The name and namespace provided here are managed by ECK + and will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may + be set to "false" if the cluster load-balancer does + not rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests + will be respected, regardless of this field. This + field may only be set for services with type LoadBalancer + and will be cleared if the type is changed to any + other type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is + specified manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This + field may not be changed through updates unless the + type field is also being changed to ExternalName (which + requires this field to be blank) or the type field + is being changed from ExternalName (in which case + this field may optionally be specified, as describe + above). Valid values are "None", empty string (""), + or a valid IP address. Setting this to "None" makes + a "headless service" (no virtual IP), which is useful + when direct endpoint connections are preferred and + proxying is not required. Only applies to types ClusterIP, + NodePort, and LoadBalancer. If this field is specified + when creating a Service of type ExternalName, creation + will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range + (as per system configuration), and is not in use, + it will be allocated to the service; otherwise creation + of the service will fail. This field may not be changed + through updates unless the type field is also being + changed to ExternalName (which requires this field + to be empty) or the type field is being changed from + ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + \"None\", empty string (\"\"), or a valid IP address. + \ Setting this to \"None\" makes a \"headless service\" + (no virtual IP), which is useful when direct endpoint + connections are preferred and proxying is not required. + \ Only applies to types ClusterIP, NodePort, and LoadBalancer. + If this field is specified when creating a Service + of type ExternalName, creation will fail. This field + will be wiped when updating a Service to type ExternalName. + \ If this field is not specified, it will be initialized + from the clusterIP field. If this field is specified, + clients must ensure that clusterIPs[0] and clusterIP + have the same value. \n This field may hold a maximum + of two entries (dual-stack IPs, in either order). + These IPs must correspond to the values of the ipFamilies + field. Both clusterIPs and ipFamilies are governed + by the ipFamilyPolicy field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes + system. + items: + type: string + type: array + externalName: + description: externalName is the external reference + that discovery mechanisms will return as an alias + for this service (e.g. a DNS CNAME record). No proxying + will be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires + `type` to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of + the Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that + assumes that external load balancers will take care + of balancing the service traffic between nodes, and + so each node will deliver traffic only to the node-local + endpoints of the service, without masquerading the + client source IP. (Traffic mistakenly sent to a node + with no endpoints will be dropped.) The default value, + "Cluster", uses the standard behavior of routing to + all endpoints evenly (possibly modified by topology + and other features). Note that traffic sent to an + External IP or LoadBalancer IP from within the cluster + will always get "Cluster" semantics, but clients sending + to a NodePort from within the cluster may need to + take traffic policy into account when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External + systems (e.g. load-balancers) can use this port to + determine if a given node holds endpoints for this + service or not. If this field is specified when creating + a Service which does not need it, creation will fail. + This field will be wiped when updating a Service to + no longer need it (e.g. changing type). This field + cannot be updated once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods + only want to talk to endpoints of the service on the + same node as the pod, dropping the traffic if there + are no local endpoints. The default value, "Cluster", + uses the standard behavior of routing to all endpoints + evenly (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the + cluster, and ipFamilyPolicy allows it, it will be + used; otherwise creation of the service will fail. + This field is conditionally mutable: it allows for + adding or removing a secondary IP family, but it does + not allow changing the primary IP family of the Service. + Valid values are \"IPv4\" and \"IPv6\". This field + only applies to Services of types ClusterIP, NodePort, + and LoadBalancer, and does apply to \"headless\" services. + This field will be wiped when updating a Service to + type ExternalName. \n This field may hold a maximum + of two entries (dual-stack families, in either order). + \ These families must correspond to the values of + the clusterIPs field, if specified. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is + no value provided, then this field will be set to + SingleStack. Services can be "SingleStack" (a single + IP family), "PreferDualStack" (two IP families on + dual-stack configured clusters or a single IP family + on single-stack clusters), or "RequireDualStack" (two + IP families on dual-stack configured clusters, otherwise + fail). The ipFamilies and clusterIPs fields depend + on the value of this field. This field will be wiped + when updating a service to type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set + when the Service type is 'LoadBalancer'. If not set, + the default load balancer implementation is used, + today this is typically done through the cloud provider + integration, but should apply for any default implementation. + If set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated + to a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load + balancer is created. This field will be ignored if + the cloud-provider does not support the feature. Deprecated: + This field was under-specified and its meaning varies + across implementations, and it cannot support dual-stack. + As of Kubernetes v1.24, users are encouraged to use + implementation-specific annotations when available. + This field may be removed in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified + client IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by + this service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this + port. This field follows standard Kubernetes + label syntax. Un-prefixed names are reserved + for IANA standard service names (as per RFC-6335 + and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the + service. This must be a DNS_LABEL. All ports + within a ServiceSpec must have unique names. + When considering the endpoints for a Service, + this must match the 'name' field in the EndpointPort. + Optional if only one ServicePort is defined + on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or + LoadBalancer. Usually assigned by the system. + If a value is specified, in-range, and not in + use it will be used, otherwise the operation + will fail. If not specified, a port will be + allocated if this Service requires one. If + this field is specified when creating a Service + which does not need it, creation will fail. + This field will be wiped when updating a Service + to no longer need it (e.g. changing type from + NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by + this service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number + must be in the range 1 to 65535. Name must be + an IANA_SVC_NAME. If this is a string, it will + be looked up as a named port in the target Pod''s + container ports. If this is not specified, the + value of the ''port'' field is used (an identity + map). This field is ignored for services with + clusterIP=None, and should be omitted or set + equal to the ''port'' field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that + any agent which deals with endpoints for this Service + should disregard any indications of ready/not-ready. + The primary use case for setting this field is for + a StatefulSet's Headless Service to propagate SRV + DNS records for its Pods for the purpose of peer discovery. + The Kubernetes controllers that generate Endpoints + and EndpointSlice resources for Services interpret + this to mean that all endpoints are considered "ready" + even if the Pods themselves are not. Agents which + consume only Kubernetes generated endpoints through + the Endpoints or EndpointSlice resources can safely + assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. + More info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based + session affinity. Must be ClientIP or None. Defaults + to None. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The + value must be >0 && <=86400(for 1 day) if + ServiceAffinity == "ClientIP". Default value + is 10800(for 3 hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" + allocates a cluster-internal IP address for load-balancing + to endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints + rather than a virtual IP. "NodePort" builds on ClusterIP + and allocates a port on every node which routes to + the same endpoints as the clusterIP. "LoadBalancer" + builds on NodePort and creates an external load-balancer + (if supported in the current cloud) which routes to + the same endpoints as the clusterIP. "ExternalName" + aliases this service to the specified externalName. + Several other fields do not apply to ExternalName + services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes + secret that contains the certificate and private key for + enabling TLS. The referenced secret should contain the + following: \n - `ca.crt`: The certificate authority (optional). + - `tls.crt`: The certificate (or a chain). - `tls.key`: + The private key to the first certificate in the certificate + chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + type: array version: description: Version of the Logstash. type: string diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 099a90ce2c..438333392a 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -73,434 +73,6 @@ spec: count: format: int32 type: integer - http: - description: 'HTTP holds the HTTP layer configuration for the Logstash - Metrics API TODO: This should likely be changed to a more general - `Services LogstashService[]`, where `LogstashService` looks a lot - like `HTTPConfig`, but is applicable for more than just an HTTP - endpoint, as logstash may need to be opened up for other services: - beats, TCP, UDP, etc, inputs' - properties: - service: - description: Service defines the template for the associated Kubernetes - Service object. - properties: - metadata: - description: ObjectMeta is the metadata of the service. The - name and namespace provided here are managed by ECK and - will be ignored. - properties: - annotations: - additionalProperties: - type: string - type: object - finalizers: - items: - type: string - type: array - labels: - additionalProperties: - type: string - type: object - name: - type: string - namespace: - type: string - type: object - spec: - description: Spec is the specification of the service. - properties: - allocateLoadBalancerNodePorts: - description: allocateLoadBalancerNodePorts defines if - NodePorts will be automatically allocated for services - with type LoadBalancer. Default is "true". It may be - set to "false" if the cluster load-balancer does not - rely on NodePorts. If the caller requests specific - NodePorts (by specifying a value), those requests will - be respected, regardless of this field. This field may - only be set for services with type LoadBalancer and - will be cleared if the type is changed to any other - type. - type: boolean - clusterIP: - description: 'clusterIP is the IP address of the service - and is usually assigned randomly. If an address is specified - manually, is in-range (as per system configuration), - and is not in use, it will be allocated to the service; - otherwise creation of the service will fail. This field - may not be changed through updates unless the type field - is also being changed to ExternalName (which requires - this field to be blank) or the type field is being changed - from ExternalName (in which case this field may optionally - be specified, as describe above). Valid values are - "None", empty string (""), or a valid IP address. Setting - this to "None" makes a "headless service" (no virtual - IP), which is useful when direct endpoint connections - are preferred and proxying is not required. Only applies - to types ClusterIP, NodePort, and LoadBalancer. If this - field is specified when creating a Service of type ExternalName, - creation will fail. This field will be wiped when updating - a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - type: string - clusterIPs: - description: "ClusterIPs is a list of IP addresses assigned - to this service, and are usually assigned randomly. - \ If an address is specified manually, is in-range (as - per system configuration), and is not in use, it will - be allocated to the service; otherwise creation of the - service will fail. This field may not be changed through - updates unless the type field is also being changed - to ExternalName (which requires this field to be empty) - or the type field is being changed from ExternalName - (in which case this field may optionally be specified, - as describe above). Valid values are \"None\", empty - string (\"\"), or a valid IP address. Setting this - to \"None\" makes a \"headless service\" (no virtual - IP), which is useful when direct endpoint connections - are preferred and proxying is not required. Only applies - to types ClusterIP, NodePort, and LoadBalancer. If this - field is specified when creating a Service of type ExternalName, - creation will fail. This field will be wiped when updating - a Service to type ExternalName. If this field is not - specified, it will be initialized from the clusterIP - field. If this field is specified, clients must ensure - that clusterIPs[0] and clusterIP have the same value. - \n This field may hold a maximum of two entries (dual-stack - IPs, in either order). These IPs must correspond to - the values of the ipFamilies field. Both clusterIPs - and ipFamilies are governed by the ipFamilyPolicy field. - More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" - items: - type: string - type: array - x-kubernetes-list-type: atomic - externalIPs: - description: externalIPs is a list of IP addresses for - which nodes in the cluster will also accept traffic - for this service. These IPs are not managed by Kubernetes. The - user is responsible for ensuring that traffic arrives - at a node with this IP. A common example is external - load-balancers that are not part of the Kubernetes system. - items: - type: string - type: array - externalName: - description: externalName is the external reference that - discovery mechanisms will return as an alias for this - service (e.g. a DNS CNAME record). No proxying will - be involved. Must be a lowercase RFC-1123 hostname - (https://tools.ietf.org/html/rfc1123) and requires `type` - to be "ExternalName". - type: string - externalTrafficPolicy: - description: externalTrafficPolicy describes how nodes - distribute service traffic they receive on one of the - Service's "externally-facing" addresses (NodePorts, - ExternalIPs, and LoadBalancer IPs). If set to "Local", - the proxy will configure the service in a way that assumes - that external load balancers will take care of balancing - the service traffic between nodes, and so each node - will deliver traffic only to the node-local endpoints - of the service, without masquerading the client source - IP. (Traffic mistakenly sent to a node with no endpoints - will be dropped.) The default value, "Cluster", uses - the standard behavior of routing to all endpoints evenly - (possibly modified by topology and other features). - Note that traffic sent to an External IP or LoadBalancer - IP from within the cluster will always get "Cluster" - semantics, but clients sending to a NodePort from within - the cluster may need to take traffic policy into account - when picking a node. - type: string - healthCheckNodePort: - description: healthCheckNodePort specifies the healthcheck - nodePort for the service. This only applies when type - is set to LoadBalancer and externalTrafficPolicy is - set to Local. If a value is specified, is in-range, - and is not in use, it will be used. If not specified, - a value will be automatically allocated. External systems - (e.g. load-balancers) can use this port to determine - if a given node holds endpoints for this service or - not. If this field is specified when creating a Service - which does not need it, creation will fail. This field - will be wiped when updating a Service to no longer need - it (e.g. changing type). This field cannot be updated - once set. - format: int32 - type: integer - internalTrafficPolicy: - description: InternalTrafficPolicy describes how nodes - distribute service traffic they receive on the ClusterIP. - If set to "Local", the proxy will assume that pods only - want to talk to endpoints of the service on the same - node as the pod, dropping the traffic if there are no - local endpoints. The default value, "Cluster", uses - the standard behavior of routing to all endpoints evenly - (possibly modified by topology and other features). - type: string - ipFamilies: - description: "IPFamilies is a list of IP families (e.g. - IPv4, IPv6) assigned to this service. This field is - usually assigned automatically based on cluster configuration - and the ipFamilyPolicy field. If this field is specified - manually, the requested family is available in the cluster, - and ipFamilyPolicy allows it, it will be used; otherwise - creation of the service will fail. This field is conditionally - mutable: it allows for adding or removing a secondary - IP family, but it does not allow changing the primary - IP family of the Service. Valid values are \"IPv4\" - and \"IPv6\". This field only applies to Services of - types ClusterIP, NodePort, and LoadBalancer, and does - apply to \"headless\" services. This field will be wiped - when updating a Service to type ExternalName. \n This - field may hold a maximum of two entries (dual-stack - families, in either order). These families must correspond - to the values of the clusterIPs field, if specified. - Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy - field." - items: - description: IPFamily represents the IP Family (IPv4 - or IPv6). This type is used to express the family - of an IP expressed by a type (e.g. service.spec.ipFamilies). - type: string - type: array - x-kubernetes-list-type: atomic - ipFamilyPolicy: - description: IPFamilyPolicy represents the dual-stack-ness - requested or required by this Service. If there is no - value provided, then this field will be set to SingleStack. - Services can be "SingleStack" (a single IP family), - "PreferDualStack" (two IP families on dual-stack configured - clusters or a single IP family on single-stack clusters), - or "RequireDualStack" (two IP families on dual-stack - configured clusters, otherwise fail). The ipFamilies - and clusterIPs fields depend on the value of this field. - This field will be wiped when updating a service to - type ExternalName. - type: string - loadBalancerClass: - description: loadBalancerClass is the class of the load - balancer implementation this Service belongs to. If - specified, the value of this field must be a label-style - identifier, with an optional prefix, e.g. "internal-vip" - or "example.com/internal-vip". Unprefixed names are - reserved for end-users. This field can only be set when - the Service type is 'LoadBalancer'. If not set, the - default load balancer implementation is used, today - this is typically done through the cloud provider integration, - but should apply for any default implementation. If - set, it is assumed that a load balancer implementation - is watching for Services with a matching class. Any - default load balancer implementation (e.g. cloud providers) - should ignore Services that set this field. This field - can only be set when creating or updating a Service - to type 'LoadBalancer'. Once set, it can not be changed. - This field will be wiped when a service is updated to - a non 'LoadBalancer' type. - type: string - loadBalancerIP: - description: 'Only applies to Service Type: LoadBalancer. - This feature depends on whether the underlying cloud-provider - supports specifying the loadBalancerIP when a load balancer - is created. This field will be ignored if the cloud-provider - does not support the feature. Deprecated: This field - was under-specified and its meaning varies across implementations, - and it cannot support dual-stack. As of Kubernetes v1.24, - users are encouraged to use implementation-specific - annotations when available. This field may be removed - in a future API version.' - type: string - loadBalancerSourceRanges: - description: 'If specified and supported by the platform, - this will restrict traffic through the cloud-provider - load-balancer will be restricted to the specified client - IPs. This field will be ignored if the cloud-provider - does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' - items: - type: string - type: array - ports: - description: 'The list of ports that are exposed by this - service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - items: - description: ServicePort contains information on service's - port. - properties: - appProtocol: - description: The application protocol for this port. - This field follows standard Kubernetes label syntax. - Un-prefixed names are reserved for IANA standard - service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). - Non-standard protocols should use prefixed names - such as mycompany.com/my-custom-protocol. - type: string - name: - description: The name of this port within the service. - This must be a DNS_LABEL. All ports within a ServiceSpec - must have unique names. When considering the endpoints - for a Service, this must match the 'name' field - in the EndpointPort. Optional if only one ServicePort - is defined on this service. - type: string - nodePort: - description: 'The port on each node on which this - service is exposed when type is NodePort or LoadBalancer. Usually - assigned by the system. If a value is specified, - in-range, and not in use it will be used, otherwise - the operation will fail. If not specified, a - port will be allocated if this Service requires - one. If this field is specified when creating - a Service which does not need it, creation will - fail. This field will be wiped when updating a - Service to no longer need it (e.g. changing type - from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' - format: int32 - type: integer - port: - description: The port that will be exposed by this - service. - format: int32 - type: integer - protocol: - default: TCP - description: The IP protocol for this port. Supports - "TCP", "UDP", and "SCTP". Default is TCP. - type: string - targetPort: - anyOf: - - type: integer - - type: string - description: 'Number or name of the port to access - on the pods targeted by the service. Number must - be in the range 1 to 65535. Name must be an IANA_SVC_NAME. - If this is a string, it will be looked up as a - named port in the target Pod''s container ports. - If this is not specified, the value of the ''port'' - field is used (an identity map). This field is - ignored for services with clusterIP=None, and - should be omitted or set equal to the ''port'' - field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' - x-kubernetes-int-or-string: true - required: - - port - type: object - type: array - x-kubernetes-list-map-keys: - - port - - protocol - x-kubernetes-list-type: map - publishNotReadyAddresses: - description: publishNotReadyAddresses indicates that any - agent which deals with endpoints for this Service should - disregard any indications of ready/not-ready. The primary - use case for setting this field is for a StatefulSet's - Headless Service to propagate SRV DNS records for its - Pods for the purpose of peer discovery. The Kubernetes - controllers that generate Endpoints and EndpointSlice - resources for Services interpret this to mean that all - endpoints are considered "ready" even if the Pods themselves - are not. Agents which consume only Kubernetes generated - endpoints through the Endpoints or EndpointSlice resources - can safely assume this behavior. - type: boolean - selector: - additionalProperties: - type: string - description: 'Route service traffic to pods with label - keys and values matching this selector. If empty or - not present, the service is assumed to have an external - process managing its endpoints, which Kubernetes will - not modify. Only applies to types ClusterIP, NodePort, - and LoadBalancer. Ignored if type is ExternalName. More - info: https://kubernetes.io/docs/concepts/services-networking/service/' - type: object - x-kubernetes-map-type: atomic - sessionAffinity: - description: 'Supports "ClientIP" and "None". Used to - maintain session affinity. Enable client IP based session - affinity. Must be ClientIP or None. Defaults to None. - More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - type: string - sessionAffinityConfig: - description: sessionAffinityConfig contains the configurations - of session affinity. - properties: - clientIP: - description: clientIP contains the configurations - of Client IP based session affinity. - properties: - timeoutSeconds: - description: timeoutSeconds specifies the seconds - of ClientIP type session sticky time. The value - must be >0 && <=86400(for 1 day) if ServiceAffinity - == "ClientIP". Default value is 10800(for 3 - hours). - format: int32 - type: integer - type: object - type: object - type: - description: 'type determines how the Service is exposed. - Defaults to ClusterIP. Valid options are ExternalName, - ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates - a cluster-internal IP address for load-balancing to - endpoints. Endpoints are determined by the selector - or if that is not specified, by manual construction - of an Endpoints object or EndpointSlice objects. If - clusterIP is "None", no virtual IP is allocated and - the endpoints are published as a set of endpoints rather - than a virtual IP. "NodePort" builds on ClusterIP and - allocates a port on every node which routes to the same - endpoints as the clusterIP. "LoadBalancer" builds on - NodePort and creates an external load-balancer (if supported - in the current cloud) which routes to the same endpoints - as the clusterIP. "ExternalName" aliases this service - to the specified externalName. Several other fields - do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' - type: string - type: object - type: object - tls: - description: TLS defines options for configuring TLS for HTTP. - properties: - certificate: - description: "Certificate is a reference to a Kubernetes secret - that contains the certificate and private key for enabling - TLS. The referenced secret should contain the following: - \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: - The certificate (or a chain). - `tls.key`: The private key - to the first certificate in the certificate chain." - properties: - secretName: - description: SecretName is the name of the secret. - type: string - type: object - selfSignedCertificate: - description: SelfSignedCertificate allows configuring the - self-signed certificate generated by the operator. - properties: - disabled: - description: Disabled indicates that the provisioning - of the self-signed certifcate should be disabled. - type: boolean - subjectAltNames: - description: SubjectAlternativeNames is a list of SANs - to include in the generated HTTP TLS certificate. - items: - description: SubjectAlternativeName represents a SAN - entry in a x509 certificate. - properties: - dns: - description: DNS is the DNS name of the subject. - type: string - ip: - description: IP is the IP address of the subject. - type: string - type: object - type: array - type: object - type: object - type: object image: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. @@ -7964,6 +7536,447 @@ spec: resource to Elasticsearch resource in a different namespace. Can only be used if ECK is enforcing RBAC on references. type: string + services: + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' + items: + properties: + name: + type: string + service: + description: Service defines the template for the associated + Kubernetes Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. + The name and namespace provided here are managed by ECK + and will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may + be set to "false" if the cluster load-balancer does + not rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests + will be respected, regardless of this field. This + field may only be set for services with type LoadBalancer + and will be cleared if the type is changed to any + other type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is + specified manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This + field may not be changed through updates unless the + type field is also being changed to ExternalName (which + requires this field to be blank) or the type field + is being changed from ExternalName (in which case + this field may optionally be specified, as describe + above). Valid values are "None", empty string (""), + or a valid IP address. Setting this to "None" makes + a "headless service" (no virtual IP), which is useful + when direct endpoint connections are preferred and + proxying is not required. Only applies to types ClusterIP, + NodePort, and LoadBalancer. If this field is specified + when creating a Service of type ExternalName, creation + will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range + (as per system configuration), and is not in use, + it will be allocated to the service; otherwise creation + of the service will fail. This field may not be changed + through updates unless the type field is also being + changed to ExternalName (which requires this field + to be empty) or the type field is being changed from + ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + \"None\", empty string (\"\"), or a valid IP address. + \ Setting this to \"None\" makes a \"headless service\" + (no virtual IP), which is useful when direct endpoint + connections are preferred and proxying is not required. + \ Only applies to types ClusterIP, NodePort, and LoadBalancer. + If this field is specified when creating a Service + of type ExternalName, creation will fail. This field + will be wiped when updating a Service to type ExternalName. + \ If this field is not specified, it will be initialized + from the clusterIP field. If this field is specified, + clients must ensure that clusterIPs[0] and clusterIP + have the same value. \n This field may hold a maximum + of two entries (dual-stack IPs, in either order). + These IPs must correspond to the values of the ipFamilies + field. Both clusterIPs and ipFamilies are governed + by the ipFamilyPolicy field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes + system. + items: + type: string + type: array + externalName: + description: externalName is the external reference + that discovery mechanisms will return as an alias + for this service (e.g. a DNS CNAME record). No proxying + will be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires + `type` to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of + the Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that + assumes that external load balancers will take care + of balancing the service traffic between nodes, and + so each node will deliver traffic only to the node-local + endpoints of the service, without masquerading the + client source IP. (Traffic mistakenly sent to a node + with no endpoints will be dropped.) The default value, + "Cluster", uses the standard behavior of routing to + all endpoints evenly (possibly modified by topology + and other features). Note that traffic sent to an + External IP or LoadBalancer IP from within the cluster + will always get "Cluster" semantics, but clients sending + to a NodePort from within the cluster may need to + take traffic policy into account when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External + systems (e.g. load-balancers) can use this port to + determine if a given node holds endpoints for this + service or not. If this field is specified when creating + a Service which does not need it, creation will fail. + This field will be wiped when updating a Service to + no longer need it (e.g. changing type). This field + cannot be updated once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods + only want to talk to endpoints of the service on the + same node as the pod, dropping the traffic if there + are no local endpoints. The default value, "Cluster", + uses the standard behavior of routing to all endpoints + evenly (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the + cluster, and ipFamilyPolicy allows it, it will be + used; otherwise creation of the service will fail. + This field is conditionally mutable: it allows for + adding or removing a secondary IP family, but it does + not allow changing the primary IP family of the Service. + Valid values are \"IPv4\" and \"IPv6\". This field + only applies to Services of types ClusterIP, NodePort, + and LoadBalancer, and does apply to \"headless\" services. + This field will be wiped when updating a Service to + type ExternalName. \n This field may hold a maximum + of two entries (dual-stack families, in either order). + \ These families must correspond to the values of + the clusterIPs field, if specified. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is + no value provided, then this field will be set to + SingleStack. Services can be "SingleStack" (a single + IP family), "PreferDualStack" (two IP families on + dual-stack configured clusters or a single IP family + on single-stack clusters), or "RequireDualStack" (two + IP families on dual-stack configured clusters, otherwise + fail). The ipFamilies and clusterIPs fields depend + on the value of this field. This field will be wiped + when updating a service to type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set + when the Service type is 'LoadBalancer'. If not set, + the default load balancer implementation is used, + today this is typically done through the cloud provider + integration, but should apply for any default implementation. + If set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated + to a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load + balancer is created. This field will be ignored if + the cloud-provider does not support the feature. Deprecated: + This field was under-specified and its meaning varies + across implementations, and it cannot support dual-stack. + As of Kubernetes v1.24, users are encouraged to use + implementation-specific annotations when available. + This field may be removed in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified + client IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by + this service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this + port. This field follows standard Kubernetes + label syntax. Un-prefixed names are reserved + for IANA standard service names (as per RFC-6335 + and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the + service. This must be a DNS_LABEL. All ports + within a ServiceSpec must have unique names. + When considering the endpoints for a Service, + this must match the 'name' field in the EndpointPort. + Optional if only one ServicePort is defined + on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or + LoadBalancer. Usually assigned by the system. + If a value is specified, in-range, and not in + use it will be used, otherwise the operation + will fail. If not specified, a port will be + allocated if this Service requires one. If + this field is specified when creating a Service + which does not need it, creation will fail. + This field will be wiped when updating a Service + to no longer need it (e.g. changing type from + NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by + this service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number + must be in the range 1 to 65535. Name must be + an IANA_SVC_NAME. If this is a string, it will + be looked up as a named port in the target Pod''s + container ports. If this is not specified, the + value of the ''port'' field is used (an identity + map). This field is ignored for services with + clusterIP=None, and should be omitted or set + equal to the ''port'' field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that + any agent which deals with endpoints for this Service + should disregard any indications of ready/not-ready. + The primary use case for setting this field is for + a StatefulSet's Headless Service to propagate SRV + DNS records for its Pods for the purpose of peer discovery. + The Kubernetes controllers that generate Endpoints + and EndpointSlice resources for Services interpret + this to mean that all endpoints are considered "ready" + even if the Pods themselves are not. Agents which + consume only Kubernetes generated endpoints through + the Endpoints or EndpointSlice resources can safely + assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. + More info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based + session affinity. Must be ClientIP or None. Defaults + to None. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The + value must be >0 && <=86400(for 1 day) if + ServiceAffinity == "ClientIP". Default value + is 10800(for 3 hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" + allocates a cluster-internal IP address for load-balancing + to endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints + rather than a virtual IP. "NodePort" builds on ClusterIP + and allocates a port on every node which routes to + the same endpoints as the clusterIP. "LoadBalancer" + builds on NodePort and creates an external load-balancer + (if supported in the current cloud) which routes to + the same endpoints as the clusterIP. "ExternalName" + aliases this service to the specified externalName. + Several other fields do not apply to ExternalName + services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes + secret that contains the certificate and private key for + enabling TLS. The referenced secret should contain the + following: \n - `ca.crt`: The certificate authority (optional). + - `tls.crt`: The certificate (or a chain). - `tls.key`: + The private key to the first certificate in the certificate + chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + type: array version: description: Version of the Logstash. type: string diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml index e6283a9568..e924b4a5b6 100644 --- a/config/samples/logstash/logstash.yaml +++ b/config/samples/logstash/logstash.yaml @@ -22,6 +22,6 @@ spec: api.http.host: "0.0.0.0" queue.type: memory podTemplate: - spec: - containers: - - name: logstash + spec: + containers: + - name: logstash \ No newline at end of file diff --git a/config/samples/logstash/logstash_svc.yaml b/config/samples/logstash/logstash_svc.yaml new file mode 100644 index 0000000000..90b432dbc9 --- /dev/null +++ b/config/samples/logstash/logstash_svc.yaml @@ -0,0 +1,42 @@ +apiVersion: elasticsearch.k8s.elastic.co/v1 +kind: Elasticsearch +metadata: + name: elasticsearch-sample +spec: + version: 8.6.1 + nodeSets: + - name: default + count: 3 + config: + node.store.allow_mmap: false +--- +apiVersion: logstash.k8s.elastic.co/v1alpha1 +kind: Logstash +metadata: + name: logstash-sample +spec: + count: 3 + version: 8.6.1 + config: + log.level: info + api.http.host: "0.0.0.0" + queue.type: memory + services: + - name: metrics + service: + spec: + type: ClusterIP + ports: + - port: 9600 + name: "stats" + protocol: TCP + targetPort: 9600 + - name: beats + service: + spec: + type: ClusterIP + ports: + - port: 5044 + name: "beats" + protocol: TCP + targetPort: 5044 diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index b926b6c0de..f36d773dce 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9171,434 +9171,6 @@ spec: count: format: int32 type: integer - http: - description: 'HTTP holds the HTTP layer configuration for the Logstash - Metrics API TODO: This should likely be changed to a more general - `Services LogstashService[]`, where `LogstashService` looks a lot - like `HTTPConfig`, but is applicable for more than just an HTTP - endpoint, as logstash may need to be opened up for other services: - beats, TCP, UDP, etc, inputs' - properties: - service: - description: Service defines the template for the associated Kubernetes - Service object. - properties: - metadata: - description: ObjectMeta is the metadata of the service. The - name and namespace provided here are managed by ECK and - will be ignored. - properties: - annotations: - additionalProperties: - type: string - type: object - finalizers: - items: - type: string - type: array - labels: - additionalProperties: - type: string - type: object - name: - type: string - namespace: - type: string - type: object - spec: - description: Spec is the specification of the service. - properties: - allocateLoadBalancerNodePorts: - description: allocateLoadBalancerNodePorts defines if - NodePorts will be automatically allocated for services - with type LoadBalancer. Default is "true". It may be - set to "false" if the cluster load-balancer does not - rely on NodePorts. If the caller requests specific - NodePorts (by specifying a value), those requests will - be respected, regardless of this field. This field may - only be set for services with type LoadBalancer and - will be cleared if the type is changed to any other - type. - type: boolean - clusterIP: - description: 'clusterIP is the IP address of the service - and is usually assigned randomly. If an address is specified - manually, is in-range (as per system configuration), - and is not in use, it will be allocated to the service; - otherwise creation of the service will fail. This field - may not be changed through updates unless the type field - is also being changed to ExternalName (which requires - this field to be blank) or the type field is being changed - from ExternalName (in which case this field may optionally - be specified, as describe above). Valid values are - "None", empty string (""), or a valid IP address. Setting - this to "None" makes a "headless service" (no virtual - IP), which is useful when direct endpoint connections - are preferred and proxying is not required. Only applies - to types ClusterIP, NodePort, and LoadBalancer. If this - field is specified when creating a Service of type ExternalName, - creation will fail. This field will be wiped when updating - a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - type: string - clusterIPs: - description: "ClusterIPs is a list of IP addresses assigned - to this service, and are usually assigned randomly. - \ If an address is specified manually, is in-range (as - per system configuration), and is not in use, it will - be allocated to the service; otherwise creation of the - service will fail. This field may not be changed through - updates unless the type field is also being changed - to ExternalName (which requires this field to be empty) - or the type field is being changed from ExternalName - (in which case this field may optionally be specified, - as describe above). Valid values are \"None\", empty - string (\"\"), or a valid IP address. Setting this - to \"None\" makes a \"headless service\" (no virtual - IP), which is useful when direct endpoint connections - are preferred and proxying is not required. Only applies - to types ClusterIP, NodePort, and LoadBalancer. If this - field is specified when creating a Service of type ExternalName, - creation will fail. This field will be wiped when updating - a Service to type ExternalName. If this field is not - specified, it will be initialized from the clusterIP - field. If this field is specified, clients must ensure - that clusterIPs[0] and clusterIP have the same value. - \n This field may hold a maximum of two entries (dual-stack - IPs, in either order). These IPs must correspond to - the values of the ipFamilies field. Both clusterIPs - and ipFamilies are governed by the ipFamilyPolicy field. - More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" - items: - type: string - type: array - x-kubernetes-list-type: atomic - externalIPs: - description: externalIPs is a list of IP addresses for - which nodes in the cluster will also accept traffic - for this service. These IPs are not managed by Kubernetes. The - user is responsible for ensuring that traffic arrives - at a node with this IP. A common example is external - load-balancers that are not part of the Kubernetes system. - items: - type: string - type: array - externalName: - description: externalName is the external reference that - discovery mechanisms will return as an alias for this - service (e.g. a DNS CNAME record). No proxying will - be involved. Must be a lowercase RFC-1123 hostname - (https://tools.ietf.org/html/rfc1123) and requires `type` - to be "ExternalName". - type: string - externalTrafficPolicy: - description: externalTrafficPolicy describes how nodes - distribute service traffic they receive on one of the - Service's "externally-facing" addresses (NodePorts, - ExternalIPs, and LoadBalancer IPs). If set to "Local", - the proxy will configure the service in a way that assumes - that external load balancers will take care of balancing - the service traffic between nodes, and so each node - will deliver traffic only to the node-local endpoints - of the service, without masquerading the client source - IP. (Traffic mistakenly sent to a node with no endpoints - will be dropped.) The default value, "Cluster", uses - the standard behavior of routing to all endpoints evenly - (possibly modified by topology and other features). - Note that traffic sent to an External IP or LoadBalancer - IP from within the cluster will always get "Cluster" - semantics, but clients sending to a NodePort from within - the cluster may need to take traffic policy into account - when picking a node. - type: string - healthCheckNodePort: - description: healthCheckNodePort specifies the healthcheck - nodePort for the service. This only applies when type - is set to LoadBalancer and externalTrafficPolicy is - set to Local. If a value is specified, is in-range, - and is not in use, it will be used. If not specified, - a value will be automatically allocated. External systems - (e.g. load-balancers) can use this port to determine - if a given node holds endpoints for this service or - not. If this field is specified when creating a Service - which does not need it, creation will fail. This field - will be wiped when updating a Service to no longer need - it (e.g. changing type). This field cannot be updated - once set. - format: int32 - type: integer - internalTrafficPolicy: - description: InternalTrafficPolicy describes how nodes - distribute service traffic they receive on the ClusterIP. - If set to "Local", the proxy will assume that pods only - want to talk to endpoints of the service on the same - node as the pod, dropping the traffic if there are no - local endpoints. The default value, "Cluster", uses - the standard behavior of routing to all endpoints evenly - (possibly modified by topology and other features). - type: string - ipFamilies: - description: "IPFamilies is a list of IP families (e.g. - IPv4, IPv6) assigned to this service. This field is - usually assigned automatically based on cluster configuration - and the ipFamilyPolicy field. If this field is specified - manually, the requested family is available in the cluster, - and ipFamilyPolicy allows it, it will be used; otherwise - creation of the service will fail. This field is conditionally - mutable: it allows for adding or removing a secondary - IP family, but it does not allow changing the primary - IP family of the Service. Valid values are \"IPv4\" - and \"IPv6\". This field only applies to Services of - types ClusterIP, NodePort, and LoadBalancer, and does - apply to \"headless\" services. This field will be wiped - when updating a Service to type ExternalName. \n This - field may hold a maximum of two entries (dual-stack - families, in either order). These families must correspond - to the values of the clusterIPs field, if specified. - Both clusterIPs and ipFamilies are governed by the ipFamilyPolicy - field." - items: - description: IPFamily represents the IP Family (IPv4 - or IPv6). This type is used to express the family - of an IP expressed by a type (e.g. service.spec.ipFamilies). - type: string - type: array - x-kubernetes-list-type: atomic - ipFamilyPolicy: - description: IPFamilyPolicy represents the dual-stack-ness - requested or required by this Service. If there is no - value provided, then this field will be set to SingleStack. - Services can be "SingleStack" (a single IP family), - "PreferDualStack" (two IP families on dual-stack configured - clusters or a single IP family on single-stack clusters), - or "RequireDualStack" (two IP families on dual-stack - configured clusters, otherwise fail). The ipFamilies - and clusterIPs fields depend on the value of this field. - This field will be wiped when updating a service to - type ExternalName. - type: string - loadBalancerClass: - description: loadBalancerClass is the class of the load - balancer implementation this Service belongs to. If - specified, the value of this field must be a label-style - identifier, with an optional prefix, e.g. "internal-vip" - or "example.com/internal-vip". Unprefixed names are - reserved for end-users. This field can only be set when - the Service type is 'LoadBalancer'. If not set, the - default load balancer implementation is used, today - this is typically done through the cloud provider integration, - but should apply for any default implementation. If - set, it is assumed that a load balancer implementation - is watching for Services with a matching class. Any - default load balancer implementation (e.g. cloud providers) - should ignore Services that set this field. This field - can only be set when creating or updating a Service - to type 'LoadBalancer'. Once set, it can not be changed. - This field will be wiped when a service is updated to - a non 'LoadBalancer' type. - type: string - loadBalancerIP: - description: 'Only applies to Service Type: LoadBalancer. - This feature depends on whether the underlying cloud-provider - supports specifying the loadBalancerIP when a load balancer - is created. This field will be ignored if the cloud-provider - does not support the feature. Deprecated: This field - was under-specified and its meaning varies across implementations, - and it cannot support dual-stack. As of Kubernetes v1.24, - users are encouraged to use implementation-specific - annotations when available. This field may be removed - in a future API version.' - type: string - loadBalancerSourceRanges: - description: 'If specified and supported by the platform, - this will restrict traffic through the cloud-provider - load-balancer will be restricted to the specified client - IPs. This field will be ignored if the cloud-provider - does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' - items: - type: string - type: array - ports: - description: 'The list of ports that are exposed by this - service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - items: - description: ServicePort contains information on service's - port. - properties: - appProtocol: - description: The application protocol for this port. - This field follows standard Kubernetes label syntax. - Un-prefixed names are reserved for IANA standard - service names (as per RFC-6335 and https://www.iana.org/assignments/service-names). - Non-standard protocols should use prefixed names - such as mycompany.com/my-custom-protocol. - type: string - name: - description: The name of this port within the service. - This must be a DNS_LABEL. All ports within a ServiceSpec - must have unique names. When considering the endpoints - for a Service, this must match the 'name' field - in the EndpointPort. Optional if only one ServicePort - is defined on this service. - type: string - nodePort: - description: 'The port on each node on which this - service is exposed when type is NodePort or LoadBalancer. Usually - assigned by the system. If a value is specified, - in-range, and not in use it will be used, otherwise - the operation will fail. If not specified, a - port will be allocated if this Service requires - one. If this field is specified when creating - a Service which does not need it, creation will - fail. This field will be wiped when updating a - Service to no longer need it (e.g. changing type - from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' - format: int32 - type: integer - port: - description: The port that will be exposed by this - service. - format: int32 - type: integer - protocol: - default: TCP - description: The IP protocol for this port. Supports - "TCP", "UDP", and "SCTP". Default is TCP. - type: string - targetPort: - anyOf: - - type: integer - - type: string - description: 'Number or name of the port to access - on the pods targeted by the service. Number must - be in the range 1 to 65535. Name must be an IANA_SVC_NAME. - If this is a string, it will be looked up as a - named port in the target Pod''s container ports. - If this is not specified, the value of the ''port'' - field is used (an identity map). This field is - ignored for services with clusterIP=None, and - should be omitted or set equal to the ''port'' - field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' - x-kubernetes-int-or-string: true - required: - - port - type: object - type: array - x-kubernetes-list-map-keys: - - port - - protocol - x-kubernetes-list-type: map - publishNotReadyAddresses: - description: publishNotReadyAddresses indicates that any - agent which deals with endpoints for this Service should - disregard any indications of ready/not-ready. The primary - use case for setting this field is for a StatefulSet's - Headless Service to propagate SRV DNS records for its - Pods for the purpose of peer discovery. The Kubernetes - controllers that generate Endpoints and EndpointSlice - resources for Services interpret this to mean that all - endpoints are considered "ready" even if the Pods themselves - are not. Agents which consume only Kubernetes generated - endpoints through the Endpoints or EndpointSlice resources - can safely assume this behavior. - type: boolean - selector: - additionalProperties: - type: string - description: 'Route service traffic to pods with label - keys and values matching this selector. If empty or - not present, the service is assumed to have an external - process managing its endpoints, which Kubernetes will - not modify. Only applies to types ClusterIP, NodePort, - and LoadBalancer. Ignored if type is ExternalName. More - info: https://kubernetes.io/docs/concepts/services-networking/service/' - type: object - x-kubernetes-map-type: atomic - sessionAffinity: - description: 'Supports "ClientIP" and "None". Used to - maintain session affinity. Enable client IP based session - affinity. Must be ClientIP or None. Defaults to None. - More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' - type: string - sessionAffinityConfig: - description: sessionAffinityConfig contains the configurations - of session affinity. - properties: - clientIP: - description: clientIP contains the configurations - of Client IP based session affinity. - properties: - timeoutSeconds: - description: timeoutSeconds specifies the seconds - of ClientIP type session sticky time. The value - must be >0 && <=86400(for 1 day) if ServiceAffinity - == "ClientIP". Default value is 10800(for 3 - hours). - format: int32 - type: integer - type: object - type: object - type: - description: 'type determines how the Service is exposed. - Defaults to ClusterIP. Valid options are ExternalName, - ClusterIP, NodePort, and LoadBalancer. "ClusterIP" allocates - a cluster-internal IP address for load-balancing to - endpoints. Endpoints are determined by the selector - or if that is not specified, by manual construction - of an Endpoints object or EndpointSlice objects. If - clusterIP is "None", no virtual IP is allocated and - the endpoints are published as a set of endpoints rather - than a virtual IP. "NodePort" builds on ClusterIP and - allocates a port on every node which routes to the same - endpoints as the clusterIP. "LoadBalancer" builds on - NodePort and creates an external load-balancer (if supported - in the current cloud) which routes to the same endpoints - as the clusterIP. "ExternalName" aliases this service - to the specified externalName. Several other fields - do not apply to ExternalName services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' - type: string - type: object - type: object - tls: - description: TLS defines options for configuring TLS for HTTP. - properties: - certificate: - description: "Certificate is a reference to a Kubernetes secret - that contains the certificate and private key for enabling - TLS. The referenced secret should contain the following: - \n - `ca.crt`: The certificate authority (optional). - `tls.crt`: - The certificate (or a chain). - `tls.key`: The private key - to the first certificate in the certificate chain." - properties: - secretName: - description: SecretName is the name of the secret. - type: string - type: object - selfSignedCertificate: - description: SelfSignedCertificate allows configuring the - self-signed certificate generated by the operator. - properties: - disabled: - description: Disabled indicates that the provisioning - of the self-signed certifcate should be disabled. - type: boolean - subjectAltNames: - description: SubjectAlternativeNames is a list of SANs - to include in the generated HTTP TLS certificate. - items: - description: SubjectAlternativeName represents a SAN - entry in a x509 certificate. - properties: - dns: - description: DNS is the DNS name of the subject. - type: string - ip: - description: IP is the IP address of the subject. - type: string - type: object - type: array - type: object - type: object - type: object image: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. @@ -9655,6 +9227,447 @@ spec: resource to Elasticsearch resource in a different namespace. Can only be used if ECK is enforcing RBAC on references. type: string + services: + description: 'HTTP holds the HTTP layer configuration for the Logstash + Metrics API TODO: This should likely be changed to a more general + `Services LogstashService[]`, where `LogstashService` looks a lot + like `HTTPConfig`, but is applicable for more than just an HTTP + endpoint, as logstash may need to be opened up for other services: + beats, TCP, UDP, etc, inputs' + items: + properties: + name: + type: string + service: + description: Service defines the template for the associated + Kubernetes Service object. + properties: + metadata: + description: ObjectMeta is the metadata of the service. + The name and namespace provided here are managed by ECK + and will be ignored. + properties: + annotations: + additionalProperties: + type: string + type: object + finalizers: + items: + type: string + type: array + labels: + additionalProperties: + type: string + type: object + name: + type: string + namespace: + type: string + type: object + spec: + description: Spec is the specification of the service. + properties: + allocateLoadBalancerNodePorts: + description: allocateLoadBalancerNodePorts defines if + NodePorts will be automatically allocated for services + with type LoadBalancer. Default is "true". It may + be set to "false" if the cluster load-balancer does + not rely on NodePorts. If the caller requests specific + NodePorts (by specifying a value), those requests + will be respected, regardless of this field. This + field may only be set for services with type LoadBalancer + and will be cleared if the type is changed to any + other type. + type: boolean + clusterIP: + description: 'clusterIP is the IP address of the service + and is usually assigned randomly. If an address is + specified manually, is in-range (as per system configuration), + and is not in use, it will be allocated to the service; + otherwise creation of the service will fail. This + field may not be changed through updates unless the + type field is also being changed to ExternalName (which + requires this field to be blank) or the type field + is being changed from ExternalName (in which case + this field may optionally be specified, as describe + above). Valid values are "None", empty string (""), + or a valid IP address. Setting this to "None" makes + a "headless service" (no virtual IP), which is useful + when direct endpoint connections are preferred and + proxying is not required. Only applies to types ClusterIP, + NodePort, and LoadBalancer. If this field is specified + when creating a Service of type ExternalName, creation + will fail. This field will be wiped when updating + a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + clusterIPs: + description: "ClusterIPs is a list of IP addresses assigned + to this service, and are usually assigned randomly. + \ If an address is specified manually, is in-range + (as per system configuration), and is not in use, + it will be allocated to the service; otherwise creation + of the service will fail. This field may not be changed + through updates unless the type field is also being + changed to ExternalName (which requires this field + to be empty) or the type field is being changed from + ExternalName (in which case this field may optionally + be specified, as describe above). Valid values are + \"None\", empty string (\"\"), or a valid IP address. + \ Setting this to \"None\" makes a \"headless service\" + (no virtual IP), which is useful when direct endpoint + connections are preferred and proxying is not required. + \ Only applies to types ClusterIP, NodePort, and LoadBalancer. + If this field is specified when creating a Service + of type ExternalName, creation will fail. This field + will be wiped when updating a Service to type ExternalName. + \ If this field is not specified, it will be initialized + from the clusterIP field. If this field is specified, + clients must ensure that clusterIPs[0] and clusterIP + have the same value. \n This field may hold a maximum + of two entries (dual-stack IPs, in either order). + These IPs must correspond to the values of the ipFamilies + field. Both clusterIPs and ipFamilies are governed + by the ipFamilyPolicy field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" + items: + type: string + type: array + x-kubernetes-list-type: atomic + externalIPs: + description: externalIPs is a list of IP addresses for + which nodes in the cluster will also accept traffic + for this service. These IPs are not managed by Kubernetes. The + user is responsible for ensuring that traffic arrives + at a node with this IP. A common example is external + load-balancers that are not part of the Kubernetes + system. + items: + type: string + type: array + externalName: + description: externalName is the external reference + that discovery mechanisms will return as an alias + for this service (e.g. a DNS CNAME record). No proxying + will be involved. Must be a lowercase RFC-1123 hostname + (https://tools.ietf.org/html/rfc1123) and requires + `type` to be "ExternalName". + type: string + externalTrafficPolicy: + description: externalTrafficPolicy describes how nodes + distribute service traffic they receive on one of + the Service's "externally-facing" addresses (NodePorts, + ExternalIPs, and LoadBalancer IPs). If set to "Local", + the proxy will configure the service in a way that + assumes that external load balancers will take care + of balancing the service traffic between nodes, and + so each node will deliver traffic only to the node-local + endpoints of the service, without masquerading the + client source IP. (Traffic mistakenly sent to a node + with no endpoints will be dropped.) The default value, + "Cluster", uses the standard behavior of routing to + all endpoints evenly (possibly modified by topology + and other features). Note that traffic sent to an + External IP or LoadBalancer IP from within the cluster + will always get "Cluster" semantics, but clients sending + to a NodePort from within the cluster may need to + take traffic policy into account when picking a node. + type: string + healthCheckNodePort: + description: healthCheckNodePort specifies the healthcheck + nodePort for the service. This only applies when type + is set to LoadBalancer and externalTrafficPolicy is + set to Local. If a value is specified, is in-range, + and is not in use, it will be used. If not specified, + a value will be automatically allocated. External + systems (e.g. load-balancers) can use this port to + determine if a given node holds endpoints for this + service or not. If this field is specified when creating + a Service which does not need it, creation will fail. + This field will be wiped when updating a Service to + no longer need it (e.g. changing type). This field + cannot be updated once set. + format: int32 + type: integer + internalTrafficPolicy: + description: InternalTrafficPolicy describes how nodes + distribute service traffic they receive on the ClusterIP. + If set to "Local", the proxy will assume that pods + only want to talk to endpoints of the service on the + same node as the pod, dropping the traffic if there + are no local endpoints. The default value, "Cluster", + uses the standard behavior of routing to all endpoints + evenly (possibly modified by topology and other features). + type: string + ipFamilies: + description: "IPFamilies is a list of IP families (e.g. + IPv4, IPv6) assigned to this service. This field is + usually assigned automatically based on cluster configuration + and the ipFamilyPolicy field. If this field is specified + manually, the requested family is available in the + cluster, and ipFamilyPolicy allows it, it will be + used; otherwise creation of the service will fail. + This field is conditionally mutable: it allows for + adding or removing a secondary IP family, but it does + not allow changing the primary IP family of the Service. + Valid values are \"IPv4\" and \"IPv6\". This field + only applies to Services of types ClusterIP, NodePort, + and LoadBalancer, and does apply to \"headless\" services. + This field will be wiped when updating a Service to + type ExternalName. \n This field may hold a maximum + of two entries (dual-stack families, in either order). + \ These families must correspond to the values of + the clusterIPs field, if specified. Both clusterIPs + and ipFamilies are governed by the ipFamilyPolicy + field." + items: + description: IPFamily represents the IP Family (IPv4 + or IPv6). This type is used to express the family + of an IP expressed by a type (e.g. service.spec.ipFamilies). + type: string + type: array + x-kubernetes-list-type: atomic + ipFamilyPolicy: + description: IPFamilyPolicy represents the dual-stack-ness + requested or required by this Service. If there is + no value provided, then this field will be set to + SingleStack. Services can be "SingleStack" (a single + IP family), "PreferDualStack" (two IP families on + dual-stack configured clusters or a single IP family + on single-stack clusters), or "RequireDualStack" (two + IP families on dual-stack configured clusters, otherwise + fail). The ipFamilies and clusterIPs fields depend + on the value of this field. This field will be wiped + when updating a service to type ExternalName. + type: string + loadBalancerClass: + description: loadBalancerClass is the class of the load + balancer implementation this Service belongs to. If + specified, the value of this field must be a label-style + identifier, with an optional prefix, e.g. "internal-vip" + or "example.com/internal-vip". Unprefixed names are + reserved for end-users. This field can only be set + when the Service type is 'LoadBalancer'. If not set, + the default load balancer implementation is used, + today this is typically done through the cloud provider + integration, but should apply for any default implementation. + If set, it is assumed that a load balancer implementation + is watching for Services with a matching class. Any + default load balancer implementation (e.g. cloud providers) + should ignore Services that set this field. This field + can only be set when creating or updating a Service + to type 'LoadBalancer'. Once set, it can not be changed. + This field will be wiped when a service is updated + to a non 'LoadBalancer' type. + type: string + loadBalancerIP: + description: 'Only applies to Service Type: LoadBalancer. + This feature depends on whether the underlying cloud-provider + supports specifying the loadBalancerIP when a load + balancer is created. This field will be ignored if + the cloud-provider does not support the feature. Deprecated: + This field was under-specified and its meaning varies + across implementations, and it cannot support dual-stack. + As of Kubernetes v1.24, users are encouraged to use + implementation-specific annotations when available. + This field may be removed in a future API version.' + type: string + loadBalancerSourceRanges: + description: 'If specified and supported by the platform, + this will restrict traffic through the cloud-provider + load-balancer will be restricted to the specified + client IPs. This field will be ignored if the cloud-provider + does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/' + items: + type: string + type: array + ports: + description: 'The list of ports that are exposed by + this service. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + items: + description: ServicePort contains information on service's + port. + properties: + appProtocol: + description: The application protocol for this + port. This field follows standard Kubernetes + label syntax. Un-prefixed names are reserved + for IANA standard service names (as per RFC-6335 + and https://www.iana.org/assignments/service-names). + Non-standard protocols should use prefixed names + such as mycompany.com/my-custom-protocol. + type: string + name: + description: The name of this port within the + service. This must be a DNS_LABEL. All ports + within a ServiceSpec must have unique names. + When considering the endpoints for a Service, + this must match the 'name' field in the EndpointPort. + Optional if only one ServicePort is defined + on this service. + type: string + nodePort: + description: 'The port on each node on which this + service is exposed when type is NodePort or + LoadBalancer. Usually assigned by the system. + If a value is specified, in-range, and not in + use it will be used, otherwise the operation + will fail. If not specified, a port will be + allocated if this Service requires one. If + this field is specified when creating a Service + which does not need it, creation will fail. + This field will be wiped when updating a Service + to no longer need it (e.g. changing type from + NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport' + format: int32 + type: integer + port: + description: The port that will be exposed by + this service. + format: int32 + type: integer + protocol: + default: TCP + description: The IP protocol for this port. Supports + "TCP", "UDP", and "SCTP". Default is TCP. + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: 'Number or name of the port to access + on the pods targeted by the service. Number + must be in the range 1 to 65535. Name must be + an IANA_SVC_NAME. If this is a string, it will + be looked up as a named port in the target Pod''s + container ports. If this is not specified, the + value of the ''port'' field is used (an identity + map). This field is ignored for services with + clusterIP=None, and should be omitted or set + equal to the ''port'' field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service' + x-kubernetes-int-or-string: true + required: + - port + type: object + type: array + x-kubernetes-list-map-keys: + - port + - protocol + x-kubernetes-list-type: map + publishNotReadyAddresses: + description: publishNotReadyAddresses indicates that + any agent which deals with endpoints for this Service + should disregard any indications of ready/not-ready. + The primary use case for setting this field is for + a StatefulSet's Headless Service to propagate SRV + DNS records for its Pods for the purpose of peer discovery. + The Kubernetes controllers that generate Endpoints + and EndpointSlice resources for Services interpret + this to mean that all endpoints are considered "ready" + even if the Pods themselves are not. Agents which + consume only Kubernetes generated endpoints through + the Endpoints or EndpointSlice resources can safely + assume this behavior. + type: boolean + selector: + additionalProperties: + type: string + description: 'Route service traffic to pods with label + keys and values matching this selector. If empty or + not present, the service is assumed to have an external + process managing its endpoints, which Kubernetes will + not modify. Only applies to types ClusterIP, NodePort, + and LoadBalancer. Ignored if type is ExternalName. + More info: https://kubernetes.io/docs/concepts/services-networking/service/' + type: object + x-kubernetes-map-type: atomic + sessionAffinity: + description: 'Supports "ClientIP" and "None". Used to + maintain session affinity. Enable client IP based + session affinity. Must be ClientIP or None. Defaults + to None. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies' + type: string + sessionAffinityConfig: + description: sessionAffinityConfig contains the configurations + of session affinity. + properties: + clientIP: + description: clientIP contains the configurations + of Client IP based session affinity. + properties: + timeoutSeconds: + description: timeoutSeconds specifies the seconds + of ClientIP type session sticky time. The + value must be >0 && <=86400(for 1 day) if + ServiceAffinity == "ClientIP". Default value + is 10800(for 3 hours). + format: int32 + type: integer + type: object + type: object + type: + description: 'type determines how the Service is exposed. + Defaults to ClusterIP. Valid options are ExternalName, + ClusterIP, NodePort, and LoadBalancer. "ClusterIP" + allocates a cluster-internal IP address for load-balancing + to endpoints. Endpoints are determined by the selector + or if that is not specified, by manual construction + of an Endpoints object or EndpointSlice objects. If + clusterIP is "None", no virtual IP is allocated and + the endpoints are published as a set of endpoints + rather than a virtual IP. "NodePort" builds on ClusterIP + and allocates a port on every node which routes to + the same endpoints as the clusterIP. "LoadBalancer" + builds on NodePort and creates an external load-balancer + (if supported in the current cloud) which routes to + the same endpoints as the clusterIP. "ExternalName" + aliases this service to the specified externalName. + Several other fields do not apply to ExternalName + services. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types' + type: string + type: object + type: object + tls: + description: TLS defines options for configuring TLS for HTTP. + properties: + certificate: + description: "Certificate is a reference to a Kubernetes + secret that contains the certificate and private key for + enabling TLS. The referenced secret should contain the + following: \n - `ca.crt`: The certificate authority (optional). + - `tls.crt`: The certificate (or a chain). - `tls.key`: + The private key to the first certificate in the certificate + chain." + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object + selfSignedCertificate: + description: SelfSignedCertificate allows configuring the + self-signed certificate generated by the operator. + properties: + disabled: + description: Disabled indicates that the provisioning + of the self-signed certifcate should be disabled. + type: boolean + subjectAltNames: + description: SubjectAlternativeNames is a list of SANs + to include in the generated HTTP TLS certificate. + items: + description: SubjectAlternativeName represents a SAN + entry in a x509 certificate. + properties: + dns: + description: DNS is the DNS name of the subject. + type: string + ip: + description: IP is the IP address of the subject. + type: string + type: object + type: array + type: object + type: object + type: object + type: array version: description: Version of the Logstash. type: string diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 781b519f72..60eb25aafa 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -494,7 +494,6 @@ HTTPConfig holds the HTTP layer configuration for resources. - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-enterprisesearch-v1beta1-enterprisesearchspec[$$EnterpriseSearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-maps-v1alpha1-mapsspec[$$MapsSpec$$] **** @@ -720,6 +719,7 @@ ServiceTemplate defines the template for a Kubernetes Service. .Appears In: **** - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-transportconfig[$$TransportConfig$$] **** @@ -759,6 +759,7 @@ TLSOptions holds TLS configuration options. .Appears In: **** - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] **** [cols="25a,75a", options="header"] @@ -1858,6 +1859,25 @@ Logstash is the Schema for the logstashes API +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice"] +=== LogstashService + + + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] +**** + +[cols="25a,75a", options="header"] +|=== +| Field | Description +| *`name`* __string__ | +| *`service`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-servicetemplate[$$ServiceTemplate$$]__ | Service defines the template for the associated Kubernetes Service object. +| *`tls`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-tlsoptions[$$TLSOptions$$]__ | TLS defines options for configuring TLS for HTTP. +|=== + + [id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec"] === LogstashSpec @@ -1876,7 +1896,7 @@ LogstashSpec defines the desired state of Logstash | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. -| *`http`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-httpconfig[$$HTTPConfig$$]__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs +| *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 0d10621327..98dc25d74f 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -44,7 +44,7 @@ type LogstashSpec struct { // a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to // be opened up for other services: beats, TCP, UDP, etc, inputs // +kubebuilder:validation:Optional - HTTP commonv1.HTTPConfig `json:"http,omitempty"` + Services []LogstashService `json:"services,omitempty"` // PodTemplate provides customisation options for the Logstash pods. PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` @@ -64,6 +64,14 @@ type LogstashSpec struct { ServiceAccountName string `json:"serviceAccountName,omitempty"` } +type LogstashService struct { + Name string `json:"name,omitempty"` + // Service defines the template for the associated Kubernetes Service object. + Service commonv1.ServiceTemplate `json:"service,omitempty"` + // TLS defines options for configuring TLS for HTTP. + TLS commonv1.TLSOptions `json:"tls,omitempty"` +} + // LogstashStatus defines the observed state of Logstash type LogstashStatus struct { // Version of the stack resource currently running. During version upgrades, multiple versions may run diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go index c038173b2e..e2140c3fe5 100644 --- a/pkg/apis/logstash/v1alpha1/name.go +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -34,3 +34,7 @@ func Name(name string) string { func HTTPServiceName(name string) string { return Namer.Suffix(name, httpServiceSuffix) } + +func UserServiceName(deployName string, name string) string { + return Namer.Suffix(deployName, name) +} diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index 42ca5a613e..e4863e0454 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -73,6 +73,23 @@ func (in *LogstashList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashService) DeepCopyInto(out *LogstashService) { + *out = *in + in.Service.DeepCopyInto(&out.Service) + in.TLS.DeepCopyInto(&out.TLS) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashService. +func (in *LogstashService) DeepCopy() *LogstashService { + if in == nil { + return nil + } + out := new(LogstashService) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { *out = *in @@ -85,7 +102,13 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { *out = new(v1.ConfigSource) **out = **in } - in.HTTP.DeepCopyInto(&out.HTTP) + if in.Services != nil { + in, out := &in.Services, &out.Services + *out = make([]LogstashService, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } in.PodTemplate.DeepCopyInto(&out.PodTemplate) if in.RevisionHistoryLimit != nil { in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 7c432ffb0f..8a17affb1c 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -7,12 +7,8 @@ package logstash import ( "context" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" - "hash/fnv" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" - "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" "k8s.io/client-go/tools/record" @@ -22,7 +18,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" ) @@ -76,7 +71,7 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log defer tracing.Span(¶ms.Context)() results := reconciler.NewResult(params.Context) - _, err := common.ReconcileService(params.Context, params.Client, newService(params.Logstash), ¶ms.Logstash) + _, err := reconcileServices(params) if err != nil { return results.WithError(err), params.Status } @@ -90,23 +85,3 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log podTemplate := buildPodTemplate(params, configHash) return reconcileStatefulSet(params, podTemplate) } - -func newService(logstash logstashv1alpha1.Logstash) *corev1.Service { - svc := corev1.Service{ - ObjectMeta: logstash.Spec.HTTP.Service.ObjectMeta, - Spec: logstash.Spec.HTTP.Service.Spec, - } - - svc.ObjectMeta.Namespace = logstash.Namespace - svc.ObjectMeta.Name = logstashv1alpha1.HTTPServiceName(logstash.Name) - - labels := logstash.GetIdentityLabels() - ports := []corev1.ServicePort{ - { - Name: logstash.Spec.HTTP.Protocol(), - Protocol: corev1.ProtocolTCP, - Port: network.HTTPPort, - }, - } - return defaults.SetServiceDefaults(&svc, labels, labels, ports) -} diff --git a/pkg/controller/logstash/labels.go b/pkg/controller/logstash/labels.go index f69c95902b..e277e77e19 100644 --- a/pkg/controller/logstash/labels.go +++ b/pkg/controller/logstash/labels.go @@ -4,13 +4,26 @@ package logstash +import ( + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" +) + const ( // TypeLabelValue represents the Logstash type. TypeLabelValue = "logstash" - // NameLabelName used to represent an Logstash in k8s resources + // NameLabelName used to represent a Logstash in k8s resources NameLabelName = "logstash.k8s.elastic.co/name" - // NamespaceLabelName used to represent an Logstash in k8s resources + // NamespaceLabelName used to represent a Logstash in k8s resources NamespaceLabelName = "logstash.k8s.elastic.co/namespace" ) + +// NewLabels returns the set of common labels for an Elastic Logstash. +func NewLabels(logstash logstashv1alpha1.Logstash) map[string]string { + return map[string]string{ + commonv1.TypeLabelName: TypeLabelValue, + NameLabelName: logstash.Name, + } +} diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 077547de38..9fd3c9f3b9 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -98,7 +98,7 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.ContainerPort { return []corev1.ContainerPort{ - {Name: logstash.Spec.HTTP.Protocol(), ContainerPort: int32(network.HTTPPort), Protocol: corev1.ProtocolTCP}, + {Name: "http", ContainerPort: int32(network.HTTPPort), Protocol: corev1.ProtocolTCP}, } } diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go new file mode 100644 index 0000000000..7e0357a406 --- /dev/null +++ b/pkg/controller/logstash/service.go @@ -0,0 +1,87 @@ +package logstash + +import ( + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// reconcileServices reconcile Services defined in spec +// When Services are empty, a default Service for port 9600 is created. +// If api.http.port is customized, user is expected to config Services. +// When Services exist, the port 9600 does not attach to any of Service. +func reconcileServices(params Params) ([]corev1.Service, error) { + if len(params.Logstash.Spec.Services) == 0 { + svc := newDefaultService(params.Logstash) + + if err := reconcileService(params, svc); err != nil { + return []corev1.Service{}, err + } + + return []corev1.Service{*svc}, nil + } else { + var svcs []corev1.Service + for _, service := range params.Logstash.Spec.Services { + svc := newService(service, params.Logstash) + + if err := reconcileService(params, svc); err != nil { + return []corev1.Service{}, err + } + + svcs = append(svcs, *svc) + } + + return svcs, nil + } +} + +func reconcileService(params Params, service *corev1.Service) error { + _, err := common.ReconcileService(params.Context, params.Client, service, ¶ms.Logstash) + if err != nil { + return err + } + return nil +} + +func newService(service logstashv1alpha1.LogstashService, logstash logstashv1alpha1.Logstash) *corev1.Service { + svc := corev1.Service{ + ObjectMeta: service.Service.ObjectMeta, + Spec: service.Service.Spec, + } + + svc.ObjectMeta.Namespace = logstash.Namespace + svc.ObjectMeta.Name = logstashv1alpha1.UserServiceName(logstash.Name, service.Name) + + labels := NewLabels(logstash) + + svc.Labels = labels + + if svc.Spec.Selector == nil { + svc.Spec.Selector = labels + } + + return &svc +} + +func newDefaultService(logstash logstashv1alpha1.Logstash) *corev1.Service { + svc := corev1.Service{ + ObjectMeta: metav1.ObjectMeta{}, + Spec: corev1.ServiceSpec{}, + } + + svc.ObjectMeta.Namespace = logstash.Namespace + svc.ObjectMeta.Name = logstashv1alpha1.HTTPServiceName(logstash.Name) + + labels := NewLabels(logstash) + ports := []corev1.ServicePort{ + { + Name: "metrics", + Protocol: corev1.ProtocolTCP, + Port: network.HTTPPort, + }, + } + return defaults.SetServiceDefaults(&svc, labels, labels, ports) +} From 94b84b5de6181f642fc787ca4551d6ca3f57d401 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 19:29:04 +0000 Subject: [PATCH 059/160] webhook check all rules --- pkg/apis/logstash/v1alpha1/webhook.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go index ab9f69de37..3945b05be7 100644 --- a/pkg/apis/logstash/v1alpha1/webhook.go +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -69,10 +69,6 @@ func (a *Logstash) validate(old *Logstash) error { errors = append(errors, err...) } } - - if len(errors) > 0 { - return apierrors.NewInvalid(groupKind, a.Name, errors) - } } for _, dc := range defaultChecks { From 1cfb725605235058f68cd9bbcab876506f3a149c Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 21:12:59 +0000 Subject: [PATCH 060/160] remove building config from existing config in Secret --- pkg/controller/logstash/config.go | 49 +++---------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index 2536c6c70d..4c66006c6b 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -5,24 +5,16 @@ package logstash import ( - "context" "hash" - apierrors "k8s.io/apimachinery/pkg/api/errors" - - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" - ulog "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func reconcileConfig(params Params, configHash hash.Hash) *reconciler.Results { @@ -55,11 +47,6 @@ func reconcileConfig(params Params, configHash hash.Hash) *reconciler.Results { } func buildConfig(params Params) ([]byte, error) { - existingCfg, err := getExistingConfig(params.Context, params.Client, params.Logstash) - if err != nil { - return nil, err - } - userProvidedCfg, err := getUserConfig(params) if err != nil { return nil, err @@ -71,41 +58,13 @@ func buildConfig(params Params) ([]byte, error) { } // merge with user settings last so they take precedence - if err := cfg.MergeWith(existingCfg, userProvidedCfg); err != nil { + if err := cfg.MergeWith(userProvidedCfg); err != nil { return nil, err } return cfg.Render() } -// getExistingConfig retrieves the canonical config, if one exists -func getExistingConfig(ctx context.Context, client k8s.Client, logstash logstashv1alpha1.Logstash) (*settings.CanonicalConfig, error) { - var secret corev1.Secret - key := types.NamespacedName{ - Namespace: logstash.Namespace, - Name: logstashv1alpha1.ConfigSecretName(logstash.Name), - } - err := client.Get(context.Background(), key, &secret) - if err != nil && apierrors.IsNotFound(err) { - ulog.FromContext(ctx).V(1).Info("Logstash config secret does not exist", "namespace", logstash.Namespace, "name", logstash.Name) - return nil, nil - } else if err != nil { - return nil, err - } - - rawCfg, exists := secret.Data[LogstashConfigFileName] - if !exists { - return nil, nil - } - - cfg, err := settings.ParseConfig(rawCfg) - if err != nil { - return nil, err - } - - return cfg, nil -} - // getUserConfig extracts the config either from the spec `config` field or from the Secret referenced by spec // `configRef` field. func getUserConfig(params Params) (*settings.CanonicalConfig, error) { From bb79c1729a46674d15bac0b841b98ab88f675754 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 21:20:19 +0000 Subject: [PATCH 061/160] rename k8sutils EmitErrorEvent() to MaybeEmitErrorEvent() --- pkg/controller/agent/controller.go | 4 ++-- pkg/controller/apmserver/controller.go | 8 ++++---- pkg/controller/association/reconciler.go | 2 +- pkg/controller/beat/controller.go | 4 ++-- pkg/controller/elasticsearch/certificates/reconcile.go | 2 +- pkg/controller/elasticsearch/elasticsearch_controller.go | 4 ++-- .../enterprisesearch/enterprisesearch_controller.go | 4 ++-- pkg/controller/kibana/controller.go | 4 ++-- pkg/controller/kibana/driver.go | 6 +++--- pkg/controller/logstash/logstash_controller.go | 4 ++-- pkg/controller/maps/controller.go | 4 ++-- pkg/controller/stackconfigpolicy/controller.go | 2 +- pkg/utils/k8s/k8sutils.go | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/controller/agent/controller.go b/pkg/controller/agent/controller.go index 62ed7001ce..ab57ced8e3 100644 --- a/pkg/controller/agent/controller.go +++ b/pkg/controller/agent/controller.go @@ -154,7 +154,7 @@ func (r *ReconcileAgent) Reconcile(ctx context.Context, request reconcile.Reques } result, err := results.Aggregate() - k8s.EmitErrorEvent(r.recorder, err, agent, events.EventReconciliationError, "Reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, agent, events.EventReconciliationError, "Reconciliation error: %v", err) return result, err } @@ -195,7 +195,7 @@ func (r *ReconcileAgent) validate(ctx context.Context, agent agentv1alpha1.Agent // Run create validations only as update validations require old object which we don't have here. if err := agent.ValidateCreate(); err != nil { logconf.FromContext(ctx).Error(err, "Validation failed") - k8s.EmitErrorEvent(r.recorder, err, &agent, events.EventReasonValidation, err.Error()) + k8s.MaybeEmitErrorEvent(r.recorder, err, &agent, events.EventReasonValidation, err.Error()) return tracing.CaptureError(ctx, err) } return nil diff --git a/pkg/controller/apmserver/controller.go b/pkg/controller/apmserver/controller.go index 4d99e2dc4d..93eefb8249 100644 --- a/pkg/controller/apmserver/controller.go +++ b/pkg/controller/apmserver/controller.go @@ -246,7 +246,7 @@ func (r *ReconcileApmServer) doReconcile(ctx context.Context, as *apmv1.ApmServe }.ReconcileCAAndHTTPCerts(ctx) if results.HasError() { _, err := results.Aggregate() - k8s.EmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Certificate reconciliation error: %v", err) return results, state } @@ -271,14 +271,14 @@ func (r *ReconcileApmServer) doReconcile(ctx context.Context, as *apmv1.ApmServe log.V(1).Info("Conflict while updating status") return results.WithResult(reconcile.Result{Requeue: true}), state } - k8s.EmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Deployment reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Deployment reconciliation error: %v", err) return results.WithError(tracing.CaptureError(ctx, err)), state } state.UpdateApmServerExternalService(*svc) _, err = results.WithError(err).Aggregate() - k8s.EmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Reconciliation error: %v", err) return results, state } @@ -300,7 +300,7 @@ func (r *ReconcileApmServer) validate(ctx context.Context, as *apmv1.ApmServer) if err := as.ValidateCreate(); err != nil { log.Error(err, "Validation failed") - k8s.EmitErrorEvent(r.recorder, err, as, events.EventReasonValidation, err.Error()) + k8s.MaybeEmitErrorEvent(r.recorder, err, as, events.EventReasonValidation, err.Error()) return tracing.CaptureError(vctx, err) } diff --git a/pkg/controller/association/reconciler.go b/pkg/controller/association/reconciler.go index 1b91282773..c0801453f8 100644 --- a/pkg/controller/association/reconciler.go +++ b/pkg/controller/association/reconciler.go @@ -402,7 +402,7 @@ func (r *Reconciler) getElasticsearch( var es esv1.Elasticsearch err := r.Get(ctx, elasticsearchRef.NamespacedName(), &es) if err != nil { - k8s.EmitErrorEvent(r.recorder, err, association, events.EventAssociationError, + k8s.MaybeEmitErrorEvent(r.recorder, err, association, events.EventAssociationError, "Failed to find referenced backend %s: %v", elasticsearchRef.NamespacedName(), err) if apierrors.IsNotFound(err) { // ES is not found, remove any existing backend configuration and retry in a bit. diff --git a/pkg/controller/beat/controller.go b/pkg/controller/beat/controller.go index f7aef5f04f..e1b0ebcdde 100644 --- a/pkg/controller/beat/controller.go +++ b/pkg/controller/beat/controller.go @@ -160,7 +160,7 @@ func (r *ReconcileBeat) Reconcile(ctx context.Context, request reconcile.Request } res, err := results.Aggregate() - k8s.EmitErrorEvent(r.recorder, err, &beat, events.EventReconciliationError, "Reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, &beat, events.EventReconciliationError, "Reconciliation error: %v", err) return res, err } @@ -192,7 +192,7 @@ func (r *ReconcileBeat) validate(ctx context.Context, beat *beatv1beta1.Beat) er if err := beat.ValidateCreate(); err != nil { ulog.FromContext(ctx).Error(err, "Validation failed") - k8s.EmitErrorEvent(r.recorder, err, beat, events.EventReasonValidation, err.Error()) + k8s.MaybeEmitErrorEvent(r.recorder, err, beat, events.EventReasonValidation, err.Error()) return tracing.CaptureError(vctx, err) } diff --git a/pkg/controller/elasticsearch/certificates/reconcile.go b/pkg/controller/elasticsearch/certificates/reconcile.go index 4a0c040bb8..086ecef638 100644 --- a/pkg/controller/elasticsearch/certificates/reconcile.go +++ b/pkg/controller/elasticsearch/certificates/reconcile.go @@ -71,7 +71,7 @@ func ReconcileHTTP( }.ReconcileCAAndHTTPCerts(ctx) if results.HasError() { _, err := results.Aggregate() - k8s.EmitErrorEvent(driver.Recorder(), err, &es, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(driver.Recorder(), err, &es, events.EventReconciliationError, "Certificate reconciliation error: %v", err) return nil, results } diff --git a/pkg/controller/elasticsearch/elasticsearch_controller.go b/pkg/controller/elasticsearch/elasticsearch_controller.go index 68b998f552..40fe6dbd3d 100644 --- a/pkg/controller/elasticsearch/elasticsearch_controller.go +++ b/pkg/controller/elasticsearch/elasticsearch_controller.go @@ -194,7 +194,7 @@ func (r *ReconcileElasticsearch) Reconcile(ctx context.Context, request reconcil } else { log.Error(err, "Error while updating annotations", "namespace", es.Namespace, "es_name", es.Name) results.WithError(err) - k8s.EmitErrorEvent(r.recorder, err, &es, events.EventReconciliationError, "Reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, &es, events.EventReconciliationError, "Reconciliation error: %v", err) } } @@ -212,7 +212,7 @@ func (r *ReconcileElasticsearch) Reconcile(ctx context.Context, request reconcil log.V(1).Info("Conflict while updating status", "namespace", es.Namespace, "es_name", es.Name) return reconcile.Result{Requeue: true}, nil } - k8s.EmitErrorEvent(r.recorder, err, &es, events.EventReconciliationError, "Reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, &es, events.EventReconciliationError, "Reconciliation error: %v", err) } return results.WithError(err).Aggregate() } diff --git a/pkg/controller/enterprisesearch/enterprisesearch_controller.go b/pkg/controller/enterprisesearch/enterprisesearch_controller.go index d343d41539..b9a8557f22 100644 --- a/pkg/controller/enterprisesearch/enterprisesearch_controller.go +++ b/pkg/controller/enterprisesearch/enterprisesearch_controller.go @@ -215,7 +215,7 @@ func (r *ReconcileEnterpriseSearch) doReconcile(ctx context.Context, ent entv1.E }.ReconcileCAAndHTTPCerts(ctx) if results.HasError() { _, err := results.Aggregate() - k8s.EmitErrorEvent(r.recorder, err, &ent, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, &ent, events.EventReconciliationError, "Certificate reconciliation error: %v", err) return results, status } @@ -275,7 +275,7 @@ func (r *ReconcileEnterpriseSearch) validate(ctx context.Context, ent *entv1.Ent if err := ent.ValidateCreate(); err != nil { ulog.FromContext(ctx).Error(err, "Validation failed") - k8s.EmitErrorEvent(r.recorder, err, ent, events.EventReasonValidation, err.Error()) + k8s.MaybeEmitErrorEvent(r.recorder, err, ent, events.EventReasonValidation, err.Error()) return tracing.CaptureError(vctx, err) } diff --git a/pkg/controller/kibana/controller.go b/pkg/controller/kibana/controller.go index 47f722df4d..83b0fdb6d0 100644 --- a/pkg/controller/kibana/controller.go +++ b/pkg/controller/kibana/controller.go @@ -195,7 +195,7 @@ func (r *ReconcileKibana) doReconcile(ctx context.Context, request reconcile.Req results := driver.Reconcile(ctx, &state, kb, r.params) result, err = results.WithError(err).Aggregate() - k8s.EmitErrorEvent(r.recorder, err, kb, events.EventReconciliationError, "Reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, kb, events.EventReconciliationError, "Reconciliation error: %v", err) return result, err } @@ -205,7 +205,7 @@ func (r *ReconcileKibana) validate(ctx context.Context, kb *kbv1.Kibana) error { if err := kb.ValidateCreate(); err != nil { ulog.FromContext(ctx).Error(err, "Validation failed") - k8s.EmitErrorEvent(r.recorder, err, kb, events.EventReasonValidation, err.Error()) + k8s.MaybeEmitErrorEvent(r.recorder, err, kb, events.EventReasonValidation, err.Error()) return tracing.CaptureError(vctx, err) } diff --git a/pkg/controller/kibana/driver.go b/pkg/controller/kibana/driver.go index 1337139213..32f374941e 100644 --- a/pkg/controller/kibana/driver.go +++ b/pkg/controller/kibana/driver.go @@ -73,13 +73,13 @@ func newDriver( ) (*driver, error) { ver, err := version.Parse(kb.Spec.Version) if err != nil { - k8s.EmitErrorEvent(recorder, err, kb, events.EventReasonValidation, "Invalid version '%s': %v", kb.Spec.Version, err) + k8s.MaybeEmitErrorEvent(recorder, err, kb, events.EventReasonValidation, "Invalid version '%s': %v", kb.Spec.Version, err) return nil, err } if !ver.GTE(minSupportedVersion) { err := pkgerrors.Errorf("unsupported Kibana version: %s", ver) - k8s.EmitErrorEvent(recorder, err, kb, events.EventReasonValidation, "Unsupported Kibana version") + k8s.MaybeEmitErrorEvent(recorder, err, kb, events.EventReasonValidation, "Unsupported Kibana version") return nil, err } @@ -135,7 +135,7 @@ func (d *driver) Reconcile( }.ReconcileCAAndHTTPCerts(ctx) if results.HasError() { _, err := results.Aggregate() - k8s.EmitErrorEvent(d.Recorder(), err, kb, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(d.Recorder(), err, kb, events.EventReconciliationError, "Certificate reconciliation error: %v", err) return results } diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go index 5c0c6816b0..2eea84378d 100644 --- a/pkg/controller/logstash/logstash_controller.go +++ b/pkg/controller/logstash/logstash_controller.go @@ -154,7 +154,7 @@ func (r *ReconcileLogstash) Reconcile(ctx context.Context, request reconcile.Req } result, err := results.Aggregate() - k8s.EmitErrorEvent(r.recorder, err, logstash, events.EventReconciliationError, "Reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, logstash, events.EventReconciliationError, "Reconciliation error: %v", err) return result, err } @@ -187,7 +187,7 @@ func (r *ReconcileLogstash) validate(ctx context.Context, logstash logstashv1alp // Run create validations only as update validations require old object which we don't have here. if err := logstash.ValidateCreate(); err != nil { logconf.FromContext(ctx).Error(err, "Validation failed") - k8s.EmitErrorEvent(r.recorder, err, &logstash, events.EventReasonValidation, err.Error()) + k8s.MaybeEmitErrorEvent(r.recorder, err, &logstash, events.EventReasonValidation, err.Error()) return tracing.CaptureError(ctx, err) } return nil diff --git a/pkg/controller/maps/controller.go b/pkg/controller/maps/controller.go index 4427a340c3..07ab717d88 100644 --- a/pkg/controller/maps/controller.go +++ b/pkg/controller/maps/controller.go @@ -233,7 +233,7 @@ func (r *ReconcileMapsServer) doReconcile(ctx context.Context, ems emsv1alpha1.E }.ReconcileCAAndHTTPCerts(ctx) if results.HasError() { _, err := results.Aggregate() - k8s.EmitErrorEvent(r.recorder, err, &ems, events.EventReconciliationError, "Certificate reconciliation error: %v", err) + k8s.MaybeEmitErrorEvent(r.recorder, err, &ems, events.EventReconciliationError, "Certificate reconciliation error: %v", err) return results, status } @@ -287,7 +287,7 @@ func (r *ReconcileMapsServer) validate(ctx context.Context, ems emsv1alpha1.Elas if err := ems.ValidateCreate(); err != nil { ulog.FromContext(ctx).Error(err, "Validation failed") - k8s.EmitErrorEvent(r.recorder, err, &ems, events.EventReasonValidation, err.Error()) + k8s.MaybeEmitErrorEvent(r.recorder, err, &ems, events.EventReasonValidation, err.Error()) return tracing.CaptureError(vctx, err) } diff --git a/pkg/controller/stackconfigpolicy/controller.go b/pkg/controller/stackconfigpolicy/controller.go index 35024a03d0..1fd4ca30e8 100644 --- a/pkg/controller/stackconfigpolicy/controller.go +++ b/pkg/controller/stackconfigpolicy/controller.go @@ -356,7 +356,7 @@ func (r *ReconcileStackConfigPolicy) validate(ctx context.Context, policy *polic if err := policy.ValidateCreate(); err != nil { ulog.FromContext(ctx).Error(err, "Validation failed") - k8s.EmitErrorEvent(r.recorder, err, policy, events.EventReasonValidation, err.Error()) + k8s.MaybeEmitErrorEvent(r.recorder, err, policy, events.EventReasonValidation, err.Error()) return tracing.CaptureError(vctx, err) } diff --git a/pkg/utils/k8s/k8sutils.go b/pkg/utils/k8s/k8sutils.go index a5649770d4..258d92c724 100644 --- a/pkg/utils/k8s/k8sutils.go +++ b/pkg/utils/k8s/k8sutils.go @@ -131,8 +131,8 @@ func GetServiceIPAddresses(svc corev1.Service) []net.IP { return ipAddrs } -// EmitErrorEvent emits an event if the error is report-worthy -func EmitErrorEvent(r record.EventRecorder, err error, obj runtime.Object, reason, message string, args ...interface{}) { +// MaybeEmitErrorEvent emits an event if the error is report-worthy +func MaybeEmitErrorEvent(r record.EventRecorder, err error, obj runtime.Object, reason, message string, args ...interface{}) { // ignore nil errors and conflict issues if err == nil || apierrors.IsConflict(err) { return From 8ec15018a0c6203536acf9a9eb9335e192f7aabc Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 21:34:32 +0000 Subject: [PATCH 062/160] remove nil error in StatefulSet --- pkg/controller/logstash/reconcile.go | 2 +- pkg/controller/logstash/sset/sset.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go index c74149a1dd..a378ea2121 100644 --- a/pkg/controller/logstash/reconcile.go +++ b/pkg/controller/logstash/reconcile.go @@ -28,7 +28,7 @@ func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*r defer tracing.Span(¶ms.Context)() results := reconciler.NewResult(params.Context) - s, _ := sset.New(sset.Params{ + s := sset.New(sset.Params{ Name: logstashv1alpha1.Name(params.Logstash.Name), Namespace: params.Logstash.Namespace, ServiceName: logstashv1alpha1.HTTPServiceName(params.Logstash.Name), diff --git a/pkg/controller/logstash/sset/sset.go b/pkg/controller/logstash/sset/sset.go index 39bc56e26d..55ca479170 100644 --- a/pkg/controller/logstash/sset/sset.go +++ b/pkg/controller/logstash/sset/sset.go @@ -30,7 +30,7 @@ type Params struct { RevisionHistoryLimit *int32 } -func New(params Params) (appsv1.StatefulSet, error) { +func New(params Params) appsv1.StatefulSet { sset := appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ Name: params.Name, @@ -59,7 +59,7 @@ func New(params Params) (appsv1.StatefulSet, error) { // store a hash of the sset resource in its labels for comparison purposes sset.Labels = hash.SetTemplateHashLabel(sset.Labels, sset.Spec) - return sset, nil + return sset } // Reconcile creates or updates the expected StatefulSet. From aec57e49bedc67c6b4da43b582b4749180c725fa Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 21:57:41 +0000 Subject: [PATCH 063/160] remove APIError struct in test --- test/e2e/test/logstash/http_client.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go index 2aea4ce8bf..e9335f5562 100644 --- a/test/e2e/test/logstash/http_client.go +++ b/test/e2e/test/logstash/http_client.go @@ -16,15 +16,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) -type APIError struct { - StatusCode int - msg string -} - -func (e *APIError) Error() string { - return e.msg -} - // TODO refactor identical to Kibana client func NewLogstashClient(logstash v1alpha1.Logstash, k *test.K8sClient) (*http.Client, error) { var caCerts []*x509.Certificate @@ -58,10 +49,7 @@ func DoRequest(client *http.Client, logstash v1alpha1.Logstash, method, path str } defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode > 299 { - return nil, &APIError{ - StatusCode: resp.StatusCode, - msg: fmt.Sprintf("fail to request %s, status is %d)", path, resp.StatusCode), - } + return nil, fmt.Errorf("fail to request %s, status is %d)\n", path, resp.StatusCode) } return io.ReadAll(resp.Body) } From b27445c95c7fbb029e7cdeaee4d27fa07f1eb12d Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Feb 2023 22:24:16 +0000 Subject: [PATCH 064/160] add license header --- pkg/controller/logstash/service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go index 7e0357a406..a934db2465 100644 --- a/pkg/controller/logstash/service.go +++ b/pkg/controller/logstash/service.go @@ -1,3 +1,7 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + package logstash import ( From 746a307ef436a6e45d73cc70b60e494e6c4462a4 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Fri, 24 Feb 2023 12:36:40 +0000 Subject: [PATCH 065/160] lint --- pkg/controller/logstash/config.go | 5 +++-- pkg/controller/logstash/pod.go | 4 ++-- pkg/controller/logstash/service.go | 23 ++++++++++++----------- test/e2e/test/logstash/http_client.go | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index 4c66006c6b..2b8ff34689 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -7,14 +7,15 @@ package logstash import ( "hash" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func reconcileConfig(params Params, configHash hash.Hash) *reconciler.Results { diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 9fd3c9f3b9..a1d71bcf6a 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -73,7 +73,7 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS ConfigHashAnnotationName: fmt.Sprint(configHash.Sum32()), } - ports := getDefaultContainerPorts(params.Logstash) + ports := getDefaultContainerPorts() builder = builder. WithResources(DefaultResources). @@ -96,7 +96,7 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS return builder.PodTemplate } -func getDefaultContainerPorts(logstash logstashv1alpha1.Logstash) []corev1.ContainerPort { +func getDefaultContainerPorts() []corev1.ContainerPort { return []corev1.ContainerPort{ {Name: "http", ContainerPort: int32(network.HTTPPort), Protocol: corev1.ProtocolTCP}, } diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go index a934db2465..8ab2f510b0 100644 --- a/pkg/controller/logstash/service.go +++ b/pkg/controller/logstash/service.go @@ -5,12 +5,13 @@ package logstash import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // reconcileServices reconcile Services defined in spec @@ -26,20 +27,20 @@ func reconcileServices(params Params) ([]corev1.Service, error) { } return []corev1.Service{*svc}, nil - } else { - var svcs []corev1.Service - for _, service := range params.Logstash.Spec.Services { - svc := newService(service, params.Logstash) + } - if err := reconcileService(params, svc); err != nil { - return []corev1.Service{}, err - } + svcs := make([]corev1.Service, len(params.Logstash.Spec.Services)) + for i, service := range params.Logstash.Spec.Services { + svc := newService(service, params.Logstash) - svcs = append(svcs, *svc) + if err := reconcileService(params, svc); err != nil { + return []corev1.Service{}, err } - return svcs, nil + svcs[i] = *svc } + + return svcs, nil } func reconcileService(params Params, service *corev1.Service) error { diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go index e9335f5562..e397957503 100644 --- a/test/e2e/test/logstash/http_client.go +++ b/test/e2e/test/logstash/http_client.go @@ -49,7 +49,7 @@ func DoRequest(client *http.Client, logstash v1alpha1.Logstash, method, path str } defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode > 299 { - return nil, fmt.Errorf("fail to request %s, status is %d)\n", path, resp.StatusCode) + return nil, fmt.Errorf("fail to request %s, status is %d)", path, resp.StatusCode) } return io.ReadAll(resp.Body) } From 822f0ab59dd5605dfe9e85b6ad3e00f152fd5988 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Fri, 24 Feb 2023 13:08:56 +0000 Subject: [PATCH 066/160] reconcileConfig return error --- pkg/controller/logstash/config.go | 9 ++++----- pkg/controller/logstash/driver.go | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index 2b8ff34689..d437718244 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -18,13 +18,12 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" ) -func reconcileConfig(params Params, configHash hash.Hash) *reconciler.Results { +func reconcileConfig(params Params, configHash hash.Hash) error { defer tracing.Span(¶ms.Context)() - results := reconciler.NewResult(params.Context) cfgBytes, err := buildConfig(params) if err != nil { - return results.WithError(err) + return err } expected := corev1.Secret{ @@ -39,12 +38,12 @@ func reconcileConfig(params Params, configHash hash.Hash) *reconciler.Results { } if _, err = reconciler.ReconcileSecret(params.Context, params.Client, expected, ¶ms.Logstash); err != nil { - return results.WithError(err) + return err } _, _ = configHash.Write(cfgBytes) - return results + return nil } func buildConfig(params Params) ([]byte, error) { diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 8a17affb1c..144b7a9711 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -78,8 +78,8 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log configHash := fnv.New32a() - if res := reconcileConfig(params, configHash); res.HasError() { - return results.WithResults(res), params.Status + if err := reconcileConfig(params, configHash); err != nil { + return results.WithError(err), params.Status } podTemplate := buildPodTemplate(params, configHash) From 0a37afe36fbde805ccb04a80a8f051ca2f1924eb Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Fri, 24 Feb 2023 15:04:42 +0000 Subject: [PATCH 067/160] change the default Service to headless service --- pkg/apis/logstash/v1alpha1/name.go | 10 +++++----- pkg/apis/logstash/v1alpha1/name_test.go | 4 ++-- pkg/controller/logstash/reconcile.go | 2 +- pkg/controller/logstash/service.go | 4 ++-- test/e2e/test/logstash/http_client.go | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go index e2140c3fe5..a2a32d47ed 100644 --- a/pkg/apis/logstash/v1alpha1/name.go +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -9,8 +9,8 @@ import ( ) const ( - httpServiceSuffix = "http" - configSuffix = "config" + defaultServiceSuffix = "default" + configSuffix = "config" ) // Namer is a Namer that is configured with the defaults for resources related to a Logstash resource. @@ -30,9 +30,9 @@ func Name(name string) string { return Namer.Suffix(name) } -// HTTPServiceName returns the name of the HTTP service for a given Logstash name. -func HTTPServiceName(name string) string { - return Namer.Suffix(name, httpServiceSuffix) +// DefaultServiceName returns the name of the HTTP service for a given Logstash name. +func DefaultServiceName(name string) string { + return Namer.Suffix(name, defaultServiceSuffix) } func UserServiceName(deployName string, name string) string { diff --git a/pkg/apis/logstash/v1alpha1/name_test.go b/pkg/apis/logstash/v1alpha1/name_test.go index 38f3983d02..e7363a13c2 100644 --- a/pkg/apis/logstash/v1alpha1/name_test.go +++ b/pkg/apis/logstash/v1alpha1/name_test.go @@ -25,8 +25,8 @@ func TestHTTPService(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := HTTPServiceName(tt.args.logstashName); got != tt.want { - t.Errorf("HTTPService() = %v, want %v", got, tt.want) + if got := DefaultServiceName(tt.args.logstashName); got != tt.want { + t.Errorf("DefaultService() = %v, want %v", got, tt.want) } }) } diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go index a378ea2121..c21e8a3d3c 100644 --- a/pkg/controller/logstash/reconcile.go +++ b/pkg/controller/logstash/reconcile.go @@ -31,7 +31,7 @@ func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*r s := sset.New(sset.Params{ Name: logstashv1alpha1.Name(params.Logstash.Name), Namespace: params.Logstash.Namespace, - ServiceName: logstashv1alpha1.HTTPServiceName(params.Logstash.Name), + ServiceName: logstashv1alpha1.DefaultServiceName(params.Logstash.Name), Selector: params.Logstash.GetIdentityLabels(), Labels: params.Logstash.GetIdentityLabels(), PodTemplateSpec: podTemplate, diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go index 8ab2f510b0..ab1a8c761b 100644 --- a/pkg/controller/logstash/service.go +++ b/pkg/controller/logstash/service.go @@ -74,11 +74,11 @@ func newService(service logstashv1alpha1.LogstashService, logstash logstashv1alp func newDefaultService(logstash logstashv1alpha1.Logstash) *corev1.Service { svc := corev1.Service{ ObjectMeta: metav1.ObjectMeta{}, - Spec: corev1.ServiceSpec{}, + Spec: corev1.ServiceSpec{ClusterIP: "None"}, } svc.ObjectMeta.Namespace = logstash.Namespace - svc.ObjectMeta.Name = logstashv1alpha1.HTTPServiceName(logstash.Name) + svc.ObjectMeta.Name = logstashv1alpha1.DefaultServiceName(logstash.Name) labels := NewLabels(logstash) ports := []corev1.ServicePort{ diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go index e397957503..8c0235a164 100644 --- a/test/e2e/test/logstash/http_client.go +++ b/test/e2e/test/logstash/http_client.go @@ -33,7 +33,7 @@ func NewLogstashClient(logstash v1alpha1.Logstash, k *test.K8sClient) (*http.Cli func DoRequest(client *http.Client, logstash v1alpha1.Logstash, method, path string) ([]byte, error) { scheme := "http" - url, err := url.Parse(fmt.Sprintf("%s://%s.%s.svc:9600%s", scheme, v1alpha1.HTTPServiceName(logstash.Name), logstash.Namespace, path)) + url, err := url.Parse(fmt.Sprintf("%s://%s.%s.svc:9600%s", scheme, v1alpha1.DefaultServiceName(logstash.Name), logstash.Namespace, path)) if err != nil { return nil, fmt.Errorf("while parsing URL: %w", err) } From df96068444b94d4dd329af687def3057db68fe6a Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Fri, 24 Feb 2023 15:26:36 +0000 Subject: [PATCH 068/160] fix service test --- pkg/apis/logstash/v1alpha1/name_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/name_test.go b/pkg/apis/logstash/v1alpha1/name_test.go index e7363a13c2..a7704be84d 100644 --- a/pkg/apis/logstash/v1alpha1/name_test.go +++ b/pkg/apis/logstash/v1alpha1/name_test.go @@ -8,7 +8,7 @@ import ( "testing" ) -func TestHTTPService(t *testing.T) { +func TestDefaultService(t *testing.T) { type args struct { logstashName string } @@ -20,7 +20,7 @@ func TestHTTPService(t *testing.T) { { name: "sample", args: args{logstashName: "sample"}, - want: "sample-ls-http", + want: "sample-ls-default", }, } for _, tt := range tests { From 4c414bd86b6f1b0e84f58ae25f24a01e9e7f827f Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Mon, 27 Feb 2023 13:26:55 +0000 Subject: [PATCH 069/160] fix podTemplate and doc generation --- config/crds/v1/all-crds.yaml | 1 + .../v1/bases/logstash.k8s.elastic.co_logstashes.yaml | 1 + .../charts/eck-operator-crds/templates/all-crds.yaml | 1 + docs/reference/api-docs.asciidoc | 12 ++++++------ hack/api-docs/config.yaml | 2 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 5 +++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 982dba9809..763fc4fdb8 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9125,6 +9125,7 @@ spec: description: PodTemplate provides customisation options for the Logstash pods. type: object + x-kubernetes-preserve-unknown-fields: true revisionHistoryLimit: description: RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 438333392a..9bc87dbbde 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -7488,6 +7488,7 @@ spec: - containers type: object type: object + x-kubernetes-preserve-unknown-fields: true revisionHistoryLimit: description: RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index f36d773dce..ddb0d02493 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9179,6 +9179,7 @@ spec: description: PodTemplate provides customisation options for the Logstash pods. type: object + x-kubernetes-preserve-unknown-fields: true revisionHistoryLimit: description: RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 60eb25aafa..365e6b8e39 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1835,6 +1835,9 @@ KibanaSpec holds the specification of a Kibana instance. Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API group +.Resource Types +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash[$$Logstash$$] + [id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstash"] @@ -1842,14 +1845,13 @@ Package v1alpha1 contains API Schema definitions for the logstash v1alpha1 API g Logstash is the Schema for the logstashes API -.Appears In: -**** -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashlist[$$LogstashList$$] -**** + [cols="25a,75a", options="header"] |=== | Field | Description +| *`apiVersion`* __string__ | `logstash.k8s.elastic.co/v1alpha1` +| *`kind`* __string__ | `Logstash` | *`metadata`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#objectmeta-v1-meta[$$ObjectMeta$$]__ | Refer to Kubernetes API documentation for fields of `metadata`. | *`spec`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$]__ | @@ -1857,8 +1859,6 @@ Logstash is the Schema for the logstashes API |=== - - [id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice"] === LogstashService diff --git a/hack/api-docs/config.yaml b/hack/api-docs/config.yaml index ec20aa7197..0e09c97da0 100644 --- a/hack/api-docs/config.yaml +++ b/hack/api-docs/config.yaml @@ -1,6 +1,6 @@ processor: ignoreTypes: - - "(Elasticsearch|ElasticsearchAutoscaler|Kibana|ApmServer|EnterpriseSearch|Beat|Agent|StackConfigPolicy)List$" + - "(Elasticsearch|ElasticsearchAutoscaler|Kibana|ApmServer|EnterpriseSearch|Beat|Agent|StackConfigPolicy|Logstash)List$" - "(Kibana|ApmServer|EnterpriseSearch|Beat|Agent|StackConfigPolicy)Health$" - "(ElasticsearchAutoscaler|Kibana|ApmServer|Reconciler|EnterpriseSearch|Beat|Agent|Maps|Policy)Status$" - "ElasticsearchSettings$" diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 98dc25d74f..178bc6c876 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -47,6 +47,7 @@ type LogstashSpec struct { Services []LogstashService `json:"services,omitempty"` // PodTemplate provides customisation options for the Logstash pods. + // +kubebuilder:pruning:PreserveUnknownFields PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` // RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. @@ -90,7 +91,7 @@ type LogstashStatus struct { ObservedGeneration int64 `json:"observedGeneration,omitempty"` } -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:object:root=true // Logstash is the Schema for the logstashes API // +k8s:openapi-gen=true @@ -110,7 +111,7 @@ type Logstash struct { Status LogstashStatus `json:"status,omitempty"` } -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:object:root=true // LogstashList contains a list of Logstash type LogstashList struct { From 018dfbc5117867f4d2e491e7b66b1acbcad65bc0 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 27 Feb 2023 13:37:24 -0500 Subject: [PATCH 070/160] Fix Service tests Update service name verification to `default` from `http` --- test/e2e/test/logstash/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 8ae6cd1678..0aead87d49 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -127,7 +127,7 @@ func (b Builder) Count() int32 { } func (b Builder) ServiceName() string { - return b.Logstash.Name + "-ls-http" + return b.Logstash.Name + "-ls-default" } func (b Builder) ListOptions() []client.ListOption { From de1fb22c4a5c2f8ca9e08c014ab7670610f0f42d Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 27 Feb 2023 14:35:06 -0500 Subject: [PATCH 071/160] Update comments to reflect change from HTTPConfig to LogstashService --- config/crds/v1/all-crds.yaml | 9 ++++----- .../v1/bases/logstash.k8s.elastic.co_logstashes.yaml | 9 ++++----- .../charts/eck-operator-crds/templates/all-crds.yaml | 9 ++++----- docs/reference/api-docs.asciidoc | 2 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 7 +++---- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 763fc4fdb8..7f291e0942 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9175,11 +9175,10 @@ spec: only be used if ECK is enforcing RBAC on references. type: string services: - description: 'HTTP holds the HTTP layer configuration for the Logstash - Metrics API TODO: This should likely be changed to a more general - `Services LogstashService[]`, where `LogstashService` looks a lot - like `HTTPConfig`, but is applicable for more than just an HTTP - endpoint, as logstash may need to be opened up for other services: + description: 'Services contains details of services that Logstash + should expose - similar to the HTTP layer configuration for the + rest of the stack, but also applicable for more use cases than the + metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs' items: properties: diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 9bc87dbbde..40d31eaf89 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -7538,11 +7538,10 @@ spec: only be used if ECK is enforcing RBAC on references. type: string services: - description: 'HTTP holds the HTTP layer configuration for the Logstash - Metrics API TODO: This should likely be changed to a more general - `Services LogstashService[]`, where `LogstashService` looks a lot - like `HTTPConfig`, but is applicable for more than just an HTTP - endpoint, as logstash may need to be opened up for other services: + description: 'Services contains details of services that Logstash + should expose - similar to the HTTP layer configuration for the + rest of the stack, but also applicable for more use cases than the + metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs' items: properties: diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index ddb0d02493..93d34492b1 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9229,11 +9229,10 @@ spec: only be used if ECK is enforcing RBAC on references. type: string services: - description: 'HTTP holds the HTTP layer configuration for the Logstash - Metrics API TODO: This should likely be changed to a more general - `Services LogstashService[]`, where `LogstashService` looks a lot - like `HTTPConfig`, but is applicable for more than just an HTTP - endpoint, as logstash may need to be opened up for other services: + description: 'Services contains details of services that Logstash + should expose - similar to the HTTP layer configuration for the + rest of the stack, but also applicable for more use cases than the + metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs' items: properties: diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 365e6b8e39..68c4b5b0fc 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1896,7 +1896,7 @@ LogstashSpec defines the desired state of Logstash | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. -| *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | HTTP holds the HTTP layer configuration for the Logstash Metrics API TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs +| *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 178bc6c876..417521dbc1 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -39,10 +39,9 @@ type LogstashSpec struct { // +kubebuilder:validation:Optional ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"` - // HTTP holds the HTTP layer configuration for the Logstash Metrics API - // TODO: This should likely be changed to a more general `Services LogstashService[]`, where `LogstashService` looks - // a lot like `HTTPConfig`, but is applicable for more than just an HTTP endpoint, as logstash may need to - // be opened up for other services: beats, TCP, UDP, etc, inputs + // Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the + // rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to + // be opened up for other services: beats, TCP, UDP, etc, inputs // +kubebuilder:validation:Optional Services []LogstashService `json:"services,omitempty"` From 41612f7b4d30d60d25ccf74fed22cd0d08468c10 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Mon, 27 Feb 2023 16:14:37 -0500 Subject: [PATCH 072/160] Update pkg/controller/logstash/service.go improve comment Co-authored-by: Peter Brachwitz --- pkg/controller/logstash/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go index ab1a8c761b..1c5e9911de 100644 --- a/pkg/controller/logstash/service.go +++ b/pkg/controller/logstash/service.go @@ -14,7 +14,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" ) -// reconcileServices reconcile Services defined in spec +// reconcileServices reconcile Services defined in the spec. // When Services are empty, a default Service for port 9600 is created. // If api.http.port is customized, user is expected to config Services. // When Services exist, the port 9600 does not attach to any of Service. From a0d176a1052e8b6367bc6ddea4a92483e71ee533 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 28 Feb 2023 14:23:32 +0000 Subject: [PATCH 073/160] remove duplicate err check --- pkg/controller/logstash/config.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index d437718244..c52bf50207 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -53,9 +53,6 @@ func buildConfig(params Params) ([]byte, error) { } cfg := defaultConfig() - if err != nil { - return nil, err - } // merge with user settings last so they take precedence if err := cfg.MergeWith(userProvidedCfg); err != nil { From b9610da97696d49d3a6267053322ffe2367614b9 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Tue, 28 Feb 2023 16:54:55 -0500 Subject: [PATCH 074/160] Add support for overriding "default" service This commit adds support to enable users to specify a `default` service to override the provided defaults. This commit also ensures that the `default` service is added if other services are defined --- pkg/controller/logstash/service.go | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go index 1c5e9911de..a5a61c8111 100644 --- a/pkg/controller/logstash/service.go +++ b/pkg/controller/logstash/service.go @@ -14,30 +14,34 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/network" ) -// reconcileServices reconcile Services defined in the spec. -// When Services are empty, a default Service for port 9600 is created. -// If api.http.port is customized, user is expected to config Services. -// When Services exist, the port 9600 does not attach to any of Service. +// reconcileServices reconcile Services defined in spec +// +// When a service is defined that matches the API service name, then that service is used to define +// the service for the logstash API. If not, then a default service is created for the API service func reconcileServices(params Params) ([]corev1.Service, error) { - if len(params.Logstash.Spec.Services) == 0 { - svc := newDefaultService(params.Logstash) - + createdApiService := false + + var svcs []corev1.Service + for _, service := range params.Logstash.Spec.Services { + var svc *corev1.Service + logstash := params.Logstash + if logstashv1alpha1.UserServiceName(logstash.Name, service.Name) == logstashv1alpha1.DefaultServiceName(logstash.Name) { + svc = newDefaultService(params.Logstash) + createdApiService = true + } else { + svc = newService(service, params.Logstash) + } if err := reconcileService(params, svc); err != nil { return []corev1.Service{}, err } - - return []corev1.Service{*svc}, nil + svcs = append(svcs, *svc) } - - svcs := make([]corev1.Service, len(params.Logstash.Spec.Services)) - for i, service := range params.Logstash.Spec.Services { - svc := newService(service, params.Logstash) - + if !createdApiService { + svc := newDefaultService(params.Logstash) if err := reconcileService(params, svc); err != nil { return []corev1.Service{}, err } - - svcs[i] = *svc + svcs = append(svcs, *svc) } return svcs, nil From 0c9409ab271227b08731b36d1d0ee8e634294364 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Tue, 28 Feb 2023 17:18:47 -0500 Subject: [PATCH 075/160] Replace 'default' service name with 'api' The default service represents the logstash API, so this commit updates the service name and associated methods to reflect that. This should also be more intuitive for users who wish to change the settings for the service. --- pkg/apis/logstash/v1alpha1/name.go | 10 +++++----- pkg/apis/logstash/v1alpha1/name_test.go | 6 +++--- pkg/controller/logstash/reconcile.go | 2 +- pkg/controller/logstash/service.go | 18 +++++++++--------- test/e2e/test/logstash/builder.go | 2 +- test/e2e/test/logstash/http_client.go | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go index a2a32d47ed..4ea4a789c4 100644 --- a/pkg/apis/logstash/v1alpha1/name.go +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -9,8 +9,8 @@ import ( ) const ( - defaultServiceSuffix = "default" - configSuffix = "config" + apiServiceSuffix = "api" + configSuffix = "config" ) // Namer is a Namer that is configured with the defaults for resources related to a Logstash resource. @@ -30,9 +30,9 @@ func Name(name string) string { return Namer.Suffix(name) } -// DefaultServiceName returns the name of the HTTP service for a given Logstash name. -func DefaultServiceName(name string) string { - return Namer.Suffix(name, defaultServiceSuffix) +// APIServiceName returns the name of the HTTP service for a given Logstash name. +func APIServiceName(name string) string { + return Namer.Suffix(name, apiServiceSuffix) } func UserServiceName(deployName string, name string) string { diff --git a/pkg/apis/logstash/v1alpha1/name_test.go b/pkg/apis/logstash/v1alpha1/name_test.go index a7704be84d..21f767af22 100644 --- a/pkg/apis/logstash/v1alpha1/name_test.go +++ b/pkg/apis/logstash/v1alpha1/name_test.go @@ -8,7 +8,7 @@ import ( "testing" ) -func TestDefaultService(t *testing.T) { +func TestAPIService(t *testing.T) { type args struct { logstashName string } @@ -20,12 +20,12 @@ func TestDefaultService(t *testing.T) { { name: "sample", args: args{logstashName: "sample"}, - want: "sample-ls-default", + want: "sample-ls-api", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := DefaultServiceName(tt.args.logstashName); got != tt.want { + if got := APIServiceName(tt.args.logstashName); got != tt.want { t.Errorf("DefaultService() = %v, want %v", got, tt.want) } }) diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go index c21e8a3d3c..89819f13c8 100644 --- a/pkg/controller/logstash/reconcile.go +++ b/pkg/controller/logstash/reconcile.go @@ -31,7 +31,7 @@ func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*r s := sset.New(sset.Params{ Name: logstashv1alpha1.Name(params.Logstash.Name), Namespace: params.Logstash.Namespace, - ServiceName: logstashv1alpha1.DefaultServiceName(params.Logstash.Name), + ServiceName: logstashv1alpha1.APIServiceName(params.Logstash.Name), Selector: params.Logstash.GetIdentityLabels(), Labels: params.Logstash.GetIdentityLabels(), PodTemplateSpec: podTemplate, diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go index a5a61c8111..b72b7ea85f 100644 --- a/pkg/controller/logstash/service.go +++ b/pkg/controller/logstash/service.go @@ -19,15 +19,15 @@ import ( // When a service is defined that matches the API service name, then that service is used to define // the service for the logstash API. If not, then a default service is created for the API service func reconcileServices(params Params) ([]corev1.Service, error) { - createdApiService := false + createdAPIService := false - var svcs []corev1.Service + svcs := make([]corev1.Service, 0) for _, service := range params.Logstash.Spec.Services { var svc *corev1.Service logstash := params.Logstash - if logstashv1alpha1.UserServiceName(logstash.Name, service.Name) == logstashv1alpha1.DefaultServiceName(logstash.Name) { - svc = newDefaultService(params.Logstash) - createdApiService = true + if logstashv1alpha1.UserServiceName(logstash.Name, service.Name) == logstashv1alpha1.APIServiceName(logstash.Name) { + svc = newAPIService(params.Logstash) + createdAPIService = true } else { svc = newService(service, params.Logstash) } @@ -36,8 +36,8 @@ func reconcileServices(params Params) ([]corev1.Service, error) { } svcs = append(svcs, *svc) } - if !createdApiService { - svc := newDefaultService(params.Logstash) + if !createdAPIService { + svc := newAPIService(params.Logstash) if err := reconcileService(params, svc); err != nil { return []corev1.Service{}, err } @@ -75,14 +75,14 @@ func newService(service logstashv1alpha1.LogstashService, logstash logstashv1alp return &svc } -func newDefaultService(logstash logstashv1alpha1.Logstash) *corev1.Service { +func newAPIService(logstash logstashv1alpha1.Logstash) *corev1.Service { svc := corev1.Service{ ObjectMeta: metav1.ObjectMeta{}, Spec: corev1.ServiceSpec{ClusterIP: "None"}, } svc.ObjectMeta.Namespace = logstash.Namespace - svc.ObjectMeta.Name = logstashv1alpha1.DefaultServiceName(logstash.Name) + svc.ObjectMeta.Name = logstashv1alpha1.APIServiceName(logstash.Name) labels := NewLabels(logstash) ports := []corev1.ServicePort{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 0aead87d49..2e7385f2d7 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -127,7 +127,7 @@ func (b Builder) Count() int32 { } func (b Builder) ServiceName() string { - return b.Logstash.Name + "-ls-default" + return b.Logstash.Name + "-ls-api" } func (b Builder) ListOptions() []client.ListOption { diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go index 8c0235a164..b9456d0153 100644 --- a/test/e2e/test/logstash/http_client.go +++ b/test/e2e/test/logstash/http_client.go @@ -33,7 +33,7 @@ func NewLogstashClient(logstash v1alpha1.Logstash, k *test.K8sClient) (*http.Cli func DoRequest(client *http.Client, logstash v1alpha1.Logstash, method, path string) ([]byte, error) { scheme := "http" - url, err := url.Parse(fmt.Sprintf("%s://%s.%s.svc:9600%s", scheme, v1alpha1.DefaultServiceName(logstash.Name), logstash.Namespace, path)) + url, err := url.Parse(fmt.Sprintf("%s://%s.%s.svc:9600%s", scheme, v1alpha1.APIServiceName(logstash.Name), logstash.Namespace, path)) if err != nil { return nil, fmt.Errorf("while parsing URL: %w", err) } From 6167cb7dc7531886355bcf2fcffe686bbbeb2132 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Tue, 28 Feb 2023 18:27:00 -0500 Subject: [PATCH 076/160] merge from feature/logstash --- hack/upgrade-test-harness/go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hack/upgrade-test-harness/go.sum b/hack/upgrade-test-harness/go.sum index 3e5bb00679..7c0c373f72 100644 --- a/hack/upgrade-test-harness/go.sum +++ b/hack/upgrade-test-harness/go.sum @@ -629,6 +629,8 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= From 30aa37b3de1366bf9eb0a525352543cccbb50ed8 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 1 Mar 2023 12:49:13 +0000 Subject: [PATCH 077/160] remove irrelevant es ref --- .../association/controller/logstash_es.go | 54 ------------------- pkg/controller/logstash/stackmon/sidecar.go | 1 + 2 files changed, 1 insertion(+), 54 deletions(-) diff --git a/pkg/controller/association/controller/logstash_es.go b/pkg/controller/association/controller/logstash_es.go index a4d0cdc704..6a79976b29 100644 --- a/pkg/controller/association/controller/logstash_es.go +++ b/pkg/controller/association/controller/logstash_es.go @@ -4,23 +4,6 @@ package controller -import ( - "strings" - - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/manager" - - commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" - esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" - logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/association" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator" - eslabel "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/v2/pkg/utils/rbac" -) - const ( // LogstashAssociationLabelName marks resources created for an association originating from Logstash with the // Logstash name. @@ -31,41 +14,4 @@ const ( // LogstashAssociationLabelType marks resources created for an association originating from Logstash // with the target resource type (e.g. "elasticsearch"). LogstashAssociationLabelType = "logstashassociation.k8s.elastic.co/type" - // LogstashSystemUserBuiltinRole is the name of the built-in role for the Logstash system user. - LogstashSystemUserBuiltinRole = "logstash_system" - // LogstashAdminUserBuiltinRole is the name of the built-in role for the Logstash admin user. - LogstashAdminUserBuiltinRole = "logstash_admin" ) - -func AddLogstashES(mgr manager.Manager, accessReviewer rbac.AccessReviewer, params operator.Parameters) error { - return association.AddAssociationController(mgr, accessReviewer, params, association.AssociationInfo{ - AssociationType: commonv1.ElasticsearchAssociationType, - AssociatedObjTemplate: func() commonv1.Associated { return &logstashv1alpha1.Logstash{} }, - ReferencedObjTemplate: func() client.Object { return &esv1.Elasticsearch{} }, - ReferencedResourceVersion: referencedElasticsearchStatusVersion, - ExternalServiceURL: getElasticsearchExternalURL, - ReferencedResourceNamer: esv1.ESNamer, - AssociationName: "logstash-es", - AssociatedShortName: "logstash", - Labels: func(associated types.NamespacedName) map[string]string { - return map[string]string{ - LogstashAssociationLabelName: associated.Name, - LogstashAssociationLabelNamespace: associated.Namespace, - LogstashAssociationLabelType: commonv1.ElasticsearchAssociationType, - } - }, - AssociationConfAnnotationNameBase: commonv1.ElasticsearchConfigAnnotationNameBase, - AssociationResourceNameLabelName: eslabel.ClusterNameLabelName, - AssociationResourceNamespaceLabelName: eslabel.ClusterNamespaceLabelName, - - ElasticsearchUserCreation: &association.ElasticsearchUserCreation{ - ElasticsearchRef: func(c k8s.Client, association commonv1.Association) (bool, commonv1.ObjectSelector, error) { - return true, association.AssociationRef(), nil - }, - UserSecretSuffix: "logstash-user", - ESUserRole: func(associated commonv1.Associated) (string, error) { - return strings.Join([]string{LogstashAdminUserBuiltinRole, LogstashSystemUserBuiltinRole}, ","), nil - }, - }, - }) -} diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go index 05a31b34f2..c34dafe6bf 100644 --- a/pkg/controller/logstash/stackmon/sidecar.go +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -39,6 +39,7 @@ func Metricbeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha metricbeatConfigTemplate, logstashv1alpha1.Namer, fmt.Sprintf("%s://localhost:%d", "http" /*logstash.Spec.HTTP.Protocol()*/, network.HTTPPort), + //TODO: integrate username password with Logstash metrics API "", /* no username for metrics API */ "", /* no password for metrics API */ false, From d4c5e05300da145d182d075947914a603a36ef06 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Wed, 1 Mar 2023 19:15:28 -0500 Subject: [PATCH 078/160] Add tests and checks for services and endpoints --- config/samples/logstash/logstash_svc.yaml | 12 ++-- pkg/controller/logstash/config.go | 2 +- test/e2e/logstash/logstash_test.go | 73 +++++++++++++++++++++++ test/e2e/test/logstash/builder.go | 17 ++++-- test/e2e/test/logstash/checks.go | 60 +++++++++++++++++++ test/e2e/test/logstash/steps.go | 4 +- 6 files changed, 155 insertions(+), 13 deletions(-) diff --git a/config/samples/logstash/logstash_svc.yaml b/config/samples/logstash/logstash_svc.yaml index 90b432dbc9..410caae8d3 100644 --- a/config/samples/logstash/logstash_svc.yaml +++ b/config/samples/logstash/logstash_svc.yaml @@ -15,20 +15,20 @@ kind: Logstash metadata: name: logstash-sample spec: - count: 3 + count: 2 version: 8.6.1 config: log.level: info api.http.host: "0.0.0.0" queue.type: memory services: - - name: metrics + - name: api service: spec: type: ClusterIP ports: - port: 9600 - name: "stats" + name: "api" protocol: TCP targetPort: 9600 - name: beats @@ -37,6 +37,10 @@ spec: type: ClusterIP ports: - port: 5044 - name: "beats" + name: "filebeat" protocol: TCP targetPort: 5044 + - port: 5045 + name: "winlogbeat" + protocol: TCP + targetPort: 5045 diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index c52bf50207..5a0409dbb6 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -73,7 +73,7 @@ func getUserConfig(params Params) (*settings.CanonicalConfig, error) { func defaultConfig() *settings.CanonicalConfig { settingsMap := map[string]interface{}{ - // Set 'api.http.host' by defaut to `0.0.0.0` for readiness probe to work. + // Set 'api.http.host' by default to `0.0.0.0` for readiness probe to work. "api.http.host": "0.0.0.0", } diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go index 96c8cd93ce..573af6b5f6 100644 --- a/test/e2e/logstash/logstash_test.go +++ b/test/e2e/logstash/logstash_test.go @@ -9,6 +9,9 @@ package logstash import ( "testing" + corev1 "k8s.io/api/core/v1" + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" ) @@ -20,6 +23,76 @@ func TestSingleLogstash(t *testing.T) { test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) } +func TestLogstashWithCustomService(t *testing.T) { + name := "test-multiple-custom-logstash" + service := logstashv1alpha1.LogstashService { + Name: "test", + Service: commonv1.ServiceTemplate{ + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + {Port: 9200}, + }, + }, + }, + } + logstashBuilder := (logstash.NewBuilder(name). + WithNodeCount(1). + WithServices(service)) + + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + +func TestLogstashWithReworkedApiService(t *testing.T) { + name := "test-multiple-custom-logstash" + service := logstashv1alpha1.LogstashService { + Name: "api", + Service: commonv1.ServiceTemplate{ + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + {Port: 9200}, + }, + }, + }, + } + logstashBuilder := (logstash.NewBuilder(name). + WithNodeCount(1). + WithServices(service)) + + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + +func TestLogstashWithCustomServiceAndAmendedApi(t *testing.T) { + name := "test-multiple-custom-logstash" + customService := logstashv1alpha1.LogstashService { + Name: "test", + Service: commonv1.ServiceTemplate{ + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + {Port: 9200}, + }, + }, + }, + } + + apiService := logstashv1alpha1.LogstashService { + Name: "api", + Service: commonv1.ServiceTemplate{ + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + {Port: 9601}, + }, + }, + }, + } + + logstashBuilder := (logstash.NewBuilder(name). + WithNodeCount(1). + WithServices(apiService, customService)) + + test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) +} + + func TestMultipleLogstashes(t *testing.T) { name := "test-multiple-logstashes" logstashBuilder := logstash.NewBuilder(name). diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 2e7385f2d7..053253a1b6 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/util/rand" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" @@ -18,7 +18,7 @@ import ( ) type Builder struct { - Logstash v1alpha1.Logstash + Logstash logstashv1alpha1.Logstash MutatedFrom *Builder } @@ -35,11 +35,11 @@ func newBuilder(name, randSuffix string) Builder { Name: name, Namespace: test.Ctx().ManagedNamespace(0), } - def := test.Ctx().ImageDefinitionFor(v1alpha1.Kind) + def := test.Ctx().ImageDefinitionFor(logstashv1alpha1.Kind) return Builder{ - Logstash: v1alpha1.Logstash{ + Logstash: logstashv1alpha1.Logstash{ ObjectMeta: meta, - Spec: v1alpha1.LogstashSpec{ + Spec: logstashv1alpha1.LogstashSpec{ Count: 1, Version: def.Version, }, @@ -110,12 +110,17 @@ func (b Builder) WithMutatedFrom(mutatedFrom *Builder) Builder { return b } +func (b Builder) WithServices(services ...logstashv1alpha1.LogstashService) Builder { + b.Logstash.Spec.Services = append(b.Logstash.Spec.Services, services...) + return b +} + func (b Builder) NSN() types.NamespacedName { return k8s.ExtractNamespacedName(&b.Logstash) } func (b Builder) Kind() string { - return v1alpha1.Kind + return logstashv1alpha1.Kind } func (b Builder) Spec() interface{} { diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index e98540c6fc..490a55394c 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -9,6 +9,8 @@ import ( "encoding/json" "fmt" + corev1 "k8s.io/api/core/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -89,3 +91,61 @@ func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { }, } } + +func CheckServices(b Builder, k *test.K8sClient) test.Step { + return test.Step{ + Name: "Logstash services should be created", + Test: test.Eventually(func() error { + serviceNames := map[string]struct{}{} + serviceNames[logstashv1alpha1.APIServiceName(b.Logstash.Name)] = struct{}{} + for _, r := range b.Logstash.Spec.Services { + serviceNames[logstashv1alpha1.UserServiceName(b.Logstash.Name, r.Name)] = struct{}{} + } + for serviceName := range serviceNames { + svc, err := k.GetService(b.Logstash.Namespace, serviceName) + if err != nil { + return err + } + if svc.Spec.Type == corev1.ServiceTypeLoadBalancer { + if len(svc.Status.LoadBalancer.Ingress) == 0 { + return fmt.Errorf("load balancer for %s not ready yet", svc.Name) + } + } + } + return nil + }), + } +} + +// CheckServicesEndpoints checks that services have the expected number of endpoints +func CheckServicesEndpoints(b Builder, k *test.K8sClient) test.Step { + return test.Step{ + Name: "Logstash services should have endpoints", + Test: test.Eventually(func() error { + servicePorts := make(map[string]int32) + servicePorts[logstashv1alpha1.APIServiceName(b.Logstash.Name)] = b.Logstash.Spec.Count + for _, r := range b.Logstash.Spec.Services { + portsPerService := int32(len(r.Service.Spec.Ports)) + servicePorts[logstashv1alpha1.UserServiceName(b.Logstash.Name, r.Name)] = b.Logstash.Spec.Count * portsPerService + } + + for endpointName, addrPortCount := range servicePorts { + if addrPortCount == 0 { + continue + } + endpoints, err := k.GetEndpoints(b.Logstash.Namespace, endpointName) + if err != nil { + return err + } + if len(endpoints.Subsets) == 0 { + return fmt.Errorf("no subset for endpoint %s", endpointName) + } + if int32(len(endpoints.Subsets[0].Addresses)*len(endpoints.Subsets[0].Ports)) != addrPortCount { + return fmt.Errorf("%d addresses and %d ports found for endpoint %s, expected %d", len(endpoints.Subsets[0].Addresses), + len(endpoints.Subsets[0].Ports), endpointName, addrPortCount) + } + } + return nil + }), + } +} diff --git a/test/e2e/test/logstash/steps.go b/test/e2e/test/logstash/steps.go index a9a324a621..e1fc34976a 100644 --- a/test/e2e/test/logstash/steps.go +++ b/test/e2e/test/logstash/steps.go @@ -84,8 +84,8 @@ func (b Builder) CheckK8sTestSteps(k *test.K8sClient) test.StepList { return test.StepList{ CheckSecrets(b, k), CheckStatus(b, k), - checks.CheckServices(b, k), - checks.CheckServicesEndpoints(b, k), + CheckServices(b, k), + CheckServicesEndpoints(b, k), checks.CheckPods(b, k), } } From 044b2c9759f7a5772e54195f4db5458e9e95b19f Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 2 Mar 2023 12:07:13 +0000 Subject: [PATCH 079/160] add issues to track log monitoring --- test/e2e/logstash/stack_monitoring_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 729674e264..676d3eb15c 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -33,6 +33,7 @@ func TestLogstashStackMonitoring(t *testing.T) { WithNodeCount(1). WithMonitoring(metrics.Ref(), logs.Ref()). //TODO: remove command when Logstash has built with a monitor version of log4j2.properties + // https://github.com/elastic/logstash/issues/14941 WithCommand([]string{"sh", "-c", "curl -o 'log4j2.properties' 'https://raw.githubusercontent.com/elastic/logstash/main/config/log4j2.properties' && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint"}) // checks that the sidecar beats have sent data in the monitoring clusters From 7e38109561aaad8d79ac75e36bb9c3da864eb403 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 2 Mar 2023 12:55:44 +0000 Subject: [PATCH 080/160] add env LOG_STYLE for log monitoring --- pkg/controller/logstash/stackmon/ls_config.go | 14 ++++++++++++++ pkg/controller/logstash/stackmon/sidecar.go | 3 +++ pkg/controller/logstash/stackmon/sidecar_test.go | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 pkg/controller/logstash/stackmon/ls_config.go diff --git a/pkg/controller/logstash/stackmon/ls_config.go b/pkg/controller/logstash/stackmon/ls_config.go new file mode 100644 index 0000000000..bd8f9c096e --- /dev/null +++ b/pkg/controller/logstash/stackmon/ls_config.go @@ -0,0 +1,14 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package stackmon + +import ( + corev1 "k8s.io/api/core/v1" +) + +// fileLogStyleEnvVar returns the environment variable to configure the Logstash container to write logs to disk +func fileLogStyleEnvVar() corev1.EnvVar { + return corev1.EnvVar{Name: "LOG_STYLE", Value: "file"} +} diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go index c34dafe6bf..5e6adf01b8 100644 --- a/pkg/controller/logstash/stackmon/sidecar.go +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -80,6 +80,9 @@ func WithMonitoring(ctx context.Context, client k8s.Client, builder *defaults.Po } if monitoring.IsLogsDefined(&logstash) { + // enable Stack logging to write Logstash logs to disk + builder.WithEnv(fileLogStyleEnvVar()) + b, err := Filebeat(ctx, client, logstash) if err != nil { return nil, err diff --git a/pkg/controller/logstash/stackmon/sidecar_test.go b/pkg/controller/logstash/stackmon/sidecar_test.go index 7bb9e35cd6..627486e106 100644 --- a/pkg/controller/logstash/stackmon/sidecar_test.go +++ b/pkg/controller/logstash/stackmon/sidecar_test.go @@ -78,6 +78,7 @@ func TestWithMonitoring(t *testing.T) { name string ls func() logstashv1alpha1.Logstash containersLength int + esEnvVarsLength int podVolumesLength int metricsVolumeMountsLength int logVolumeMountsLength int @@ -97,6 +98,7 @@ func TestWithMonitoring(t *testing.T) { return sampleLs }, containersLength: 2, + esEnvVarsLength: 0, podVolumesLength: 2, metricsVolumeMountsLength: 2, }, @@ -109,6 +111,7 @@ func TestWithMonitoring(t *testing.T) { return sampleLs }, containersLength: 2, + esEnvVarsLength: 1, podVolumesLength: 3, logVolumeMountsLength: 3, }, @@ -122,6 +125,7 @@ func TestWithMonitoring(t *testing.T) { return sampleLs }, containersLength: 3, + esEnvVarsLength: 1, podVolumesLength: 4, metricsVolumeMountsLength: 2, logVolumeMountsLength: 3, @@ -136,6 +140,7 @@ func TestWithMonitoring(t *testing.T) { return sampleLs }, containersLength: 3, + esEnvVarsLength: 1, podVolumesLength: 5, metricsVolumeMountsLength: 2, logVolumeMountsLength: 3, From 1f774305fdfbdcbd93b6a020a0dcff6aed360f3b Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 2 Mar 2023 09:08:59 -0500 Subject: [PATCH 081/160] Update pkg/apis/logstash/v1alpha1/webhook.go Co-authored-by: Michael Morello --- pkg/apis/logstash/v1alpha1/webhook.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go index 3945b05be7..7b7c564f20 100644 --- a/pkg/apis/logstash/v1alpha1/webhook.go +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -32,9 +32,9 @@ var _ webhook.Validator = &Logstash{} // ValidateCreate is called by the validating webhook to validate the create operation. // Satisfies the webhook.Validator interface. -func (a *Logstash) ValidateCreate() error { - validationLog.V(1).Info("Validate create", "name", a.Name) - return a.validate(nil) +func (l *Logstash) ValidateCreate() error { + validationLog.V(1).Info("Validate create", "name", l.Name) + return l.validate(nil) } // ValidateDelete is called by the validating webhook to validate the delete operation. From b677c65918445e2eee8f2a7d7084c67d7ae776e5 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 2 Mar 2023 09:16:47 -0500 Subject: [PATCH 082/160] Update pkg/controller/logstash/service.go Co-authored-by: Michael Morello --- pkg/controller/logstash/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go index b72b7ea85f..7348e7970e 100644 --- a/pkg/controller/logstash/service.go +++ b/pkg/controller/logstash/service.go @@ -21,7 +21,7 @@ import ( func reconcileServices(params Params) ([]corev1.Service, error) { createdAPIService := false - svcs := make([]corev1.Service, 0) + svcs := make([]corev1.Service, 0, len(params.Logstash.Spec.Services)+1) for _, service := range params.Logstash.Spec.Services { var svc *corev1.Service logstash := params.Logstash From a797940f531b85dd04eefc37f507dc8e3a5a4fee Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 2 Mar 2023 11:28:51 -0500 Subject: [PATCH 083/160] Addressing code review comments --- config/samples/logstash/logstash.yaml | 12 ------------ hack/operatorhub/templates/csv.tpl | 13 ++++++++++++- pkg/apis/logstash/v1alpha1/name.go | 4 ---- pkg/apis/logstash/v1alpha1/name_test.go | 26 +------------------------ pkg/apis/logstash/v1alpha1/webhook.go | 20 +++++++++---------- pkg/controller/logstash/reconcile.go | 6 +++--- 6 files changed, 26 insertions(+), 55 deletions(-) diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml index e924b4a5b6..850dd41d9c 100644 --- a/config/samples/logstash/logstash.yaml +++ b/config/samples/logstash/logstash.yaml @@ -1,15 +1,3 @@ -apiVersion: elasticsearch.k8s.elastic.co/v1 -kind: Elasticsearch -metadata: - name: elasticsearch-sample -spec: - version: 8.6.1 - nodeSets: - - name: default - count: 3 - config: - node.store.allow_mmap: false ---- apiVersion: logstash.k8s.elastic.co/v1alpha1 kind: Logstash metadata: diff --git a/hack/operatorhub/templates/csv.tpl b/hack/operatorhub/templates/csv.tpl index ada5f27a84..2225ae6d41 100644 --- a/hack/operatorhub/templates/csv.tpl +++ b/hack/operatorhub/templates/csv.tpl @@ -7,7 +7,7 @@ metadata: certified: 'false' containerImage: {{ .OperatorRepo }}{{ .Tag }} createdAt: {{ now | date "2006-01-02 15:04:05" }} - description: Run Elasticsearch, Kibana, APM Server, Beats, Enterprise Search, Elastic Agent and Elastic Maps Server on Kubernetes and OpenShift + description: Run Elasticsearch, Kibana, APM Server, Beats, Enterprise Search, Elastic Agent, Elastic Maps Server and Logstash on Kubernetes and OpenShift repository: https://github.com/elastic/cloud-on-k8s support: elastic.co alm-examples: |- @@ -226,6 +226,17 @@ metadata: "name": "elasticsearch-sample" } } + }, + { + "apiVersion": "logstash.k8s.elastic.co/v1alpha1", + "kind": "Logstash", + "metadata" : { + "name": "logstash-sample" + }, + "spec": { + "version": "{{ .StackVersion }}", + "count": 1 + } } ] name: {{ .PackageName }}.v{{ .NewVersion }} diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go index 4ea4a789c4..88c56cd9ea 100644 --- a/pkg/apis/logstash/v1alpha1/name.go +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -21,10 +21,6 @@ func ConfigSecretName(name string) string { return Namer.Suffix(name, configSuffix) } -func ConfigMapName(name string) string { - return Namer.Suffix(name, "configmap") -} - // Name returns the name of Logstash. func Name(name string) string { return Namer.Suffix(name) diff --git a/pkg/apis/logstash/v1alpha1/name_test.go b/pkg/apis/logstash/v1alpha1/name_test.go index 21f767af22..2ea1267e34 100644 --- a/pkg/apis/logstash/v1alpha1/name_test.go +++ b/pkg/apis/logstash/v1alpha1/name_test.go @@ -78,28 +78,4 @@ func TestLogstashName(t *testing.T) { } }) } -} - -func TestConfigMapName(t *testing.T) { - type args struct { - logstashName string - } - tests := []struct { - name string - args args - want string - }{ - { - name: "sample", - args: args{logstashName: "sample"}, - want: "sample-ls-configmap", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := ConfigMapName(tt.args.logstashName); got != tt.want { - t.Errorf("ConfigMap() = %v, want %v", got, tt.want) - } - }) - } -} +} \ No newline at end of file diff --git a/pkg/apis/logstash/v1alpha1/webhook.go b/pkg/apis/logstash/v1alpha1/webhook.go index 7b7c564f20..e01092d610 100644 --- a/pkg/apis/logstash/v1alpha1/webhook.go +++ b/pkg/apis/logstash/v1alpha1/webhook.go @@ -39,46 +39,46 @@ func (l *Logstash) ValidateCreate() error { // ValidateDelete is called by the validating webhook to validate the delete operation. // Satisfies the webhook.Validator interface. -func (a *Logstash) ValidateDelete() error { - validationLog.V(1).Info("Validate delete", "name", a.Name) +func (l *Logstash) ValidateDelete() error { + validationLog.V(1).Info("Validate delete", "name", l.Name) return nil } // ValidateUpdate is called by the validating webhook to validate the update operation. // Satisfies the webhook.Validator interface. -func (a *Logstash) ValidateUpdate(old runtime.Object) error { - validationLog.V(1).Info("Validate update", "name", a.Name) +func (l *Logstash) ValidateUpdate(old runtime.Object) error { + validationLog.V(1).Info("Validate update", "name", l.Name) oldObj, ok := old.(*Logstash) if !ok { return errors.New("cannot cast old object to Logstash type") } - return a.validate(oldObj) + return l.validate(oldObj) } // WebhookPath returns the HTTP path used by the validating webhook. -func (a *Logstash) WebhookPath() string { +func (l *Logstash) WebhookPath() string { return webhookPath } -func (a *Logstash) validate(old *Logstash) error { +func (l *Logstash) validate(old *Logstash) error { var errors field.ErrorList if old != nil { for _, uc := range updateChecks { - if err := uc(old, a); err != nil { + if err := uc(old, l); err != nil { errors = append(errors, err...) } } } for _, dc := range defaultChecks { - if err := dc(a); err != nil { + if err := dc(l); err != nil { errors = append(errors, err...) } } if len(errors) > 0 { - return apierrors.NewInvalid(groupKind, a.Name, errors) + return apierrors.NewInvalid(groupKind, l.Name, errors) } return nil } diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go index 89819f13c8..e4521a83a2 100644 --- a/pkg/controller/logstash/reconcile.go +++ b/pkg/controller/logstash/reconcile.go @@ -48,11 +48,11 @@ func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*r } var status logstashv1alpha1.LogstashStatus + if status, err = calculateStatus(¶ms, reconciled.Status.ReadyReplicas, reconciled.Status.Replicas); err != nil { - err = errors.Wrap(err, "while calculating status") + results.WithError(errors.Wrap(err, "while calculating status")) } - - return results.WithError(err), status + return results, status } // calculateStatus will calculate a new status from the state of the pods within the k8s cluster From 315a803e5ef3c9967531dba6687d0cde946a2bbe Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 28 Feb 2023 14:21:45 +0000 Subject: [PATCH 084/160] add pipeline config and unit test # Conflicts: # pkg/apis/logstash/v1alpha1/name.go --- config/crds/v1/all-crds.yaml | 19 ++ .../logstash.k8s.elastic.co_logstashes.yaml | 19 ++ .../samples/logstash/logstash_pipeline.yaml | 30 ++ .../eck-operator-crds/templates/all-crds.yaml | 19 ++ docs/reference/api-docs.asciidoc | 13 + pkg/apis/logstash/v1alpha1/logstash_types.go | 11 + pkg/apis/logstash/v1alpha1/name.go | 5 + .../v1alpha1/zz_generated.deepcopy.go | 18 ++ pkg/controller/logstash/driver.go | 4 + pkg/controller/logstash/pipeline.go | 79 ++++++ pkg/controller/logstash/pipeline_test.go | 130 +++++++++ pkg/controller/logstash/pipelines_config.go | 154 ++++++++++ .../logstash/pipelines_config_test.go | 263 ++++++++++++++++++ .../logstash/pipelines_configref.go | 75 +++++ .../logstash/pipelines_configref_test.go | 191 +++++++++++++ pkg/controller/logstash/pod.go | 10 + 16 files changed, 1040 insertions(+) create mode 100644 config/samples/logstash/logstash_pipeline.yaml create mode 100644 pkg/controller/logstash/pipeline.go create mode 100644 pkg/controller/logstash/pipeline_test.go create mode 100644 pkg/controller/logstash/pipelines_config.go create mode 100644 pkg/controller/logstash/pipelines_config_test.go create mode 100644 pkg/controller/logstash/pipelines_configref.go create mode 100644 pkg/controller/logstash/pipelines_configref_test.go diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 7f291e0942..72f48a8906 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9121,6 +9121,25 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + additionalProperties: + type: string + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 40d31eaf89..229b4b2393 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -77,6 +77,25 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + additionalProperties: + type: string + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. diff --git a/config/samples/logstash/logstash_pipeline.yaml b/config/samples/logstash/logstash_pipeline.yaml new file mode 100644 index 0000000000..9b82b15434 --- /dev/null +++ b/config/samples/logstash/logstash_pipeline.yaml @@ -0,0 +1,30 @@ +apiVersion: elasticsearch.k8s.elastic.co/v1 +kind: Elasticsearch +metadata: + name: elasticsearch-sample +spec: + version: 8.6.1 + nodeSets: + - name: default + count: 1 + config: + node.store.allow_mmap: false +--- +apiVersion: logstash.k8s.elastic.co/v1alpha1 +kind: Logstash +metadata: + name: logstash-sample +spec: + count: 1 + version: 8.6.1 + config: + log.level: info + api.http.host: "0.0.0.0" + queue.type: memory + pipelines: + - pipeline.id: main + config.string: input { exec { command => 'uptime' interval => 10 } } output { stdout{} } + podTemplate: + spec: + containers: + - name: logstash \ No newline at end of file diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 93d34492b1..4339601682 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9175,6 +9175,25 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + additionalProperties: + type: string + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 68c4b5b0fc..a90f42fa14 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1896,6 +1896,7 @@ LogstashSpec defines the desired state of Logstash | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. +| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelineRef`] can be specified. | *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. @@ -1924,6 +1925,18 @@ LogstashStatus defines the observed state of Logstash |=== +[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-pipeline"] +=== Pipeline + + + +.Appears In: +**** +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] +**** + + + [id="{anchor_prefix}-maps-k8s-elastic-co-v1alpha1"] == maps.k8s.elastic.co/v1alpha1 diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 417521dbc1..39fd1c679f 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -39,6 +39,17 @@ type LogstashSpec struct { // +kubebuilder:validation:Optional ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"` + // Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. + // +kubebuilder:validation:Optional + // +kubebuilder:pruning:PreserveUnknownFields + Pipelines []map[string]string `json:"pipelines,omitempty"` + + // PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. + // Logstash pipelines must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] + // can be specified. + // +kubebuilder:validation:Optional + PipelinesRef *commonv1.ConfigSource `json:"pipelinesRef,omitempty"` + // Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the // rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to // be opened up for other services: beats, TCP, UDP, etc, inputs diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go index 88c56cd9ea..dcee068c2e 100644 --- a/pkg/apis/logstash/v1alpha1/name.go +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -11,6 +11,7 @@ import ( const ( apiServiceSuffix = "api" configSuffix = "config" + pipelineSuffix = "pipeline" ) // Namer is a Namer that is configured with the defaults for resources related to a Logstash resource. @@ -34,3 +35,7 @@ func APIServiceName(name string) string { func UserServiceName(deployName string, name string) string { return Namer.Suffix(deployName, name) } + +func PipelineSecretName(name string) string { + return Namer.Suffix(name, pipelineSuffix) +} \ No newline at end of file diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index e4863e0454..e3537aa39e 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -102,6 +102,24 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { *out = new(v1.ConfigSource) **out = **in } + if in.Pipelines != nil { + in, out := &in.Pipelines, &out.Pipelines + *out = make([]map[string]string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + } + } + if in.PipelinesRef != nil { + in, out := &in.PipelinesRef, &out.PipelinesRef + *out = new(v1.ConfigSource) + **out = **in + } if in.Services != nil { in, out := &in.Services, &out.Services *out = make([]LogstashService, len(*in)) diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 144b7a9711..cb1c654f79 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -82,6 +82,10 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log return results.WithError(err), params.Status } + if err := reconcilePipeline(params, configHash); err != nil { + return results.WithError(err), params.Status + } + podTemplate := buildPodTemplate(params, configHash) return reconcileStatefulSet(params, podTemplate) } diff --git a/pkg/controller/logstash/pipeline.go b/pkg/controller/logstash/pipeline.go new file mode 100644 index 0000000000..da78be90ca --- /dev/null +++ b/pkg/controller/logstash/pipeline.go @@ -0,0 +1,79 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "hash" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" +) + +func reconcilePipeline(params Params, configHash hash.Hash) error { + defer tracing.Span(¶ms.Context)() + + cfgBytes, err := buildPipeline(params) + if err != nil { + return err + } + + expected := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: params.Logstash.Namespace, + Name: logstashv1alpha1.PipelineSecretName(params.Logstash.Name), + Labels: labels.AddCredentialsLabel(NewLabels(params.Logstash)), + }, + Data: map[string][]byte{ + PipelineFileName: cfgBytes, + }, + } + + if _, err = reconciler.ReconcileSecret(params.Context, params.Client, expected, ¶ms.Logstash); err != nil { + return err + } + + _, _ = configHash.Write(cfgBytes) + + return nil +} + +func buildPipeline(params Params) ([]byte, error) { + userProvidedCfg, err := getUserPipeline(params) + if err != nil { + return nil, err + } + + if userProvidedCfg != nil { + return userProvidedCfg.Render() + } + + cfg := defaultPipeline() + return cfg.Render() +} + +// getUserPipeline extracts the pipeline either from the spec `pipeline` field or from the Secret referenced by spec +// `pipelineRef` field. +func getUserPipeline(params Params) (*PipelinesConfig, error) { + if params.Logstash.Spec.Pipelines != nil { + return NewPipelinesConfigFrom(params.Logstash.Spec.Pipelines) + } + return ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) +} + +func defaultPipeline() *PipelinesConfig { + pipelines := []map[string]string{ + { + "pipeline.id": "demo", + "config.string": "input { exec { command => \"uptime\" interval => 5 } } output { stdout{} }", + }, + } + + return MustPipelinesConfig(pipelines) +} diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go new file mode 100644 index 0000000000..aa71aa4d8d --- /dev/null +++ b/pkg/controller/logstash/pipeline_test.go @@ -0,0 +1,130 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/tools/record" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + +func Test_buildPipeline(t *testing.T) { + defaultPipelinesConfig := MustPipelinesConfig( + []map[string]string{ + { + "pipeline.id": "demo", + "config.string": "input { exec { command => \"uptime\" interval => 5 } } output { stdout{} }", + }, + }, + ) + + for _, tt := range []struct { + name string + pipelines []map[string]string + configRef *commonv1.ConfigSource + client k8s.Client + want *PipelinesConfig + wantErr bool + }{ + { + name: "no user pipeline", + want: defaultPipelinesConfig, + }, + { + name: "pipeline populated", + pipelines: []map[string]string{{"pipeline.id": "main"}}, + want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + }, + { + name: "configref populated - no secret", + configRef: &commonv1.ConfigSource{ + SecretRef: commonv1.SecretRef{ + SecretName: "my-secret-pipeline", + }, + }, + client: k8s.NewFakeClient(), + want: NewPipelinesConfig(), + wantErr: true, + }, + { + name: "configref populated - no secret key", + configRef: &commonv1.ConfigSource{ + SecretRef: commonv1.SecretRef{ + SecretName: "my-secret-pipeline", + }, + }, + client: k8s.NewFakeClient(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-secret-pipeline", + }, + }), + want: NewPipelinesConfig(), + wantErr: true, + }, + { + name: "configref populated - malformed config", + configRef: &commonv1.ConfigSource{ + SecretRef: commonv1.SecretRef{ + SecretName: "my-secret-pipeline-2", + }, + }, + client: k8s.NewFakeClient(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-secret-pipeline-2", + }, + Data: map[string][]byte{"pipelines.yml": []byte("something:bad:value")}, + }), + want: NewPipelinesConfig(), + wantErr: true, + }, + { + name: "configref populated", + configRef: &commonv1.ConfigSource{ + SecretRef: commonv1.SecretRef{ + SecretName: "my-secret-pipeline-2", + }, + }, + client: k8s.NewFakeClient(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-secret-pipeline-2", + }, + Data: map[string][]byte{"pipelines.yml": []byte(`- "pipeline.id": "main"`)}, + }), + want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + }, + } { + t.Run(tt.name, func(t *testing.T) { + params := Params{ + Context: context.Background(), + Client: tt.client, + EventRecorder: &record.FakeRecorder{}, + Watches: watches.NewDynamicWatches(), + Logstash: logstashv1alpha1.Logstash{ + Spec: logstashv1alpha1.LogstashSpec{ + Pipelines: tt.pipelines, + PipelinesRef: tt.configRef, + }, + }, + } + + gotYaml, gotErr := buildPipeline(params) + diff, err := tt.want.Diff(MustParsePipelineConfig(gotYaml)) + if diff { + t.Errorf("buildPipeline() got unexpected differences: %v", err) + } + + require.Equal(t, tt.wantErr, gotErr != nil) + }) + } +} diff --git a/pkg/controller/logstash/pipelines_config.go b/pkg/controller/logstash/pipelines_config.go new file mode 100644 index 0000000000..1d7632e316 --- /dev/null +++ b/pkg/controller/logstash/pipelines_config.go @@ -0,0 +1,154 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "fmt" + "reflect" + + ucfg "github.com/elastic/go-ucfg" + uyaml "github.com/elastic/go-ucfg/yaml" + "github.com/pkg/errors" + yaml "gopkg.in/yaml.v3" +) + +// PipelinesConfig contains configuration for Logstash pipeline ("pipelines.yml"), +// as array of map of string +type PipelinesConfig ucfg.Config + +// Options are config options for the YAML file. +var Options = []ucfg.Option{ucfg.AppendValues} + +// NewPipelinesConfig creates a new empty config. +func NewPipelinesConfig() *PipelinesConfig { + return fromConfig(ucfg.New()) +} + +// NewPipelinesConfigFrom creates a new pipeline from the API type after normalizing the data. +func NewPipelinesConfigFrom(data []map[string]string) (*PipelinesConfig, error) { + config, err := ucfg.NewFrom(data, Options...) + if err != nil { + return nil, err + } + if err := checkTypeArray(config); err != nil { + return nil, err + } + return fromConfig(config), nil +} + +// MustPipelinesConfig creates a new pipeline and panics on errors. +// Use for testing only. +func MustPipelinesConfig(cfg interface{}) *PipelinesConfig { + config, err := ucfg.NewFrom(cfg, Options...) + if err != nil { + panic(err) + } + if err := checkTypeArray(config); err != nil { + panic(err) + } + return fromConfig(config) +} + +// ParsePipelinesConfig parses the given pipeline content into a PipelinesConfig. +// Expects content to be in YAML format. +func ParsePipelinesConfig(yml []byte) (*PipelinesConfig, error) { + config, err := uyaml.NewConfig(yml, Options...) + if err != nil { + return nil, err + } + + if err := checkTypeArray(config); err != nil { + return nil, err + } + return fromConfig(config), nil +} + +// MustParsePipelineConfig parses the given pipeline content into a Pipelines. +// Expects content to be in YAML format. Panics on error. +func MustParsePipelineConfig(yml []byte) *PipelinesConfig { + config, err := uyaml.NewConfig(yml, Options...) + if err != nil { + panic(err) + } + if err := checkTypeArray(config); err != nil { + panic(err) + } + return fromConfig(config) +} + +// Render returns the content of the configuration file, +// with fields sorted alphabetically +func (c *PipelinesConfig) Render() ([]byte, error) { + if c == nil { + return []byte{}, nil + } + var out []interface{} + if err := c.asUCfg().Unpack(&out); err != nil { + return []byte{}, err + } + return yaml.Marshal(out) +} + +// Diff returns the flattened keys where c and c2 differ. +// This is used in test only +func (c *PipelinesConfig) Diff(c2 *PipelinesConfig) (bool, error) { + if c == c2 { + return false, nil + } + if c == nil && c2 != nil { + return true, fmt.Errorf("empty lhs config %s", c2.asUCfg().FlattenedKeys(Options...)) + } + if c != nil && c2 == nil { + return true, fmt.Errorf("empty rhs config %s", c.asUCfg().FlattenedKeys(Options...)) + } + + var s []map[string]string + var s2 []map[string]string + err := c.asUCfg().Unpack(&s, Options...) + if err != nil { + return true, err + } + err = c2.asUCfg().Unpack(&s2, Options...) + if err != nil { + return true, err + } + + return diffSlice(s, s2) +} + +func diffSlice(s1, s2 []map[string]string) (bool, error) { + if len(s1) != len(s2) { + return true, fmt.Errorf("array size doesn't match %d, %d", len(s1), len(s2)) + } + var diff []string + for i, m := range s1 { + m2 := s2[i] + if eq := reflect.DeepEqual(m, m2); !eq { + diff = append(diff, fmt.Sprintf("%s vs %s, ", m, m2)) + } + } + + if len(diff) > 0 { + return true, fmt.Errorf("there are %d differences. %s", len(diff), diff) + } + + return false, nil +} + +func (c *PipelinesConfig) asUCfg() *ucfg.Config { + return (*ucfg.Config)(c) +} + +func fromConfig(in *ucfg.Config) *PipelinesConfig { + return (*PipelinesConfig)(in) +} + +// checkTypeArray checks if config is an Array or empty, otherwise throws error +func checkTypeArray(config *ucfg.Config) error { + if config.IsDict() { + return errors.New("config is not an array") + } + return nil +} diff --git a/pkg/controller/logstash/pipelines_config_test.go b/pkg/controller/logstash/pipelines_config_test.go new file mode 100644 index 0000000000..e765b6b8bb --- /dev/null +++ b/pkg/controller/logstash/pipelines_config_test.go @@ -0,0 +1,263 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestPipelinesConfig_Render(t *testing.T) { + config := MustPipelinesConfig( + []map[string]string{ + { + "pipeline.id": "demo", + "config.string": "input { exec { command => \"uptime\" interval => 5 } } output { stdout{} }", + }, + { + "pipeline.id": "standard", + "queue.type": "persisted", + "dead_letter_queue.max_bytes": "1024mb", + "path.config": "/tmp/logstash/*.config", + }, + }, + ) + output, err := config.Render() + require.NoError(t, err) + expected := []byte(`- config.string: input { exec { command => "uptime" interval => 5 } } output { stdout{} } + pipeline.id: demo +- dead_letter_queue.max_bytes: 1024mb + path.config: /tmp/logstash/*.config + pipeline.id: standard + queue.type: persisted +`) + require.Equal(t, string(expected), string(output)) +} + +func TestParsePipelinesConfig(t *testing.T) { + tests := []struct { + name string + input string + want *PipelinesConfig + wantErr bool + }{ + { + name: "no input", + input: "", + want: NewPipelinesConfig(), + wantErr: false, + }, + { + name: "simple input", + input: "- pipeline.id: demo\n config.string: input { exec { command => \"${ENV}\" interval => 5 } }", + want: MustPipelinesConfig( + []map[string]string{ + { + "pipeline.id": "demo", + "config.string": "input { exec { command => \"${ENV}\" interval => 5 } }", + }, + }, + ), + wantErr: false, + }, + { + name: "trim whitespaces between key and value", + input: "- pipeline.id : demo \n path.config : /tmp/logstash/*.config ", + want: MustPipelinesConfig( + []map[string]string{ + { + "pipeline.id": "demo", + "path.config": "/tmp/logstash/*.config", + }, + }, + ), + wantErr: false, + }, + { + name: "tabs are invalid in YAML", + input: "\ta: b \n c:d ", + wantErr: true, + }, + { + name: "trim newlines", + input: "- pipeline.id: demo \n\n- pipeline.id: demo2 \n", + want: MustPipelinesConfig( + []map[string]string{ + {"pipeline.id": "demo"}, + {"pipeline.id": "demo2"}, + }, + ), + wantErr: false, + }, + { + name: "ignore comments", + input: "- pipeline.id: demo \n#this is a comment\n pipeline.workers: \"1\"\n", + want: MustPipelinesConfig( + []map[string]string{ + { + "pipeline.id": "demo", + "pipeline.workers": "1", + }, + }, + ), + wantErr: false, + }, + { + name: "support quotes", + input: `- "pipeline.id": "quote"`, + want: MustPipelinesConfig( + []map[string]string{ + {"pipeline.id": "quote"}, + }, + ), + wantErr: false, + }, + { + name: "support special characters", + input: `- config.string: "${node.ip}%.:=+è! /"`, + want: MustPipelinesConfig( + []map[string]string{ + {"config.string": `${node.ip}%.:=+è! /`}, + }, + ), + wantErr: false, + }, + { + name: "invalid entry", + input: "config: not an array", + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := ParsePipelinesConfig([]byte(tt.input)) + if (err != nil) != tt.wantErr { + t.Errorf("ParsePipelinesConfig() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if got == tt.want { + return + } + + if diff, _ := got.Diff(tt.want); diff { + gotRendered, err := got.Render() + require.NoError(t, err) + wantRendered, err := tt.want.Render() + require.NoError(t, err) + t.Errorf("ParsePipelinesConfig(), want: %s, got: %s", wantRendered, gotRendered) + } + }) + } +} + +func TestPipelinesConfig_Diff(t *testing.T) { + tests := []struct { + name string + c *PipelinesConfig + c2 *PipelinesConfig + wantDiff bool + }{ + { + name: "nil diff", + c: nil, + c2: nil, + wantDiff: false, + }, + { + name: "lhs nil", + c: nil, + c2: MustPipelinesConfig( + []map[string]string{ + {"a": "a"}, + {"b": "b"}, + }, + ), + wantDiff: true, + }, + { + name: "rhs nil", + c: MustPipelinesConfig( + []map[string]string{ + {"a": "a"}, + }, + ), + c2: nil, + wantDiff: true, + }, + { + name: "same multi key value", + c: MustPipelinesConfig( + []map[string]string{ + {"a": "a", "b": "b"}, + }, + ), + c2: MustPipelinesConfig( + []map[string]string{ + {"b": "b", "a": "a"}, + }, + ), + wantDiff: false, + }, + { + name: "different value", + c: MustPipelinesConfig( + []map[string]string{ + {"a": "a"}, + }, + ), + c2: MustPipelinesConfig( + []map[string]string{ + {"a": "b"}, + }, + ), + wantDiff: true, + }, + { + name: "array size different", + c: MustPipelinesConfig( + []map[string]string{ + {"a": "a"}, + }, + ), + c2: MustPipelinesConfig( + []map[string]string{ + {"a": "a"}, + {"a": "a"}, + }, + ), + wantDiff: true, + }, + { + name: "respects list order", + c: MustPipelinesConfig( + []map[string]string{ + {"a": "a"}, + {"b": "b"}, + }, + ), + c2: MustPipelinesConfig( + []map[string]string{ + {"b": "b"}, + {"a": "a"}, + }, + ), + wantDiff: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + diff, err := tt.c.Diff(tt.c2) + if (err != nil) != tt.wantDiff { + t.Errorf("Diff() got unexpected differences. wantDiff: %t, err: %v", tt.wantDiff, err) + return + } + + require.Equal(t, tt.wantDiff, diff) + }) + } +} diff --git a/pkg/controller/logstash/pipelines_configref.go b/pkg/controller/logstash/pipelines_configref.go new file mode 100644 index 0000000000..373f7e4763 --- /dev/null +++ b/pkg/controller/logstash/pipelines_configref.go @@ -0,0 +1,75 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "context" + "fmt" + + "github.com/pkg/errors" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" +) + +// PipelinesRefWatchName returns the name of the watch registered on the secret referenced in `configRef`. +func PipelinesRefWatchName(resource types.NamespacedName) string { + return fmt.Sprintf("%s-%s-pipelinesref", resource.Namespace, resource.Name) +} + +// ParseConfigRef retrieves the content of a secret referenced in `configRef`, sets up dynamic watches for that secret, +// and parses the secret content into a PipelinesConfig. +func ParseConfigRef( + driver driver.Interface, + resource runtime.Object, // eg. Beat, EnterpriseSearch + configRef *commonv1.ConfigSource, + secretKey string, // retrieve config data from that entry in the secret +) (*PipelinesConfig, error) { + resourceMeta, err := meta.Accessor(resource) + if err != nil { + return nil, err + } + namespace := resourceMeta.GetNamespace() + resourceNsn := types.NamespacedName{Namespace: namespace, Name: resourceMeta.GetName()} + + // ensure watches match the referenced secret + var secretNames []string + if configRef != nil && configRef.SecretName != "" { + secretNames = append(secretNames, configRef.SecretName) + } + if err := watches.WatchUserProvidedSecrets(resourceNsn, driver.DynamicWatches(), PipelinesRefWatchName(resourceNsn), secretNames); err != nil { + return nil, err + } + + if len(secretNames) == 0 { + // no secret referenced, nothing to do + return nil, nil + } + + var secret corev1.Secret + if err := driver.K8sClient().Get(context.Background(), types.NamespacedName{Namespace: namespace, Name: configRef.SecretName}, &secret); err != nil { + // the secret may not exist (yet) in the cache, let's explicitly error out and retry later + return nil, err + } + data, exists := secret.Data[secretKey] + if !exists { + msg := fmt.Sprintf("unable to parse configRef secret %s/%s: missing key %s", namespace, configRef.SecretName, secretKey) + driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg) + return nil, errors.New(msg) + } + parsed, err := ParsePipelinesConfig(data) + if err != nil { + msg := fmt.Sprintf("unable to parse %s in configRef secret %s/%s", secretKey, namespace, configRef.SecretName) + driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg) + return nil, errors.Wrap(err, msg) + } + return parsed, nil +} diff --git a/pkg/controller/logstash/pipelines_configref_test.go b/pkg/controller/logstash/pipelines_configref_test.go new file mode 100644 index 0000000000..8cda53d5d7 --- /dev/null +++ b/pkg/controller/logstash/pipelines_configref_test.go @@ -0,0 +1,191 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package logstash + +import ( + "testing" + + "github.com/stretchr/testify/require" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/tools/record" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" +) + +type fakeDriver struct { + client k8s.Client + watches watches.DynamicWatches + recorder record.EventRecorder +} + +func (f fakeDriver) K8sClient() k8s.Client { + return f.client +} + +func (f fakeDriver) DynamicWatches() watches.DynamicWatches { + return f.watches +} + +func (f fakeDriver) Recorder() record.EventRecorder { + return f.recorder +} + +var _ driver.Interface = fakeDriver{} + +func TestParseConfigRef(t *testing.T) { + // any resource Kind would work here (eg. Beat, EnterpriseSearch, etc.) + resNsn := types.NamespacedName{Namespace: "ns", Name: "resource"} + res := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: resNsn.Namespace, Name: resNsn.Name}} + watchName := PipelinesRefWatchName(resNsn) + + tests := []struct { + name string + configRef *commonv1.ConfigSource + secretKey string + runtimeObjs []runtime.Object + want *PipelinesConfig + wantErr bool + existingWatches []string + wantWatches []string + wantEvent string + }{ + { + name: "happy path", + configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", + runtimeObjs: []runtime.Object{ + &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, + Data: map[string][]byte{ + "configFile.yml": []byte(`- "pipeline.id": "main"`), + }}, + }, + want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + wantWatches: []string{watchName}, + }, + { + name: "happy path, secret already watched", + configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", + runtimeObjs: []runtime.Object{ + &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, + Data: map[string][]byte{ + "configFile.yml": []byte(`- "pipeline.id": "main"`), + }}, + }, + want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + existingWatches: []string{watchName}, + wantWatches: []string{watchName}, + }, + { + name: "no configRef specified", + configRef: nil, + secretKey: "configFile.yml", + runtimeObjs: []runtime.Object{ + &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, + Data: map[string][]byte{ + "configFile.yml": []byte(`- "pipeline.id": "main"`), + }}, + }, + want: nil, + wantWatches: []string{}, + }, + { + name: "no configRef specified: clear existing watches", + configRef: nil, + secretKey: "configFile.yml", + runtimeObjs: []runtime.Object{ + &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, + Data: map[string][]byte{ + "configFile.yml": []byte(`- "pipeline.id": "main"`), + }}, + }, + want: nil, + existingWatches: []string{watchName}, + wantWatches: []string{}, + }, + { + name: "secret not found: error out but watch the future secret", + configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", + runtimeObjs: []runtime.Object{}, + want: nil, + wantErr: true, + wantWatches: []string{watchName}, + }, + { + name: "missing key in the referenced secret: error out, watch the secret and emit an event", + configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", + runtimeObjs: []runtime.Object{ + &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, + Data: map[string][]byte{ + "unexpected-key": []byte(`- "pipeline.id": "main"`), + }}, + }, + wantErr: true, + wantWatches: []string{watchName}, + wantEvent: "Warning Unexpected unable to parse configRef secret ns/my-secret: missing key configFile.yml", + }, + { + name: "invalid config the referenced secret: error out, watch the secret and emit an event", + configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", + runtimeObjs: []runtime.Object{ + &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, + Data: map[string][]byte{ + "configFile.yml": []byte(`"this.is": "an invalid array"`), + }}, + }, + wantErr: true, + wantWatches: []string{watchName}, + wantEvent: "Warning Unexpected unable to parse configFile.yml in configRef secret ns/my-secret", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + fakeRecorder := record.NewFakeRecorder(10) + w := watches.NewDynamicWatches() + for _, existingWatch := range tt.existingWatches { + require.NoError(t, w.Secrets.AddHandler(watches.NamedWatch{Name: existingWatch})) + } + d := fakeDriver{ + client: k8s.NewFakeClient(tt.runtimeObjs...), + watches: w, + recorder: fakeRecorder, + } + got, err := ParseConfigRef(d, &res, tt.configRef, tt.secretKey) + if (err != nil) != tt.wantErr { + t.Errorf("ParseConfigRef() error = %v, wantErr %v", err, tt.wantErr) + return + } + require.Equal(t, tt.want, got) + require.Equal(t, tt.wantWatches, d.watches.Secrets.Registrations()) + + if tt.wantEvent != "" { + require.Equal(t, tt.wantEvent, <-fakeRecorder.Events) + } else { + // no event expected + select { + case e := <-fakeRecorder.Events: + require.Fail(t, "no event expected but got one", "event", e) + default: + // ok + } + } + }) + } +} diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index a1d71bcf6a..84318c9ad8 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -32,6 +32,9 @@ const ( LogstashConfigVolumeName = "logstash" LogstashConfigFileName = "logstash.yml" + PipelineVolumeName = "pipeline" + PipelineFileName = "pipelines.yml" + // ConfigHashAnnotationName is an annotation used to store the Logstash config hash. ConfigHashAnnotationName = "logstash.k8s.elastic.co/config-hash" @@ -64,6 +67,13 @@ func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateS path.Join(ConfigMountPath, LogstashConfigFileName), LogstashConfigFileName, 0644), + // volume with logstash pipeline file + volume.NewSecretVolume( + logstashv1alpha1.PipelineSecretName(params.Logstash.Name), + PipelineVolumeName, + path.Join(ConfigMountPath, PipelineFileName), + PipelineFileName, + 0644), } labels := maps.Merge(params.Logstash.GetIdentityLabels(), map[string]string{ From 9f6ccf19229828ff9d35059bfe12e8a8e71df80b Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Fri, 3 Mar 2023 02:15:02 +0000 Subject: [PATCH 085/160] add pipeline to sample --- config/samples/logstash/logstash.yaml | 4 +++ .../samples/logstash/logstash_pipeline.yaml | 30 ------------------- 2 files changed, 4 insertions(+), 30 deletions(-) delete mode 100644 config/samples/logstash/logstash_pipeline.yaml diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml index 850dd41d9c..97e1d87263 100644 --- a/config/samples/logstash/logstash.yaml +++ b/config/samples/logstash/logstash.yaml @@ -1,3 +1,4 @@ + apiVersion: logstash.k8s.elastic.co/v1alpha1 kind: Logstash metadata: @@ -9,6 +10,9 @@ spec: log.level: info api.http.host: "0.0.0.0" queue.type: memory + pipelines: + - pipeline.id: main + config.string: input { exec { command => 'uptime' interval => 10 } } output { stdout{} } podTemplate: spec: containers: diff --git a/config/samples/logstash/logstash_pipeline.yaml b/config/samples/logstash/logstash_pipeline.yaml deleted file mode 100644 index 9b82b15434..0000000000 --- a/config/samples/logstash/logstash_pipeline.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: elasticsearch.k8s.elastic.co/v1 -kind: Elasticsearch -metadata: - name: elasticsearch-sample -spec: - version: 8.6.1 - nodeSets: - - name: default - count: 1 - config: - node.store.allow_mmap: false ---- -apiVersion: logstash.k8s.elastic.co/v1alpha1 -kind: Logstash -metadata: - name: logstash-sample -spec: - count: 1 - version: 8.6.1 - config: - log.level: info - api.http.host: "0.0.0.0" - queue.type: memory - pipelines: - - pipeline.id: main - config.string: input { exec { command => 'uptime' interval => 10 } } output { stdout{} } - podTemplate: - spec: - containers: - - name: logstash \ No newline at end of file From db5dd826c70292fcb8c37652d72584213ef85f2e Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Fri, 3 Mar 2023 02:32:49 +0000 Subject: [PATCH 086/160] lint and doc --- docs/reference/api-docs.asciidoc | 15 ++------------- pkg/apis/logstash/v1alpha1/name.go | 4 ++-- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index a90f42fa14..6494d43d84 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1896,7 +1896,8 @@ LogstashSpec defines the desired state of Logstash | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. -| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelineRef`] can be specified. +| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. +| *`pipelinesRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified. | *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. @@ -1925,18 +1926,6 @@ LogstashStatus defines the observed state of Logstash |=== -[id="{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-pipeline"] -=== Pipeline - - - -.Appears In: -**** -- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] -**** - - - [id="{anchor_prefix}-maps-k8s-elastic-co-v1alpha1"] == maps.k8s.elastic.co/v1alpha1 diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go index dcee068c2e..8b93b2cf3a 100644 --- a/pkg/apis/logstash/v1alpha1/name.go +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -11,7 +11,7 @@ import ( const ( apiServiceSuffix = "api" configSuffix = "config" - pipelineSuffix = "pipeline" + pipelineSuffix = "pipeline" ) // Namer is a Namer that is configured with the defaults for resources related to a Logstash resource. @@ -38,4 +38,4 @@ func UserServiceName(deployName string, name string) string { func PipelineSecretName(name string) string { return Namer.Suffix(name, pipelineSuffix) -} \ No newline at end of file +} From e94b7f3bb88cdcf2e78b5eb6ac9cffe161f0d2ee Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Fri, 3 Mar 2023 19:17:06 +0000 Subject: [PATCH 087/160] add e2e test --- test/e2e/logstash/pipeline_test.go | 135 +++++++++++++++++++++++++++++ test/e2e/test/logstash/builder.go | 35 ++++++++ test/e2e/test/logstash/checks.go | 100 ++++++++++++++++----- 3 files changed, 247 insertions(+), 23 deletions(-) create mode 100644 test/e2e/logstash/pipeline_test.go diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go new file mode 100644 index 0000000000..685945abab --- /dev/null +++ b/test/e2e/logstash/pipeline_test.go @@ -0,0 +1,135 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +//go:build logstash || e2e + +package logstash + +import ( + corev1 "k8s.io/api/core/v1" + "testing" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestPipelineConfigRefLogstash(t *testing.T) { + secretName := "ls-generator-pipeline" + + pipelineSecret := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: secretName, + Namespace: test.Ctx().ManagedNamespace(0), + }, + StringData: map[string]string{ + "pipelines.yml": ` +- pipeline.id: generator + config.string: input { generator {} } filter { sleep { time => 10 } } output { stdout { codec => dots } } +- pipeline.id: demo + config.string: input { stdin{} } output { stdout{} }`, + }, + } + + before := test.StepsFunc(func(k *test.K8sClient) test.StepList { + return test.StepList{}.WithStep(test.Step{ + Name: "Create pipeline secret", + Test: test.Eventually(func() error { + return k.CreateOrUpdateSecrets(pipelineSecret) + }), + }) + }) + + name := "test-pipeline-ref" + b := logstash.NewBuilder(name). + WithNodeCount(1). + WithPipelinesConfigRef(commonv1.ConfigSource{ + SecretRef: commonv1.SecretRef{ + SecretName: secretName, + }, + }) + + steps := test.StepsFunc(func(k *test.K8sClient) test.StepList { + return test.StepList{ + b.CheckMetricsRequest(k, + logstash.Request{ + Name: "pipeline [generator]", + Path: "/_node/pipelines/generator", + }, + logstash.Want{ + Status: "green", + }), + } + }) + + test.Sequence(before, steps, b).RunSequential(t) +} + +func TestPipelineConfigLogstash(t *testing.T) { + secretName := "ls-split-pipe" + + pipelineSecret := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: secretName, + Namespace: test.Ctx().ManagedNamespace(0), + }, + StringData: map[string]string{ + "split.conf": "input { exec { command => \"uptime\" interval => 10 } } output { stdout{} }", + }, + } + + before := test.StepsFunc(func(k *test.K8sClient) test.StepList { + return test.StepList{}.WithStep(test.Step{ + Name: "Create pipeline secret", + Test: test.Eventually(func() error { + return k.CreateOrUpdateSecrets(pipelineSecret) + }), + }) + }) + + name := "test-split-pipeline" + volName := "ls-pipe-vol" + mountPath := "/usr/share/logstash/pipeline" + + b := logstash.NewBuilder(name). + WithNodeCount(1). + WithPipelines([]map[string]string{ + { + "pipeline.id": "split", + "path.config": mountPath, + }, + { + "pipeline.id": "demo", + "config.string": "input { stdin{} } output { stdout{} }", + }, + }). + WithVolumes(corev1.Volume{ + Name: volName, + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: secretName, + }, + }, + }). + WithVolumeMounts(corev1.VolumeMount{ + Name: volName, + MountPath: mountPath, + }) + + steps := test.StepsFunc(func(k *test.K8sClient) test.StepList { + return test.StepList{ + b.CheckMetricsRequest(k, + logstash.Request{ + Name: "pipeline [split]", + Path: "/_node/pipelines/split", + }, + logstash.Want{ + Status: "green", + }), + } + }) + + test.Sequence(before, steps, b).RunSequential(t) +} diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 053253a1b6..d75a6c2a37 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -5,11 +5,14 @@ package logstash import ( + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" "sigs.k8s.io/controller-runtime/pkg/client" + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" @@ -115,6 +118,38 @@ func (b Builder) WithServices(services ...logstashv1alpha1.LogstashService) Buil return b } +func (b Builder) WithPipelines(pipelines []map[string]string) Builder { + b.Logstash.Spec.Pipelines = pipelines + return b +} + +func (b Builder) WithPipelinesConfigRef(ref commonv1.ConfigSource) Builder { + b.Logstash.Spec.PipelinesRef = &ref + return b +} + +func (b Builder) WithVolumes(vols ...corev1.Volume) Builder { + b.Logstash.Spec.PodTemplate.Spec.Volumes = append(b.Logstash.Spec.PodTemplate.Spec.Volumes, vols...) + return b +} + +func (b Builder) WithVolumeMounts(mounts ...corev1.VolumeMount) Builder { + if b.Logstash.Spec.PodTemplate.Spec.Containers == nil { + b.Logstash.Spec.PodTemplate.Spec.Containers = []corev1.Container{ + { + Name: "logstash", + VolumeMounts: mounts, + }, + } + } else { + if b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts == nil { + b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{} + } + b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts = append(b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts, mounts...) + } + return b +} + func (b Builder) NSN() types.NamespacedName { return k8s.ExtractNamespacedName(&b.Logstash) } diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 490a55394c..26396d33fe 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -8,6 +8,11 @@ import ( "context" "encoding/json" "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings" corev1 "k8s.io/api/core/v1" @@ -16,9 +21,16 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) -type logstashStatus struct { - Version string `json:"version"` - Status string `json:"status"` +type Request struct { + Name string + Path string +} + +type Want struct { + Status string + // Key is field path of ucfg.Config. Value is the expected string + // example, pipelines.demo.batch_size : 2 + Match map[string]string } // CheckSecrets checks that expected secrets have been created. @@ -35,6 +47,14 @@ func CheckSecrets(b Builder, k *test.K8sClient) test.Step { "logstash.k8s.elastic.co/name": logstashName, }, }, + { + Name: logstashName + "-ls-pipeline", + Keys: []string{"pipelines.yml"}, + Labels: map[string]string{ + "eck.k8s.elastic.co/credentials": "true", + "logstash.k8s.elastic.co/name": logstashName, + }, + }, } return expected }) @@ -65,29 +85,63 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { } func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { - println(test.Ctx().TestTimeout) return test.StepList{ - { - Name: "Logstash should respond to requests", - Test: test.Eventually(func() error { - client, err := NewLogstashClient(b.Logstash, k) - if err != nil { - return err - } - bytes, err := DoRequest(client, b.Logstash, "GET", "/") - if err != nil { - return err - } - var status logstashStatus - if err := json.Unmarshal(bytes, &status); err != nil { - return err - } + b.CheckMetricsRequest(k, + Request{ + Name: "metrics", + Path: "/", + }, + Want{ + Status: "green", + }), + b.CheckMetricsRequest(k, + Request{ + Name: "default pipeline", + Path: "/_node/pipelines/demo", + }, + Want{ + Status: "green", + Match: map[string]string{"pipelines.demo.workers": "2"}, + }), + } +} + +func (b Builder) CheckMetricsRequest(k *test.K8sClient, req Request, want Want) test.Step { + return test.Step{ + Name: fmt.Sprintf("Logstash should respond to %s requests", req.Name), + Test: func(t *testing.T) { + t.Helper() - if status.Status != "green" { - return fmt.Errorf("expected green but got %s", status.Status) + // send request and parse to map obj + client, err := NewLogstashClient(b.Logstash, k) + require.NoError(t, err) + + bytes, err := DoRequest(client, b.Logstash, "GET", req.Path) + require.NoError(t, err) + + var response map[string]interface{} + err = json.Unmarshal(bytes, &response) + require.NoError(t, err) + + // parse response to ucfg.Config for traverse + res, err := settings.NewCanonicalConfigFrom(response) + require.NoError(t, err) + + // check status + status, err := res.String("status") + require.NoError(t, err) + if status != want.Status { + require.NoError(t, fmt.Errorf("expected %s but got %s", want.Status, status)) + } + + // check expected string + for k, v := range want.Match { + str, err := res.String(k) + require.NoError(t, err) + if str != v { + require.NoError(t, fmt.Errorf("expected %s to be %s but got %s", k, v, str)) } - return nil - }), + } }, } } From 149a9b78fbacef152dbf2cc92b45f35bd3303ed7 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 7 Mar 2023 10:51:09 +0000 Subject: [PATCH 088/160] lint, doc, generate --- config/crds/v1/all-crds.yaml | 109 ++++++++++++++++++ .../logstash.k8s.elastic.co_logstashes.yaml | 109 ++++++++++++++++++ .../eck-operator-crds/templates/all-crds.yaml | 109 ++++++++++++++++++ docs/reference/api-docs.asciidoc | 2 + pkg/apis/logstash/v1alpha1/logstash_types.go | 4 +- .../v1alpha1/zz_generated.deepcopy.go | 38 +++++- pkg/controller/logstash/driver.go | 1 - test/e2e/test/logstash/builder.go | 1 - 8 files changed, 368 insertions(+), 5 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 7f291e0942..4f30dd94d3 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9121,6 +9121,108 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + monitoring: + description: Monitoring enables you to collect and ship log and monitoring + data of this Logstash. Metricbeat and Filebeat are deployed in the + same Pod as sidecars and each one sends data to one or two different + Elasticsearch monitoring clusters running in the same Kubernetes + cluster. + properties: + logs: + description: Logs holds references to Elasticsearch clusters which + receive log data from an associated resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + metrics: + description: Metrics holds references to Elasticsearch clusters + which receive monitoring data from this resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. @@ -9629,6 +9731,13 @@ spec: expectedNodes: format: int32 type: integer + monitoringAssociationStatus: + additionalProperties: + description: AssociationStatus is the status of an association resource. + type: string + description: MonitoringAssociationStatus is the status of any auto-linking + to monitoring Elasticsearch clusters. + type: object observedGeneration: description: ObservedGeneration is the most recent generation observed for this Logstash instance. It corresponds to the metadata generation, diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 40d31eaf89..5d330d10e2 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -77,6 +77,108 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + monitoring: + description: Monitoring enables you to collect and ship log and monitoring + data of this Logstash. Metricbeat and Filebeat are deployed in the + same Pod as sidecars and each one sends data to one or two different + Elasticsearch monitoring clusters running in the same Kubernetes + cluster. + properties: + logs: + description: Logs holds references to Elasticsearch clusters which + receive log data from an associated resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + metrics: + description: Metrics holds references to Elasticsearch clusters + which receive monitoring data from this resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. @@ -7992,6 +8094,13 @@ spec: expectedNodes: format: int32 type: integer + monitoringAssociationStatus: + additionalProperties: + description: AssociationStatus is the status of an association resource. + type: string + description: MonitoringAssociationStatus is the status of any auto-linking + to monitoring Elasticsearch clusters. + type: object observedGeneration: description: ObservedGeneration is the most recent generation observed for this Logstash instance. It corresponds to the metadata generation, diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 93d34492b1..74932dc3e2 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9175,6 +9175,108 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + monitoring: + description: Monitoring enables you to collect and ship log and monitoring + data of this Logstash. Metricbeat and Filebeat are deployed in the + same Pod as sidecars and each one sends data to one or two different + Elasticsearch monitoring clusters running in the same Kubernetes + cluster. + properties: + logs: + description: Logs holds references to Elasticsearch clusters which + receive log data from an associated resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + metrics: + description: Metrics holds references to Elasticsearch clusters + which receive monitoring data from this resource. + properties: + elasticsearchRefs: + description: ElasticsearchRefs is a reference to a list of + monitoring Elasticsearch clusters running in the same Kubernetes + cluster. Due to existing limitations, only a single Elasticsearch + cluster is currently supported. + items: + description: ObjectSelector defines a reference to a Kubernetes + object which can be an Elastic resource managed by the + operator or a Secret describing an external Elastic resource + not managed by the operator. + properties: + name: + description: Name of an existing Kubernetes object corresponding + to an Elastic resource managed by ECK. + type: string + namespace: + description: Namespace of the Kubernetes object. If + empty, defaults to the current namespace. + type: string + secretName: + description: 'SecretName is the name of an existing + Kubernetes secret that contains connection information + for associating an Elastic resource not managed by + the operator. The referenced secret must contain the + following: - `url`: the URL to reach the Elastic resource + - `username`: the username of the user to be authenticated + to the Elastic resource - `password`: the password + of the user to be authenticated to the Elastic resource + - `ca.crt`: the CA certificate in PEM format (optional). + This field cannot be used in combination with the + other fields name, namespace or serviceName.' + type: string + serviceName: + description: ServiceName is the name of an existing + Kubernetes service which is used to make requests + to the referenced object. It has to be in the same + namespace as the referenced resource. If left empty, + the default HTTP service of the referenced resource + is used. + type: string + type: object + type: array + type: object + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. @@ -9683,6 +9785,13 @@ spec: expectedNodes: format: int32 type: integer + monitoringAssociationStatus: + additionalProperties: + description: AssociationStatus is the status of an association resource. + type: string + description: MonitoringAssociationStatus is the status of any auto-linking + to monitoring Elasticsearch clusters. + type: object observedGeneration: description: ObservedGeneration is the most recent generation observed for this Logstash instance. It corresponds to the metadata generation, diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 68c4b5b0fc..df6bf48238 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -590,6 +590,7 @@ Monitoring holds references to both the metrics, and logs Elasticsearch clusters - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-beat-v1beta1-beatspec[$$BeatSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-elasticsearch-v1-elasticsearchspec[$$ElasticsearchSpec$$] - xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-kibana-v1-kibanaspec[$$KibanaSpec$$] +- xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashspec[$$LogstashSpec$$] **** [cols="25a,75a", options="header"] @@ -1897,6 +1898,7 @@ LogstashSpec defines the desired state of Logstash | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. | *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs +| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index b5c5c9456f..188a59c319 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -118,8 +118,8 @@ type Logstash struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec LogstashSpec `json:"spec,omitempty"` - Status LogstashStatus `json:"status,omitempty"` + Spec LogstashSpec `json:"spec,omitempty"` + Status LogstashStatus `json:"status,omitempty"` MonitoringAssocConfs map[commonv1.ObjectSelector]commonv1.AssociationConf `json:"-"` } diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index e4863e0454..0d921a9c67 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -20,7 +20,14 @@ func (in *Logstash) DeepCopyInto(out *Logstash) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) + if in.MonitoringAssocConfs != nil { + in, out := &in.MonitoringAssocConfs, &out.MonitoringAssocConfs + *out = make(map[v1.ObjectSelector]v1.AssociationConf, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Logstash. @@ -73,6 +80,27 @@ func (in *LogstashList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LogstashMonitoringAssociation) DeepCopyInto(out *LogstashMonitoringAssociation) { + *out = *in + if in.Logstash != nil { + in, out := &in.Logstash, &out.Logstash + *out = new(Logstash) + (*in).DeepCopyInto(*out) + } + out.ref = in.ref +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashMonitoringAssociation. +func (in *LogstashMonitoringAssociation) DeepCopy() *LogstashMonitoringAssociation { + if in == nil { + return nil + } + out := new(LogstashMonitoringAssociation) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LogstashService) DeepCopyInto(out *LogstashService) { *out = *in @@ -109,6 +137,7 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + in.Monitoring.DeepCopyInto(&out.Monitoring) in.PodTemplate.DeepCopyInto(&out.PodTemplate) if in.RevisionHistoryLimit != nil { in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit @@ -137,6 +166,13 @@ func (in *LogstashSpec) DeepCopy() *LogstashSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LogstashStatus) DeepCopyInto(out *LogstashStatus) { *out = *in + if in.MonitoringAssociationStatus != nil { + in, out := &in.MonitoringAssociationStatus, &out.MonitoringAssociationStatus + *out = make(v1.AssociationStatusMap, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogstashStatus. diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index afdd29d11f..8fe5caea18 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -9,7 +9,6 @@ import ( "hash/fnv" - "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" "k8s.io/client-go/tools/record" diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index d087c38707..cd58857a0c 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -119,7 +119,6 @@ func (b Builder) WithServices(services ...logstashv1alpha1.LogstashService) Buil return b } - func (b Builder) WithMonitoring(metricsESRef commonv1.ObjectSelector, logsESRef commonv1.ObjectSelector) Builder { b.Logstash.Spec.Monitoring.Metrics.ElasticsearchRefs = []commonv1.ObjectSelector{metricsESRef} b.Logstash.Spec.Monitoring.Logs.ElasticsearchRefs = []commonv1.ObjectSelector{logsESRef} From b98a36c5c40854576a909d2d07a5f473d8296f81 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 7 Mar 2023 12:14:16 +0000 Subject: [PATCH 089/160] update example --- config/samples/logstash/logstash_stackmonitor.yaml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/config/samples/logstash/logstash_stackmonitor.yaml b/config/samples/logstash/logstash_stackmonitor.yaml index 12ae1c9a72..793d85f945 100644 --- a/config/samples/logstash/logstash_stackmonitor.yaml +++ b/config/samples/logstash/logstash_stackmonitor.yaml @@ -11,18 +11,6 @@ spec: config: node.store.allow_mmap: false --- -apiVersion: elasticsearch.k8s.elastic.co/v1 -kind: Elasticsearch -metadata: - name: elasticsearch-sample -spec: - version: 8.6.1 - nodeSets: - - name: default - count: 1 - config: - node.store.allow_mmap: false ---- apiVersion: logstash.k8s.elastic.co/v1alpha1 kind: Logstash metadata: From 85decbb5452483e2ff772dd5f73179028d27a13e Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 7 Mar 2023 12:14:24 +0000 Subject: [PATCH 090/160] add webhook --- pkg/apis/logstash/v1alpha1/validations.go | 15 +++ pkg/apis/logstash/v1alpha1/webhook_test.go | 124 +++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 pkg/apis/logstash/v1alpha1/webhook_test.go diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go index 1f70d2783a..36cef8dc7a 100644 --- a/pkg/apis/logstash/v1alpha1/validations.go +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -7,6 +7,8 @@ package v1alpha1 import ( "k8s.io/apimachinery/pkg/util/validation/field" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" ) @@ -17,6 +19,8 @@ var ( checkNameLength, checkSupportedVersion, checkSingleConfigSource, + checkMonitoring, + checkAssociations, } updateChecks = []func(old, curr *Logstash) field.ErrorList{ @@ -54,3 +58,14 @@ func checkSingleConfigSource(a *Logstash) field.ErrorList { return nil } + +func checkMonitoring(k *Logstash) field.ErrorList { + return validations.Validate(k, k.Spec.Version) +} + +func checkAssociations(k *Logstash) field.ErrorList { + monitoringPath := field.NewPath("spec").Child("monitoring") + err1 := commonv1.CheckAssociationRefs(monitoringPath.Child("metrics"), k.GetMonitoringMetricsRefs()...) + err2 := commonv1.CheckAssociationRefs(monitoringPath.Child("logs"), k.GetMonitoringLogsRefs()...) + return append(err1, err2...) +} diff --git a/pkg/apis/logstash/v1alpha1/webhook_test.go b/pkg/apis/logstash/v1alpha1/webhook_test.go new file mode 100644 index 0000000000..14ff7839b7 --- /dev/null +++ b/pkg/apis/logstash/v1alpha1/webhook_test.go @@ -0,0 +1,124 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package v1alpha1_test + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" + admissionv1beta1 "k8s.io/api/admission/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/utils/test" +) + +func TestWebhook(t *testing.T) { + testCases := []test.ValidationWebhookTestCase{ + { + Name: "simple-stackmon-ref", + Operation: admissionv1beta1.Create, + Object: func(t *testing.T, uid string) []byte { + t.Helper() + ent := mkLogstash(uid) + ent.Spec.Version = "8.6.0" + ent.Spec.Monitoring = commonv1.Monitoring{Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{Name: "esmonname", Namespace: "esmonns"}}}} + return serialize(t, ent) + }, + Check: test.ValidationWebhookSucceeded, + }, + { + Name: "multiple-stackmon-ref", + Operation: admissionv1beta1.Create, + Object: func(t *testing.T, uid string) []byte { + t.Helper() + ent := mkLogstash(uid) + ent.Spec.Version = "8.6.0" + ent.Spec.Monitoring = commonv1.Monitoring{ + Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es1monname"}}}, + Logs: commonv1.LogsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es2monname"}}}, + } + return serialize(t, ent) + }, + Check: test.ValidationWebhookSucceeded, + }, + { + Name: "invalid-version-for-stackmon", + Operation: admissionv1beta1.Create, + Object: func(t *testing.T, uid string) []byte { + t.Helper() + ent := mkLogstash(uid) + ent.Spec.Version = "7.13.0" + ent.Spec.Monitoring = commonv1.Monitoring{Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{Name: "esmonname", Namespace: "esmonns"}}}} + return serialize(t, ent) + }, + Check: test.ValidationWebhookFailed( + `spec.version: Invalid value: "7.13.0": Unsupported version: version 7.13.0 is lower than the lowest supported version of 8.6.0`, + ), + }, + { + Name: "invalid-stackmon-ref-with-name", + Operation: admissionv1beta1.Create, + Object: func(t *testing.T, uid string) []byte { + t.Helper() + ent := mkLogstash(uid) + ent.Spec.Version = "8.6.0" + ent.Spec.Monitoring = commonv1.Monitoring{ + Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es1monname", Name: "xx"}}}, + Logs: commonv1.LogsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es2monname"}}}, + } + return serialize(t, ent) + }, + Check: test.ValidationWebhookFailed( + `spec.monitoring.metrics: Forbidden: Invalid association reference: specify name or secretName, not both`, + ), + }, + { + Name: "invalid-stackmon-ref-with-service-name", + Operation: admissionv1beta1.Create, + Object: func(t *testing.T, uid string) []byte { + t.Helper() + ent := mkLogstash(uid) + ent.Spec.Version = "8.6.0" + ent.Spec.Monitoring = commonv1.Monitoring{ + Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es1monname"}}}, + Logs: commonv1.LogsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es2monname", ServiceName: "xx"}}}, + } + return serialize(t, ent) + }, + Check: test.ValidationWebhookFailed( + `spec.monitoring.logs: Forbidden: Invalid association reference: serviceName or namespace can only be used in combination with name, not with secretName`, + ), + }, + } + + validator := &v1alpha1.Logstash{} + gvk := metav1.GroupVersionKind{Group: v1alpha1.GroupVersion.Group, Version: v1alpha1.GroupVersion.Version, Kind: v1alpha1.Kind} + test.RunValidationWebhookTests(t, gvk, validator, testCases...) +} + +func mkLogstash(uid string) *v1alpha1.Logstash { + return &v1alpha1.Logstash{ + ObjectMeta: metav1.ObjectMeta{ + Name: "webhook-test", + UID: types.UID(uid), + }, + Spec: v1alpha1.LogstashSpec{ + Version: "8.6.0", + }, + } +} + +func serialize(t *testing.T, k *v1alpha1.Logstash) []byte { + t.Helper() + + objBytes, err := json.Marshal(k) + require.NoError(t, err) + + return objBytes +} From ee630d2595fadaadf13562212af718e8421364bd Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 7 Mar 2023 12:20:40 +0000 Subject: [PATCH 091/160] add todo --- config/samples/logstash/logstash_stackmonitor.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/samples/logstash/logstash_stackmonitor.yaml b/config/samples/logstash/logstash_stackmonitor.yaml index 793d85f945..2e00cd9977 100644 --- a/config/samples/logstash/logstash_stackmonitor.yaml +++ b/config/samples/logstash/logstash_stackmonitor.yaml @@ -26,6 +26,8 @@ spec: spec: containers: - name: logstash + #TODO: remove command when Logstash has built with a monitor version of log4j2.properties + # https://github.com/elastic/logstash/issues/14941 command: ['sh', '-c', 'curl -o "log4j2.properties" "https://raw.githubusercontent.com/elastic/logstash/main/config/log4j2.properties" && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint'] monitoring: metrics: From 6fc77c0d7c8d7ee35a39ac59101268c9b0ee50a8 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 7 Mar 2023 16:16:03 +0000 Subject: [PATCH 092/160] lint, doc and generate --- config/crds/v1/all-crds.yaml | 19 ++++++++++++++ .../logstash.k8s.elastic.co_logstashes.yaml | 19 ++++++++++++++ .../eck-operator-crds/templates/all-crds.yaml | 19 ++++++++++++++ docs/reference/api-docs.asciidoc | 2 ++ .../v1alpha1/zz_generated.deepcopy.go | 18 +++++++++++++ test/e2e/test/logstash/checks.go | 26 ------------------- 6 files changed, 77 insertions(+), 26 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 7f291e0942..72f48a8906 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9121,6 +9121,25 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + additionalProperties: + type: string + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 40d31eaf89..229b4b2393 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -77,6 +77,25 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + additionalProperties: + type: string + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 93d34492b1..4339601682 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9175,6 +9175,25 @@ spec: description: Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. type: string + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + additionalProperties: + type: string + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 68c4b5b0fc..6494d43d84 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1896,6 +1896,8 @@ LogstashSpec defines the desired state of Logstash | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. +| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. +| *`pipelinesRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified. | *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index e4863e0454..e3537aa39e 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -102,6 +102,24 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { *out = new(v1.ConfigSource) **out = **in } + if in.Pipelines != nil { + in, out := &in.Pipelines, &out.Pipelines + *out = make([]map[string]string, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + } + } + if in.PipelinesRef != nil { + in, out := &in.PipelinesRef, &out.PipelinesRef + *out = new(v1.ConfigSource) + **out = **in + } if in.Services != nil { in, out := &in.Services, &out.Services *out = make([]LogstashService, len(*in)) diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 097aaf9f4d..26396d33fe 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -21,9 +21,6 @@ import ( "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" ) -type logstashStatus struct { - Version string `json:"version"` - Status string `json:"status"` type Request struct { Name string Path string @@ -88,29 +85,6 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { } func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { - println(test.Ctx().TestTimeout) - return test.StepList{ - { - Name: "Logstash should respond to requests", - Test: test.Eventually(func() error { - client, err := NewLogstashClient(b.Logstash, k) - if err != nil { - return err - } - bytes, err := DoRequest(client, b.Logstash, "GET", "/") - if err != nil { - return err - } - var status logstashStatus - if err := json.Unmarshal(bytes, &status); err != nil { - return err - } - - if status.Status != "green" { - return fmt.Errorf("expected green but got %s", status.Status) - } - return nil - }), return test.StepList{ b.CheckMetricsRequest(k, Request{ From 6badd2e8647e2a482dac7b46ddfd36b0ea36e0b2 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 7 Mar 2023 18:08:56 +0000 Subject: [PATCH 093/160] add pipelines and pipelinesRef validation --- pkg/apis/logstash/v1alpha1/validations.go | 13 +++++ .../logstash/v1alpha1/validations_test.go | 51 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go index 1f70d2783a..3233a93fc4 100644 --- a/pkg/apis/logstash/v1alpha1/validations.go +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -17,6 +17,7 @@ var ( checkNameLength, checkSupportedVersion, checkSingleConfigSource, + checkSinglePipelineSource, } updateChecks = []func(old, curr *Logstash) field.ErrorList{ @@ -54,3 +55,15 @@ func checkSingleConfigSource(a *Logstash) field.ErrorList { return nil } + +func checkSinglePipelineSource(a *Logstash) field.ErrorList { + if a.Spec.Pipelines != nil && a.Spec.PipelinesRef != nil { + msg := "Specify at most one of [`pipelines`, `pipelinesRef`], not both" + return field.ErrorList{ + field.Forbidden(field.NewPath("spec").Child("pipelines"), msg), + field.Forbidden(field.NewPath("spec").Child("pipelinesRef"), msg), + } + } + + return nil +} diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 08cd574aa4..700e222271 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -145,6 +145,57 @@ func Test_checkSingleConfigSource(t *testing.T) { } } +func Test_checkSinglePipelineSource(t *testing.T) { + tests := []struct { + name string + logstash Logstash + wantErr bool + }{ + { + name: "pipelinesRef absent, pipelines present", + logstash: Logstash{ + Spec: LogstashSpec{ + Pipelines: []map[string]string{}, + }, + }, + wantErr: false, + }, + { + name: "pipelines absent, pipelinesRef present", + logstash: Logstash{ + Spec: LogstashSpec{ + PipelinesRef: &commonv1.ConfigSource{}, + }, + }, + wantErr: false, + }, + { + name: "neither present", + logstash: Logstash{ + Spec: LogstashSpec{}, + }, + wantErr: false, + }, + { + name: "both present", + logstash: Logstash{ + Spec: LogstashSpec{ + Pipelines: []map[string]string{}, + PipelinesRef: &commonv1.ConfigSource{}, + }, + }, + wantErr: true, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + got := checkSinglePipelineSource(&tc.logstash) + assert.Equal(t, tc.wantErr, len(got) > 0) + }) + } +} + func Test_checkSupportedVersion(t *testing.T) { for _, tt := range []struct { name string From 3d2f47b2aab1977bb933775ae040a8e3006dc4ad Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 7 Mar 2023 18:50:44 +0000 Subject: [PATCH 094/160] rename and comment pipelines config --- pkg/controller/logstash/pipelines_config.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/controller/logstash/pipelines_config.go b/pkg/controller/logstash/pipelines_config.go index 1d7632e316..56cb1ab846 100644 --- a/pkg/controller/logstash/pipelines_config.go +++ b/pkg/controller/logstash/pipelines_config.go @@ -26,13 +26,13 @@ func NewPipelinesConfig() *PipelinesConfig { return fromConfig(ucfg.New()) } -// NewPipelinesConfigFrom creates a new pipeline from the API type after normalizing the data. +// NewPipelinesConfigFrom creates a new pipeline from spec. func NewPipelinesConfigFrom(data []map[string]string) (*PipelinesConfig, error) { config, err := ucfg.NewFrom(data, Options...) if err != nil { return nil, err } - if err := checkTypeArray(config); err != nil { + if err := checkIsDict(config); err != nil { return nil, err } return fromConfig(config), nil @@ -45,7 +45,7 @@ func MustPipelinesConfig(cfg interface{}) *PipelinesConfig { if err != nil { panic(err) } - if err := checkTypeArray(config); err != nil { + if err := checkIsDict(config); err != nil { panic(err) } return fromConfig(config) @@ -59,7 +59,7 @@ func ParsePipelinesConfig(yml []byte) (*PipelinesConfig, error) { return nil, err } - if err := checkTypeArray(config); err != nil { + if err := checkIsDict(config); err != nil { return nil, err } return fromConfig(config), nil @@ -72,7 +72,7 @@ func MustParsePipelineConfig(yml []byte) *PipelinesConfig { if err != nil { panic(err) } - if err := checkTypeArray(config); err != nil { + if err := checkIsDict(config); err != nil { panic(err) } return fromConfig(config) @@ -91,8 +91,8 @@ func (c *PipelinesConfig) Render() ([]byte, error) { return yaml.Marshal(out) } -// Diff returns the flattened keys where c and c2 differ. -// This is used in test only +// Diff returns true if the key/value or the sequence of two PipelinesConfig are different +// Use for testing only. func (c *PipelinesConfig) Diff(c2 *PipelinesConfig) (bool, error) { if c == c2 { return false, nil @@ -118,6 +118,7 @@ func (c *PipelinesConfig) Diff(c2 *PipelinesConfig) (bool, error) { return diffSlice(s, s2) } +// diffSlice returns true if the key/value or the sequence of two PipelinesConfig are different func diffSlice(s1, s2 []map[string]string) (bool, error) { if len(s1) != len(s2) { return true, fmt.Errorf("array size doesn't match %d, %d", len(s1), len(s2)) @@ -145,10 +146,10 @@ func fromConfig(in *ucfg.Config) *PipelinesConfig { return (*PipelinesConfig)(in) } -// checkTypeArray checks if config is an Array or empty, otherwise throws error -func checkTypeArray(config *ucfg.Config) error { +// checkIsDict throws error if config is a key/val map +func checkIsDict(config *ucfg.Config) error { if config.IsDict() { - return errors.New("config is not an array") + return errors.New("pipelines should be an array") } return nil } From 53aa65766befa8e2533d4c1568bff2cc6c648f35 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:12:55 +0000 Subject: [PATCH 095/160] Update pkg/controller/logstash/stackmon/sidecar.go Co-authored-by: Rob Bavey --- pkg/controller/logstash/stackmon/sidecar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go index 5e6adf01b8..77393b4ead 100644 --- a/pkg/controller/logstash/stackmon/sidecar.go +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -80,7 +80,7 @@ func WithMonitoring(ctx context.Context, client k8s.Client, builder *defaults.Po } if monitoring.IsLogsDefined(&logstash) { - // enable Stack logging to write Logstash logs to disk + // Set environment variable to tell Logstash container to write logs to disk builder.WithEnv(fileLogStyleEnvVar()) b, err := Filebeat(ctx, client, logstash) From 3f76e57257717385cb987b0383101b2c400b729f Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:13:07 +0000 Subject: [PATCH 096/160] Update pkg/apis/logstash/v1alpha1/logstash_types.go Co-authored-by: Michael Morello --- pkg/apis/logstash/v1alpha1/logstash_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 188a59c319..843cfae5df 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -151,7 +151,7 @@ func (l *Logstash) GetObservedGeneration() int64 { } func (l *Logstash) GetAssociations() []commonv1.Association { - associations := make([]commonv1.Association, 0) + var associations []commonv1.Association for _, ref := range l.Spec.Monitoring.Metrics.ElasticsearchRefs { if ref.IsDefined() { From 18609b50e8d9811ca6d3c24d3527b10e3ad6db14 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Wed, 8 Mar 2023 17:13:15 +0000 Subject: [PATCH 097/160] Update pkg/controller/logstash/stackmon/sidecar.go Co-authored-by: Michael Morello --- pkg/controller/logstash/stackmon/sidecar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go index 77393b4ead..648cb4b3d9 100644 --- a/pkg/controller/logstash/stackmon/sidecar.go +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -66,7 +66,7 @@ func WithMonitoring(ctx context.Context, client k8s.Client, builder *defaults.Po } configHash := fnv.New32a() - volumes := make([]corev1.Volume, 0) + var volumes []corev1.Volume if monitoring.IsMetricsDefined(&logstash) { b, err := Metricbeat(ctx, client, logstash) From 9ceef2b3c60ba8f55d01a0731f3ac0fb1fd40aff Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 17:18:41 +0000 Subject: [PATCH 098/160] ship deprecation log with filebeat --- pkg/controller/logstash/stackmon/filebeat.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controller/logstash/stackmon/filebeat.yml b/pkg/controller/logstash/stackmon/filebeat.yml index eef95065a3..314ef3c1f2 100644 --- a/pkg/controller/logstash/stackmon/filebeat.yml +++ b/pkg/controller/logstash/stackmon/filebeat.yml @@ -5,6 +5,7 @@ filebeat.modules: var.paths: - "/usr/share/logstash/logs/logstash-plain.log" - "/usr/share/logstash/logs/logstash-json.log" + - "/usr/share/logstash/logs/logstash-deprecation.log" slowlog: enabled: true var.paths: From ef6437f70ea67e4eaa4e0133cb3a07f320b5025d Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 17:22:18 +0000 Subject: [PATCH 099/160] add comments --- pkg/controller/logstash/stackmon/sidecar.go | 1 + test/e2e/logstash/stack_monitoring_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/controller/logstash/stackmon/sidecar.go b/pkg/controller/logstash/stackmon/sidecar.go index 648cb4b3d9..c178de44fe 100644 --- a/pkg/controller/logstash/stackmon/sidecar.go +++ b/pkg/controller/logstash/stackmon/sidecar.go @@ -89,6 +89,7 @@ func WithMonitoring(ctx context.Context, client k8s.Client, builder *defaults.Po } // create a logs volume shared between Logstash and Filebeat + // TODO: revisit log volume when persistent storage is added logsVolume := volume.NewEmptyDirVolume(logstashLogsVolumeName, logstashLogsMountPath) volumes = append(volumes, logsVolume.Volume()) filebeat := b.Container diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 676d3eb15c..28059d63c9 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -15,7 +15,7 @@ import ( "testing" ) -// TestESStackMonitoring tests that when an Logstash is configured with monitoring, its log and metrics are +// TestLogstashStackMonitoring tests that when Logstash is configured with monitoring, its log and metrics are // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestLogstashStackMonitoring(t *testing.T) { // only execute this test on supported version From 9c9c12e60a2d195557f6d8bf1cfcc891f89abe1f Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 17:31:25 +0000 Subject: [PATCH 100/160] use static log4j2.properties --- test/e2e/logstash/stack_monitoring_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 28059d63c9..0f5872ef36 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -34,7 +34,7 @@ func TestLogstashStackMonitoring(t *testing.T) { WithMonitoring(metrics.Ref(), logs.Ref()). //TODO: remove command when Logstash has built with a monitor version of log4j2.properties // https://github.com/elastic/logstash/issues/14941 - WithCommand([]string{"sh", "-c", "curl -o 'log4j2.properties' 'https://raw.githubusercontent.com/elastic/logstash/main/config/log4j2.properties' && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint"}) + WithCommand([]string{"sh", "-c", "curl -o 'log4j2.properties' 'https://raw.githubusercontent.com/elastic/logstash/445a15489da63e678664eb38dbe8bf64d9a7ffe0/config/log4j2.properties' && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint"}) // checks that the sidecar beats have sent data in the monitoring clusters steps := func(k *test.K8sClient) test.StepList { From e4e5d846fbd6bdc8dc24a6c853918baa78b165ea Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 18:20:34 +0000 Subject: [PATCH 101/160] rename receiver --- pkg/apis/logstash/v1alpha1/validations.go | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go index 36cef8dc7a..ca776228c5 100644 --- a/pkg/apis/logstash/v1alpha1/validations.go +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -28,16 +28,16 @@ var ( } ) -func checkNoUnknownFields(a *Logstash) field.ErrorList { - return commonv1.NoUnknownFields(a, a.ObjectMeta) +func checkNoUnknownFields(l *Logstash) field.ErrorList { + return commonv1.NoUnknownFields(l, l.ObjectMeta) } -func checkNameLength(a *Logstash) field.ErrorList { - return commonv1.CheckNameLength(a) +func checkNameLength(l *Logstash) field.ErrorList { + return commonv1.CheckNameLength(l) } -func checkSupportedVersion(a *Logstash) field.ErrorList { - return commonv1.CheckSupportedStackVersion(a.Spec.Version, version.SupportedLogstashVersions) +func checkSupportedVersion(l *Logstash) field.ErrorList { + return commonv1.CheckSupportedStackVersion(l.Spec.Version, version.SupportedLogstashVersions) } func checkNoDowngrade(prev, curr *Logstash) field.ErrorList { @@ -47,8 +47,8 @@ func checkNoDowngrade(prev, curr *Logstash) field.ErrorList { return commonv1.CheckNoDowngrade(prev.Spec.Version, curr.Spec.Version) } -func checkSingleConfigSource(a *Logstash) field.ErrorList { - if a.Spec.Config != nil && a.Spec.ConfigRef != nil { +func checkSingleConfigSource(l *Logstash) field.ErrorList { + if l.Spec.Config != nil && l.Spec.ConfigRef != nil { msg := "Specify at most one of [`config`, `configRef`], not both" return field.ErrorList{ field.Forbidden(field.NewPath("spec").Child("config"), msg), @@ -59,13 +59,13 @@ func checkSingleConfigSource(a *Logstash) field.ErrorList { return nil } -func checkMonitoring(k *Logstash) field.ErrorList { - return validations.Validate(k, k.Spec.Version) +func checkMonitoring(l *Logstash) field.ErrorList { + return validations.Validate(l, l.Spec.Version) } -func checkAssociations(k *Logstash) field.ErrorList { +func checkAssociations(l *Logstash) field.ErrorList { monitoringPath := field.NewPath("spec").Child("monitoring") - err1 := commonv1.CheckAssociationRefs(monitoringPath.Child("metrics"), k.GetMonitoringMetricsRefs()...) - err2 := commonv1.CheckAssociationRefs(monitoringPath.Child("logs"), k.GetMonitoringLogsRefs()...) + err1 := commonv1.CheckAssociationRefs(monitoringPath.Child("metrics"), l.GetMonitoringMetricsRefs()...) + err2 := commonv1.CheckAssociationRefs(monitoringPath.Child("logs"), l.GetMonitoringLogsRefs()...) return append(err1, err2...) } From fab33db6ab92c4ec28889e9dabff88d7c06c4bab Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 18:33:43 +0000 Subject: [PATCH 102/160] remove duplicate container name --- pkg/controller/logstash/pod.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/controller/logstash/pod.go b/pkg/controller/logstash/pod.go index 6227fdb774..00ff46e823 100644 --- a/pkg/controller/logstash/pod.go +++ b/pkg/controller/logstash/pod.go @@ -25,8 +25,6 @@ import ( ) const ( - ContainerName = "logstash" - ConfigVolumeName = "config" ConfigMountPath = "/usr/share/logstash/config" @@ -56,7 +54,7 @@ var ( func buildPodTemplate(params Params, configHash hash.Hash32) corev1.PodTemplateSpec { defer tracing.Span(¶ms.Context)() spec := ¶ms.Logstash.Spec - builder := defaults.NewPodTemplateBuilder(params.GetPodTemplate(), ContainerName) + builder := defaults.NewPodTemplateBuilder(params.GetPodTemplate(), logstashv1alpha1.LogstashContainerName) vols := []volume.VolumeLike{ // volume with logstash configuration file volume.NewSecretVolume( From 60736da106273f802938866611b69adb4a16eb00 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 19:17:36 +0000 Subject: [PATCH 103/160] set minimum es version for test --- test/e2e/logstash/stack_monitoring_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 0f5872ef36..2827586c0c 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -7,7 +7,7 @@ package logstash import ( - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" @@ -15,11 +15,15 @@ import ( "testing" ) +var ( + MinESVersion = version.MustParse("8.0.0") +) + // TestLogstashStackMonitoring tests that when Logstash is configured with monitoring, its log and metrics are // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestLogstashStackMonitoring(t *testing.T) { // only execute this test on supported version - err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion) + err := IsSupportedVersion(test.Ctx().ElasticStackVersion) if err != nil { t.SkipNow() } @@ -43,3 +47,14 @@ func TestLogstashStackMonitoring(t *testing.T) { test.Sequence(nil, steps, metrics, logs, monitored).RunSequential(t) } + +func IsSupportedVersion(v string) error { + ver, err := version.Parse(v) + if err != nil { + return err + } + if ver.LT(MinESVersion) { + return fmt.Errorf("unsupported version for Stack Monitoring: required >= %s", MinESVersion) + } + return nil +} From 0fb32990b25c1b1357c151816a5a848cdba8cf9d Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 19:59:53 +0000 Subject: [PATCH 104/160] add doc for log4j2 requirement --- config/crds/v1/all-crds.yaml | 8 ++++++-- .../crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml | 8 ++++++-- .../charts/eck-operator-crds/templates/all-crds.yaml | 8 ++++++-- docs/reference/api-docs.asciidoc | 2 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 3 +++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 4f30dd94d3..2b8fd4d54b 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9122,11 +9122,15 @@ spec: and Type have to match the Logstash in the image. type: string monitoring: - description: Monitoring enables you to collect and ship log and monitoring + description: 'Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes - cluster. + cluster. This feature is under technical preview. To allow Logstash + outputs log to disk and ships the log through Filebeat, the Logstash + docker image requires a customised log4j2.properties to write log + to file. The default log4j2.properties in docker only writes log + to stdout. Issue: https://github.com/elastic/logstash/issues/14941' properties: logs: description: Logs holds references to Elasticsearch clusters which diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 5d330d10e2..fa8d30e2b1 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -78,11 +78,15 @@ spec: and Type have to match the Logstash in the image. type: string monitoring: - description: Monitoring enables you to collect and ship log and monitoring + description: 'Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes - cluster. + cluster. This feature is under technical preview. To allow Logstash + outputs log to disk and ships the log through Filebeat, the Logstash + docker image requires a customised log4j2.properties to write log + to file. The default log4j2.properties in docker only writes log + to stdout. Issue: https://github.com/elastic/logstash/issues/14941' properties: logs: description: Logs holds references to Elasticsearch clusters which diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 74932dc3e2..191863748a 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9176,11 +9176,15 @@ spec: and Type have to match the Logstash in the image. type: string monitoring: - description: Monitoring enables you to collect and ship log and monitoring + description: 'Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes - cluster. + cluster. This feature is under technical preview. To allow Logstash + outputs log to disk and ships the log through Filebeat, the Logstash + docker image requires a customised log4j2.properties to write log + to file. The default log4j2.properties in docker only writes log + to stdout. Issue: https://github.com/elastic/logstash/issues/14941' properties: logs: description: Logs holds references to Elasticsearch clusters which diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index df6bf48238..35cd60c57d 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1898,7 +1898,7 @@ LogstashSpec defines the desired state of Logstash | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. | *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs -| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. +| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. This feature is under technical preview. To allow Logstash outputs log to disk and ships the log through Filebeat, the Logstash docker image requires a customised log4j2.properties to write log to file. The default log4j2.properties in docker only writes log to stdout. Issue: https://github.com/elastic/logstash/issues/14941 | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 843cfae5df..18ed05cd80 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -51,6 +51,9 @@ type LogstashSpec struct { // Monitoring enables you to collect and ship log and monitoring data of this Logstash. // Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different // Elasticsearch monitoring clusters running in the same Kubernetes cluster. + // This feature is under technical preview. To allow Logstash outputs log to disk and ships the log through Filebeat, + // the Logstash docker image requires a customised log4j2.properties to write log to file. + // The default log4j2.properties in docker only writes log to stdout. Issue: https://github.com/elastic/logstash/issues/14941 // +kubebuilder:validation:Optional Monitoring commonv1.Monitoring `json:"monitoring,omitempty"` From 29c66ff466451bd17f76cbd084155cae99e192fc Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 21:32:16 +0000 Subject: [PATCH 105/160] Revert "set minimum es version for test" This reverts commit 60736da106273f802938866611b69adb4a16eb00. --- test/e2e/logstash/stack_monitoring_test.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 2827586c0c..0f5872ef36 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -7,7 +7,7 @@ package logstash import ( - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" @@ -15,15 +15,11 @@ import ( "testing" ) -var ( - MinESVersion = version.MustParse("8.0.0") -) - // TestLogstashStackMonitoring tests that when Logstash is configured with monitoring, its log and metrics are // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestLogstashStackMonitoring(t *testing.T) { // only execute this test on supported version - err := IsSupportedVersion(test.Ctx().ElasticStackVersion) + err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion) if err != nil { t.SkipNow() } @@ -47,14 +43,3 @@ func TestLogstashStackMonitoring(t *testing.T) { test.Sequence(nil, steps, metrics, logs, monitored).RunSequential(t) } - -func IsSupportedVersion(v string) error { - ver, err := version.Parse(v) - if err != nil { - return err - } - if ver.LT(MinESVersion) { - return fmt.Errorf("unsupported version for Stack Monitoring: required >= %s", MinESVersion) - } - return nil -} From 461fbf75b004092776f3b274f51bf4dfa116e6fd Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 22:49:49 +0000 Subject: [PATCH 106/160] reuse ParseConfigRef --- pkg/controller/common/configref.go | 25 +++++++++- pkg/controller/logstash/pipelines_config.go | 13 +++-- .../logstash/pipelines_configref.go | 50 +++++-------------- 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/pkg/controller/common/configref.go b/pkg/controller/common/configref.go index 0f100206b8..f7c6279399 100644 --- a/pkg/controller/common/configref.go +++ b/pkg/controller/common/configref.go @@ -7,6 +7,8 @@ package common import ( "context" "fmt" + "github.com/elastic/go-ucfg" + uyaml "github.com/elastic/go-ucfg/yaml" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" @@ -34,6 +36,23 @@ func ParseConfigRef( configRef *commonv1.ConfigSource, secretKey string, // retrieve config data from that entry in the secret ) (*settings.CanonicalConfig, error) { + parsed, err := ParseConfigRefToConfig(driver, resource, configRef, secretKey, ConfigRefWatchName, settings.Options) + if err != nil { + return nil, err + } + return (*settings.CanonicalConfig)(parsed), nil +} + +// ParseConfigRefToConfig retrieves the content of a secret referenced in `configRef`, sets up dynamic watches for that secret, +// and parses the secret content into ucfg.Config. +func ParseConfigRefToConfig( + driver driver.Interface, + resource runtime.Object, // eg. Beat, EnterpriseSearch + configRef *commonv1.ConfigSource, + secretKey string, // retrieve config data from that entry in the secret + configRefWatchName func(types.NamespacedName) string, + configOptions []ucfg.Option, +) (*ucfg.Config, error) { resourceMeta, err := meta.Accessor(resource) if err != nil { return nil, err @@ -46,7 +65,7 @@ func ParseConfigRef( if configRef != nil && configRef.SecretName != "" { secretNames = append(secretNames, configRef.SecretName) } - if err := watches.WatchUserProvidedSecrets(resourceNsn, driver.DynamicWatches(), ConfigRefWatchName(resourceNsn), secretNames); err != nil { + if err := watches.WatchUserProvidedSecrets(resourceNsn, driver.DynamicWatches(), configRefWatchName(resourceNsn), secretNames); err != nil { return nil, err } @@ -66,7 +85,9 @@ func ParseConfigRef( driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg) return nil, errors.New(msg) } - parsed, err := settings.ParseConfig(data) + + parsed, err := uyaml.NewConfig(data, configOptions...) + if err != nil { msg := fmt.Sprintf("unable to parse %s in configRef secret %s/%s", secretKey, namespace, configRef.SecretName) driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg) diff --git a/pkg/controller/logstash/pipelines_config.go b/pkg/controller/logstash/pipelines_config.go index 56cb1ab846..6e7921d3f0 100644 --- a/pkg/controller/logstash/pipelines_config.go +++ b/pkg/controller/logstash/pipelines_config.go @@ -32,7 +32,7 @@ func NewPipelinesConfigFrom(data []map[string]string) (*PipelinesConfig, error) if err != nil { return nil, err } - if err := checkIsDict(config); err != nil { + if err := checkIsArray(config); err != nil { return nil, err } return fromConfig(config), nil @@ -45,7 +45,7 @@ func MustPipelinesConfig(cfg interface{}) *PipelinesConfig { if err != nil { panic(err) } - if err := checkIsDict(config); err != nil { + if err := checkIsArray(config); err != nil { panic(err) } return fromConfig(config) @@ -58,8 +58,7 @@ func ParsePipelinesConfig(yml []byte) (*PipelinesConfig, error) { if err != nil { return nil, err } - - if err := checkIsDict(config); err != nil { + if err := checkIsArray(config); err != nil { return nil, err } return fromConfig(config), nil @@ -72,7 +71,7 @@ func MustParsePipelineConfig(yml []byte) *PipelinesConfig { if err != nil { panic(err) } - if err := checkIsDict(config); err != nil { + if err := checkIsArray(config); err != nil { panic(err) } return fromConfig(config) @@ -146,8 +145,8 @@ func fromConfig(in *ucfg.Config) *PipelinesConfig { return (*PipelinesConfig)(in) } -// checkIsDict throws error if config is a key/val map -func checkIsDict(config *ucfg.Config) error { +// checkIsArray throws error if config is a key/val map +func checkIsArray(config *ucfg.Config) error { if config.IsDict() { return errors.New("pipelines should be an array") } diff --git a/pkg/controller/logstash/pipelines_configref.go b/pkg/controller/logstash/pipelines_configref.go index 373f7e4763..d28f32f4fc 100644 --- a/pkg/controller/logstash/pipelines_configref.go +++ b/pkg/controller/logstash/pipelines_configref.go @@ -5,9 +5,8 @@ package logstash import ( - "context" "fmt" - + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" @@ -15,9 +14,8 @@ import ( "k8s.io/apimachinery/pkg/types" commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" ) // PipelinesRefWatchName returns the name of the watch registered on the secret referenced in `configRef`. @@ -29,47 +27,25 @@ func PipelinesRefWatchName(resource types.NamespacedName) string { // and parses the secret content into a PipelinesConfig. func ParseConfigRef( driver driver.Interface, - resource runtime.Object, // eg. Beat, EnterpriseSearch + resource runtime.Object, configRef *commonv1.ConfigSource, secretKey string, // retrieve config data from that entry in the secret ) (*PipelinesConfig, error) { - resourceMeta, err := meta.Accessor(resource) + parsed, err := common.ParseConfigRefToConfig(driver, resource, configRef, secretKey, PipelinesRefWatchName, Options) if err != nil { return nil, err } - namespace := resourceMeta.GetNamespace() - resourceNsn := types.NamespacedName{Namespace: namespace, Name: resourceMeta.GetName()} - // ensure watches match the referenced secret - var secretNames []string - if configRef != nil && configRef.SecretName != "" { - secretNames = append(secretNames, configRef.SecretName) - } - if err := watches.WatchUserProvidedSecrets(resourceNsn, driver.DynamicWatches(), PipelinesRefWatchName(resourceNsn), secretNames); err != nil { - return nil, err - } + if parsed != nil { + if err := checkIsArray(parsed); err != nil { + resourceMeta, _ := meta.Accessor(resource) + namespace := resourceMeta.GetNamespace() - if len(secretNames) == 0 { - // no secret referenced, nothing to do - return nil, nil + msg := fmt.Sprintf("unable to parse %s in configRef secret %s/%s", secretKey, namespace, configRef.SecretName) + driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg) + return nil, errors.Wrap(err, msg) + } } - var secret corev1.Secret - if err := driver.K8sClient().Get(context.Background(), types.NamespacedName{Namespace: namespace, Name: configRef.SecretName}, &secret); err != nil { - // the secret may not exist (yet) in the cache, let's explicitly error out and retry later - return nil, err - } - data, exists := secret.Data[secretKey] - if !exists { - msg := fmt.Sprintf("unable to parse configRef secret %s/%s: missing key %s", namespace, configRef.SecretName, secretKey) - driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg) - return nil, errors.New(msg) - } - parsed, err := ParsePipelinesConfig(data) - if err != nil { - msg := fmt.Sprintf("unable to parse %s in configRef secret %s/%s", secretKey, namespace, configRef.SecretName) - driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg) - return nil, errors.Wrap(err, msg) - } - return parsed, nil + return (*PipelinesConfig)(parsed), nil } From 16092ca685d2918e6e84a44befbe463d59d860c9 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 8 Mar 2023 23:10:19 +0000 Subject: [PATCH 107/160] lint --- pkg/controller/common/configref.go | 1 + pkg/controller/logstash/pipelines_configref.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/controller/common/configref.go b/pkg/controller/common/configref.go index f7c6279399..89961372b8 100644 --- a/pkg/controller/common/configref.go +++ b/pkg/controller/common/configref.go @@ -7,6 +7,7 @@ package common import ( "context" "fmt" + "github.com/elastic/go-ucfg" uyaml "github.com/elastic/go-ucfg/yaml" diff --git a/pkg/controller/logstash/pipelines_configref.go b/pkg/controller/logstash/pipelines_configref.go index d28f32f4fc..be59347152 100644 --- a/pkg/controller/logstash/pipelines_configref.go +++ b/pkg/controller/logstash/pipelines_configref.go @@ -6,13 +6,15 @@ package logstash import ( "fmt" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" From b5943a46958c3fbf1502f07a1bbff0425f6df6be Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 9 Mar 2023 10:37:30 +0000 Subject: [PATCH 108/160] set minimum es version for test --- test/e2e/logstash/stack_monitoring_test.go | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 0f5872ef36..29b5200f4e 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -7,19 +7,25 @@ package logstash import ( - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" + "fmt" + "testing" + + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" - "testing" +) + +var ( + MinESVersion = version.MustParse("8.0.0") ) // TestLogstashStackMonitoring tests that when Logstash is configured with monitoring, its log and metrics are // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestLogstashStackMonitoring(t *testing.T) { // only execute this test on supported version - err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion) + err := IsSupportedVersion(test.Ctx().ElasticStackVersion) if err != nil { t.SkipNow() } @@ -43,3 +49,14 @@ func TestLogstashStackMonitoring(t *testing.T) { test.Sequence(nil, steps, metrics, logs, monitored).RunSequential(t) } + +func IsSupportedVersion(v string) error { + ver, err := version.Parse(v) + if err != nil { + return err + } + if ver.LT(MinESVersion) { + return fmt.Errorf("unsupported version for Stack Monitoring: required >= %s", MinESVersion) + } + return nil +} From 48915cfe41895af5d9df9c03663bf0c2434c358d Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 9 Mar 2023 12:06:11 +0000 Subject: [PATCH 109/160] - refactor version validation - update min version to 8.7.0 - update sample - update test - remove log4j2 issue doc --- config/crds/v1/all-crds.yaml | 8 ++---- .../logstash.k8s.elastic.co_logstashes.yaml | 8 ++---- .../logstash/logstash_stackmonitor.yaml | 5 +--- .../eck-operator-crds/templates/all-crds.yaml | 8 ++---- docs/reference/api-docs.asciidoc | 2 +- pkg/apis/beat/v1beta1/validations.go | 2 +- pkg/apis/kibana/v1/webhook.go | 2 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 3 --- pkg/apis/logstash/v1alpha1/validations.go | 7 ++++- pkg/apis/logstash/v1alpha1/webhook_test.go | 10 +++---- .../stackmon/validations/validations.go | 12 ++++----- .../stackmon/validations/validations_test.go | 2 +- .../elasticsearch/validation/validations.go | 2 +- test/e2e/beat/config_test.go | 2 +- test/e2e/es/stack_monitoring_test.go | 4 +-- test/e2e/kb/stack_monitoring_test.go | 2 +- test/e2e/logstash/stack_monitoring_test.go | 26 +++---------------- 17 files changed, 37 insertions(+), 68 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 2b8fd4d54b..4f30dd94d3 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9122,15 +9122,11 @@ spec: and Type have to match the Logstash in the image. type: string monitoring: - description: 'Monitoring enables you to collect and ship log and monitoring + description: Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes - cluster. This feature is under technical preview. To allow Logstash - outputs log to disk and ships the log through Filebeat, the Logstash - docker image requires a customised log4j2.properties to write log - to file. The default log4j2.properties in docker only writes log - to stdout. Issue: https://github.com/elastic/logstash/issues/14941' + cluster. properties: logs: description: Logs holds references to Elasticsearch clusters which diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index fa8d30e2b1..5d330d10e2 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -78,15 +78,11 @@ spec: and Type have to match the Logstash in the image. type: string monitoring: - description: 'Monitoring enables you to collect and ship log and monitoring + description: Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes - cluster. This feature is under technical preview. To allow Logstash - outputs log to disk and ships the log through Filebeat, the Logstash - docker image requires a customised log4j2.properties to write log - to file. The default log4j2.properties in docker only writes log - to stdout. Issue: https://github.com/elastic/logstash/issues/14941' + cluster. properties: logs: description: Logs holds references to Elasticsearch clusters which diff --git a/config/samples/logstash/logstash_stackmonitor.yaml b/config/samples/logstash/logstash_stackmonitor.yaml index 2e00cd9977..5194e52be2 100644 --- a/config/samples/logstash/logstash_stackmonitor.yaml +++ b/config/samples/logstash/logstash_stackmonitor.yaml @@ -17,7 +17,7 @@ metadata: name: logstash-sample spec: count: 1 - version: 8.6.1 + version: 8.7.0 config: log.level: info api.http.host: "0.0.0.0" @@ -26,9 +26,6 @@ spec: spec: containers: - name: logstash - #TODO: remove command when Logstash has built with a monitor version of log4j2.properties - # https://github.com/elastic/logstash/issues/14941 - command: ['sh', '-c', 'curl -o "log4j2.properties" "https://raw.githubusercontent.com/elastic/logstash/main/config/log4j2.properties" && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint'] monitoring: metrics: elasticsearchRefs: diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 191863748a..74932dc3e2 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9176,15 +9176,11 @@ spec: and Type have to match the Logstash in the image. type: string monitoring: - description: 'Monitoring enables you to collect and ship log and monitoring + description: Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes - cluster. This feature is under technical preview. To allow Logstash - outputs log to disk and ships the log through Filebeat, the Logstash - docker image requires a customised log4j2.properties to write log - to file. The default log4j2.properties in docker only writes log - to stdout. Issue: https://github.com/elastic/logstash/issues/14941' + cluster. properties: logs: description: Logs holds references to Elasticsearch clusters which diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 35cd60c57d..df6bf48238 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1898,7 +1898,7 @@ LogstashSpec defines the desired state of Logstash | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. | *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs -| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. This feature is under technical preview. To allow Logstash outputs log to disk and ships the log through Filebeat, the Logstash docker image requires a customised log4j2.properties to write log to file. The default log4j2.properties in docker only writes log to stdout. Issue: https://github.com/elastic/logstash/issues/14941 +| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. | *`revisionHistoryLimit`* __integer__ | RevisionHistoryLimit is the number of revisions to retain to allow rollback in the underlying StatefulSet. | *`secureSettings`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-secretsource[$$SecretSource$$] array__ | SecureSettings is a list of references to Kubernetes Secrets containing sensitive configuration options for the Logstash. Secrets data can be then referenced in the Logstash config using the Secret's keys or as specified in `Entries` field of each SecureSetting. diff --git a/pkg/apis/beat/v1beta1/validations.go b/pkg/apis/beat/v1beta1/validations.go index 7f147ee7db..d42148bbb6 100644 --- a/pkg/apis/beat/v1beta1/validations.go +++ b/pkg/apis/beat/v1beta1/validations.go @@ -121,5 +121,5 @@ func checkAssociations(b *Beat) field.ErrorList { } func checkMonitoring(b *Beat) field.ErrorList { - return validations.Validate(b, b.Spec.Version) + return validations.Validate(b, b.Spec.Version, validations.MinStackVersion) } diff --git a/pkg/apis/kibana/v1/webhook.go b/pkg/apis/kibana/v1/webhook.go index a304cfe946..bc0df62098 100644 --- a/pkg/apis/kibana/v1/webhook.go +++ b/pkg/apis/kibana/v1/webhook.go @@ -123,7 +123,7 @@ func checkNoDowngrade(prev, curr *Kibana) field.ErrorList { } func checkMonitoring(k *Kibana) field.ErrorList { - errs := validations.Validate(k, k.Spec.Version) + errs := validations.Validate(k, k.Spec.Version, validations.MinStackVersion) // Kibana must be associated to an Elasticsearch when monitoring metrics are enabled if monitoring.IsMetricsDefined(k) && !k.Spec.ElasticsearchRef.IsDefined() { errs = append(errs, field.Invalid(field.NewPath("spec").Child("elasticsearchRef"), k.Spec.ElasticsearchRef, diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 18ed05cd80..843cfae5df 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -51,9 +51,6 @@ type LogstashSpec struct { // Monitoring enables you to collect and ship log and monitoring data of this Logstash. // Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different // Elasticsearch monitoring clusters running in the same Kubernetes cluster. - // This feature is under technical preview. To allow Logstash outputs log to disk and ships the log through Filebeat, - // the Logstash docker image requires a customised log4j2.properties to write log to file. - // The default log4j2.properties in docker only writes log to stdout. Issue: https://github.com/elastic/logstash/issues/14941 // +kubebuilder:validation:Optional Monitoring commonv1.Monitoring `json:"monitoring,omitempty"` diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go index ca776228c5..579456c4b5 100644 --- a/pkg/apis/logstash/v1alpha1/validations.go +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -14,6 +14,11 @@ import ( ) var ( + // MinStackMonVersion is the minimum version of Logstash to enable Stack Monitoring on an Elastic Stack application. + // This requirement comes from the fact that we configure Logstash to write logs to disk for Filebeat + // via the env var LOG_STYLE available from this version. + MinStackMonVersion = version.MustParse("8.7.0-SNAPSHOT") + defaultChecks = []func(*Logstash) field.ErrorList{ checkNoUnknownFields, checkNameLength, @@ -60,7 +65,7 @@ func checkSingleConfigSource(l *Logstash) field.ErrorList { } func checkMonitoring(l *Logstash) field.ErrorList { - return validations.Validate(l, l.Spec.Version) + return validations.Validate(l, l.Spec.Version, MinStackMonVersion) } func checkAssociations(l *Logstash) field.ErrorList { diff --git a/pkg/apis/logstash/v1alpha1/webhook_test.go b/pkg/apis/logstash/v1alpha1/webhook_test.go index 14ff7839b7..6e949c1c1a 100644 --- a/pkg/apis/logstash/v1alpha1/webhook_test.go +++ b/pkg/apis/logstash/v1alpha1/webhook_test.go @@ -26,7 +26,7 @@ func TestWebhook(t *testing.T) { Object: func(t *testing.T, uid string) []byte { t.Helper() ent := mkLogstash(uid) - ent.Spec.Version = "8.6.0" + ent.Spec.Version = "8.7.0" ent.Spec.Monitoring = commonv1.Monitoring{Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{Name: "esmonname", Namespace: "esmonns"}}}} return serialize(t, ent) }, @@ -38,7 +38,7 @@ func TestWebhook(t *testing.T) { Object: func(t *testing.T, uid string) []byte { t.Helper() ent := mkLogstash(uid) - ent.Spec.Version = "8.6.0" + ent.Spec.Version = "8.7.0" ent.Spec.Monitoring = commonv1.Monitoring{ Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es1monname"}}}, Logs: commonv1.LogsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es2monname"}}}, @@ -58,7 +58,7 @@ func TestWebhook(t *testing.T) { return serialize(t, ent) }, Check: test.ValidationWebhookFailed( - `spec.version: Invalid value: "7.13.0": Unsupported version: version 7.13.0 is lower than the lowest supported version of 8.6.0`, + `spec.version: Invalid value: "7.13.0": Unsupported version for Stack Monitoring. Required >= 8.7.0`, ), }, { @@ -67,7 +67,7 @@ func TestWebhook(t *testing.T) { Object: func(t *testing.T, uid string) []byte { t.Helper() ent := mkLogstash(uid) - ent.Spec.Version = "8.6.0" + ent.Spec.Version = "8.7.0" ent.Spec.Monitoring = commonv1.Monitoring{ Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es1monname", Name: "xx"}}}, Logs: commonv1.LogsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es2monname"}}}, @@ -84,7 +84,7 @@ func TestWebhook(t *testing.T) { Object: func(t *testing.T, uid string) []byte { t.Helper() ent := mkLogstash(uid) - ent.Spec.Version = "8.6.0" + ent.Spec.Version = "8.7.0" ent.Spec.Monitoring = commonv1.Monitoring{ Metrics: commonv1.MetricsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es1monname"}}}, Logs: commonv1.LogsMonitoring{ElasticsearchRefs: []commonv1.ObjectSelector{{SecretName: "es2monname", ServiceName: "xx"}}}, diff --git a/pkg/controller/common/stackmon/validations/validations.go b/pkg/controller/common/stackmon/validations/validations.go index 45a435ebe8..bfc6642cb5 100644 --- a/pkg/controller/common/stackmon/validations/validations.go +++ b/pkg/controller/common/stackmon/validations/validations.go @@ -31,12 +31,12 @@ var ( // Validate validates that the resource version is supported for Stack Monitoring and that there is exactly one // Elasticsearch reference defined to send monitoring data when Stack Monitoring is defined -func Validate(resource monitoring.HasMonitoring, version string) field.ErrorList { +func Validate(resource monitoring.HasMonitoring, version string, minVersion version.Version) field.ErrorList { var errs field.ErrorList if monitoring.IsDefined(resource) { - err := IsSupportedVersion(version) + err := IsSupportedVersion(version, minVersion) if err != nil { - finalMinStackVersion, _ := semver.FinalizeVersion(MinStackVersion.String()) // discards prerelease suffix + finalMinStackVersion, _ := semver.FinalizeVersion(minVersion.String()) // discards prerelease suffix errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), version, fmt.Sprintf(UnsupportedVersionMsg, finalMinStackVersion))) } @@ -55,13 +55,13 @@ func Validate(resource monitoring.HasMonitoring, version string) field.ErrorList } // IsSupportedVersion returns true if the resource version is supported for Stack Monitoring, else returns false -func IsSupportedVersion(v string) error { +func IsSupportedVersion(v string, minVersion version.Version) error { ver, err := version.Parse(v) if err != nil { return err } - if ver.LT(MinStackVersion) { - return fmt.Errorf("unsupported version for Stack Monitoring: required >= %s", MinStackVersion) + if ver.LT(minVersion) { + return fmt.Errorf("unsupported version for Stack Monitoring: required >= %s", minVersion) } return nil } diff --git a/pkg/controller/common/stackmon/validations/validations_test.go b/pkg/controller/common/stackmon/validations/validations_test.go index 0679d08b0c..e3e2c93b81 100644 --- a/pkg/controller/common/stackmon/validations/validations_test.go +++ b/pkg/controller/common/stackmon/validations/validations_test.go @@ -97,7 +97,7 @@ func TestValidate(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - err := Validate(&tc.es, tc.es.Spec.Version) + err := Validate(&tc.es, tc.es.Spec.Version, MinStackVersion) if len(err) > 0 { require.True(t, tc.isErr) } else { diff --git a/pkg/controller/elasticsearch/validation/validations.go b/pkg/controller/elasticsearch/validation/validations.go index cccfbb30ba..570e5ac387 100644 --- a/pkg/controller/elasticsearch/validation/validations.go +++ b/pkg/controller/elasticsearch/validation/validations.go @@ -330,7 +330,7 @@ func currentVersion(current esv1.Elasticsearch) (version.Version, *field.Error) } func validMonitoring(es esv1.Elasticsearch) field.ErrorList { - return stackmon.Validate(&es, es.Spec.Version) + return stackmon.Validate(&es, es.Spec.Version, stackmon.MinStackVersion) } func validAssociations(es esv1.Elasticsearch) field.ErrorList { diff --git a/test/e2e/beat/config_test.go b/test/e2e/beat/config_test.go index b0b439ff6a..39b49a5a75 100644 --- a/test/e2e/beat/config_test.go +++ b/test/e2e/beat/config_test.go @@ -66,7 +66,7 @@ func TestMetricbeatDefaultConfig(t *testing.T) { } { t.Run(tt.name, func(t *testing.T) { // only execute this test on supported versions when stack monitoring is enabled - err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion) + err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion, validations.MinStackVersion) if tt.withStackMonitoring && err != nil { t.SkipNow() } diff --git a/test/e2e/es/stack_monitoring_test.go b/test/e2e/es/stack_monitoring_test.go index 7c83fddc1a..0fd6e5ae74 100644 --- a/test/e2e/es/stack_monitoring_test.go +++ b/test/e2e/es/stack_monitoring_test.go @@ -37,7 +37,7 @@ const nodePort = int32(32767) // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestESStackMonitoring(t *testing.T) { // only execute this test on supported version - err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion) + err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion, validations.MinStackVersion) if err != nil { t.SkipNow() } @@ -68,7 +68,7 @@ func TestExternalESStackMonitoring(t *testing.T) { t.SkipNow() } // only execute this test on supported version - err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion) + err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion, validations.MinStackVersion) if err != nil { t.SkipNow() } diff --git a/test/e2e/kb/stack_monitoring_test.go b/test/e2e/kb/stack_monitoring_test.go index 967e34b62a..bdafacc60b 100644 --- a/test/e2e/kb/stack_monitoring_test.go +++ b/test/e2e/kb/stack_monitoring_test.go @@ -20,7 +20,7 @@ import ( // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestKBStackMonitoring(t *testing.T) { // only execute this test on supported version - err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion) + err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion, validations.MinStackVersion) if err != nil { t.SkipNow() } diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 29b5200f4e..929f3d9cbe 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -7,25 +7,21 @@ package logstash import ( - "fmt" "testing" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" + logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" ) -var ( - MinESVersion = version.MustParse("8.0.0") -) - // TestLogstashStackMonitoring tests that when Logstash is configured with monitoring, its log and metrics are // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestLogstashStackMonitoring(t *testing.T) { // only execute this test on supported version - err := IsSupportedVersion(test.Ctx().ElasticStackVersion) + err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion, logstashv1alpha1.MinStackMonVersion) if err != nil { t.SkipNow() } @@ -37,10 +33,7 @@ func TestLogstashStackMonitoring(t *testing.T) { WithESMasterDataNodes(2, elasticsearch.DefaultResources) monitored := logstash.NewBuilder("test-ls-mon-a"). WithNodeCount(1). - WithMonitoring(metrics.Ref(), logs.Ref()). - //TODO: remove command when Logstash has built with a monitor version of log4j2.properties - // https://github.com/elastic/logstash/issues/14941 - WithCommand([]string{"sh", "-c", "curl -o 'log4j2.properties' 'https://raw.githubusercontent.com/elastic/logstash/445a15489da63e678664eb38dbe8bf64d9a7ffe0/config/log4j2.properties' && mv log4j2.properties config/log4j2.properties && /usr/local/bin/docker-entrypoint"}) + WithMonitoring(metrics.Ref(), logs.Ref()) // checks that the sidecar beats have sent data in the monitoring clusters steps := func(k *test.K8sClient) test.StepList { @@ -49,14 +42,3 @@ func TestLogstashStackMonitoring(t *testing.T) { test.Sequence(nil, steps, metrics, logs, monitored).RunSequential(t) } - -func IsSupportedVersion(v string) error { - ver, err := version.Parse(v) - if err != nil { - return err - } - if ver.LT(MinESVersion) { - return fmt.Errorf("unsupported version for Stack Monitoring: required >= %s", MinESVersion) - } - return nil -} From 7c57920e35ba0ddb9fee12ad10d55b739f8629e3 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 14 Mar 2023 22:32:31 +0000 Subject: [PATCH 110/160] change Pipelines to []commonv1.Config --- config/crds/v1/all-crds.yaml | 2 - .../logstash.k8s.elastic.co_logstashes.yaml | 2 - config/samples/logstash/logstash.yaml | 3 + .../eck-operator-crds/templates/all-crds.yaml | 2 - docs/reference/api-docs.asciidoc | 2 +- pkg/apis/logstash/v1alpha1/logstash_types.go | 2 +- .../logstash/v1alpha1/validations_test.go | 4 +- .../v1alpha1/zz_generated.deepcopy.go | 10 +-- pkg/controller/logstash/pipeline.go | 10 ++- pkg/controller/logstash/pipeline_test.go | 16 ++-- pkg/controller/logstash/pipelines_config.go | 32 ++------ .../logstash/pipelines_config_test.go | 74 ++++++++++++------- .../logstash/pipelines_configref.go | 16 ---- .../logstash/pipelines_configref_test.go | 2 +- test/e2e/logstash/logstash_test.go | 11 ++- test/e2e/logstash/pipeline_test.go | 16 ++-- test/e2e/test/logstash/builder.go | 2 +- 17 files changed, 98 insertions(+), 108 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 72f48a8906..6093f2523a 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9125,8 +9125,6 @@ spec: description: Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. items: - additionalProperties: - type: string type: object type: array x-kubernetes-preserve-unknown-fields: true diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 229b4b2393..33ca0546f9 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -81,8 +81,6 @@ spec: description: Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. items: - additionalProperties: - type: string type: object type: array x-kubernetes-preserve-unknown-fields: true diff --git a/config/samples/logstash/logstash.yaml b/config/samples/logstash/logstash.yaml index 850dd41d9c..fa49c576de 100644 --- a/config/samples/logstash/logstash.yaml +++ b/config/samples/logstash/logstash.yaml @@ -9,6 +9,9 @@ spec: log.level: info api.http.host: "0.0.0.0" queue.type: memory + pipelines: + - pipeline.id: main + config.string: input { exec { command => 'uptime' interval => 10 } } output { stdout{} } podTemplate: spec: containers: diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 4339601682..a7013f6658 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9179,8 +9179,6 @@ spec: description: Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. items: - additionalProperties: - type: string type: object type: array x-kubernetes-preserve-unknown-fields: true diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index 6494d43d84..caf09f55cf 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1896,7 +1896,7 @@ LogstashSpec defines the desired state of Logstash | *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image. | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. -| *`pipelines`* __object array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. +| *`pipelines`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$] array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. | *`pipelinesRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified. | *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index 39fd1c679f..dda2de82a5 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -42,7 +42,7 @@ type LogstashSpec struct { // Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. // +kubebuilder:validation:Optional // +kubebuilder:pruning:PreserveUnknownFields - Pipelines []map[string]string `json:"pipelines,omitempty"` + Pipelines []commonv1.Config `json:"pipelines,omitempty"` // PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. // Logstash pipelines must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] diff --git a/pkg/apis/logstash/v1alpha1/validations_test.go b/pkg/apis/logstash/v1alpha1/validations_test.go index 700e222271..d6ecd75d5a 100644 --- a/pkg/apis/logstash/v1alpha1/validations_test.go +++ b/pkg/apis/logstash/v1alpha1/validations_test.go @@ -155,7 +155,7 @@ func Test_checkSinglePipelineSource(t *testing.T) { name: "pipelinesRef absent, pipelines present", logstash: Logstash{ Spec: LogstashSpec{ - Pipelines: []map[string]string{}, + Pipelines: []commonv1.Config{}, }, }, wantErr: false, @@ -180,7 +180,7 @@ func Test_checkSinglePipelineSource(t *testing.T) { name: "both present", logstash: Logstash{ Spec: LogstashSpec{ - Pipelines: []map[string]string{}, + Pipelines: []commonv1.Config{}, PipelinesRef: &commonv1.ConfigSource{}, }, }, diff --git a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go index e3537aa39e..b512cf0c07 100644 --- a/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go @@ -104,15 +104,9 @@ func (in *LogstashSpec) DeepCopyInto(out *LogstashSpec) { } if in.Pipelines != nil { in, out := &in.Pipelines, &out.Pipelines - *out = make([]map[string]string, len(*in)) + *out = make([]v1.Config, len(*in)) for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } + (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.PipelinesRef != nil { diff --git a/pkg/controller/logstash/pipeline.go b/pkg/controller/logstash/pipeline.go index da78be90ca..0cc2c25156 100644 --- a/pkg/controller/logstash/pipeline.go +++ b/pkg/controller/logstash/pipeline.go @@ -62,7 +62,11 @@ func buildPipeline(params Params) ([]byte, error) { // `pipelineRef` field. func getUserPipeline(params Params) (*PipelinesConfig, error) { if params.Logstash.Spec.Pipelines != nil { - return NewPipelinesConfigFrom(params.Logstash.Spec.Pipelines) + var pipelines []map[string]interface{} + for _, p := range params.Logstash.Spec.Pipelines { + pipelines = append(pipelines, p.Data) + } + return NewPipelinesConfigFrom(pipelines) } return ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) } @@ -70,8 +74,8 @@ func getUserPipeline(params Params) (*PipelinesConfig, error) { func defaultPipeline() *PipelinesConfig { pipelines := []map[string]string{ { - "pipeline.id": "demo", - "config.string": "input { exec { command => \"uptime\" interval => 5 } } output { stdout{} }", + "pipeline.id": "main", + "path.config": "/usr/share/logstash/pipeline", }, } diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go index aa71aa4d8d..916ba37a54 100644 --- a/pkg/controller/logstash/pipeline_test.go +++ b/pkg/controller/logstash/pipeline_test.go @@ -21,17 +21,17 @@ import ( func Test_buildPipeline(t *testing.T) { defaultPipelinesConfig := MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ { - "pipeline.id": "demo", - "config.string": "input { exec { command => \"uptime\" interval => 5 } } output { stdout{} }", + "pipeline.id": "main", + "path.config": "/usr/share/logstash/pipeline", }, }, ) for _, tt := range []struct { name string - pipelines []map[string]string + pipelines []commonv1.Config configRef *commonv1.ConfigSource client k8s.Client want *PipelinesConfig @@ -42,9 +42,11 @@ func Test_buildPipeline(t *testing.T) { want: defaultPipelinesConfig, }, { - name: "pipeline populated", - pipelines: []map[string]string{{"pipeline.id": "main"}}, - want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + name: "pipeline populated", + pipelines: []commonv1.Config{ + {Data: map[string]interface{}{"pipeline.id": "main"}}, + }, + want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), }, { name: "configref populated - no secret", diff --git a/pkg/controller/logstash/pipelines_config.go b/pkg/controller/logstash/pipelines_config.go index 6e7921d3f0..1f1de61466 100644 --- a/pkg/controller/logstash/pipelines_config.go +++ b/pkg/controller/logstash/pipelines_config.go @@ -10,12 +10,12 @@ import ( ucfg "github.com/elastic/go-ucfg" uyaml "github.com/elastic/go-ucfg/yaml" - "github.com/pkg/errors" yaml "gopkg.in/yaml.v3" ) // PipelinesConfig contains configuration for Logstash pipeline ("pipelines.yml"), -// as array of map of string +// `.` in between the key, pipeline.id, is treated as string +// pipelines.yml is expected an array of pipeline definition type PipelinesConfig ucfg.Config // Options are config options for the YAML file. @@ -27,14 +27,11 @@ func NewPipelinesConfig() *PipelinesConfig { } // NewPipelinesConfigFrom creates a new pipeline from spec. -func NewPipelinesConfigFrom(data []map[string]string) (*PipelinesConfig, error) { +func NewPipelinesConfigFrom(data []map[string]interface{}) (*PipelinesConfig, error) { config, err := ucfg.NewFrom(data, Options...) if err != nil { return nil, err } - if err := checkIsArray(config); err != nil { - return nil, err - } return fromConfig(config), nil } @@ -45,9 +42,6 @@ func MustPipelinesConfig(cfg interface{}) *PipelinesConfig { if err != nil { panic(err) } - if err := checkIsArray(config); err != nil { - panic(err) - } return fromConfig(config) } @@ -58,9 +52,6 @@ func ParsePipelinesConfig(yml []byte) (*PipelinesConfig, error) { if err != nil { return nil, err } - if err := checkIsArray(config); err != nil { - return nil, err - } return fromConfig(config), nil } @@ -71,9 +62,6 @@ func MustParsePipelineConfig(yml []byte) *PipelinesConfig { if err != nil { panic(err) } - if err := checkIsArray(config); err != nil { - panic(err) - } return fromConfig(config) } @@ -103,8 +91,8 @@ func (c *PipelinesConfig) Diff(c2 *PipelinesConfig) (bool, error) { return true, fmt.Errorf("empty rhs config %s", c.asUCfg().FlattenedKeys(Options...)) } - var s []map[string]string - var s2 []map[string]string + var s []map[string]interface{} + var s2 []map[string]interface{} err := c.asUCfg().Unpack(&s, Options...) if err != nil { return true, err @@ -118,7 +106,7 @@ func (c *PipelinesConfig) Diff(c2 *PipelinesConfig) (bool, error) { } // diffSlice returns true if the key/value or the sequence of two PipelinesConfig are different -func diffSlice(s1, s2 []map[string]string) (bool, error) { +func diffSlice(s1, s2 []map[string]interface{}) (bool, error) { if len(s1) != len(s2) { return true, fmt.Errorf("array size doesn't match %d, %d", len(s1), len(s2)) } @@ -144,11 +132,3 @@ func (c *PipelinesConfig) asUCfg() *ucfg.Config { func fromConfig(in *ucfg.Config) *PipelinesConfig { return (*PipelinesConfig)(in) } - -// checkIsArray throws error if config is a key/val map -func checkIsArray(config *ucfg.Config) error { - if config.IsDict() { - return errors.New("pipelines should be an array") - } - return nil -} diff --git a/pkg/controller/logstash/pipelines_config_test.go b/pkg/controller/logstash/pipelines_config_test.go index e765b6b8bb..f1107c2ce3 100644 --- a/pkg/controller/logstash/pipelines_config_test.go +++ b/pkg/controller/logstash/pipelines_config_test.go @@ -12,14 +12,16 @@ import ( func TestPipelinesConfig_Render(t *testing.T) { config := MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ { "pipeline.id": "demo", "config.string": "input { exec { command => \"uptime\" interval => 5 } } output { stdout{} }", }, { "pipeline.id": "standard", + "pipeline.workers": 1, "queue.type": "persisted", + "queue.drain": true, "dead_letter_queue.max_bytes": "1024mb", "path.config": "/tmp/logstash/*.config", }, @@ -32,6 +34,8 @@ func TestPipelinesConfig_Render(t *testing.T) { - dead_letter_queue.max_bytes: 1024mb path.config: /tmp/logstash/*.config pipeline.id: standard + pipeline.workers: 1 + queue.drain: true queue.type: persisted `) require.Equal(t, string(expected), string(output)) @@ -54,7 +58,7 @@ func TestParsePipelinesConfig(t *testing.T) { name: "simple input", input: "- pipeline.id: demo\n config.string: input { exec { command => \"${ENV}\" interval => 5 } }", want: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ { "pipeline.id": "demo", "config.string": "input { exec { command => \"${ENV}\" interval => 5 } }", @@ -63,11 +67,37 @@ func TestParsePipelinesConfig(t *testing.T) { ), wantErr: false, }, + { + name: "number input", + input: "- pipeline.id: main\n pipeline.workers: 4", + want: MustPipelinesConfig( + []map[string]interface{}{ + { + "pipeline.id": "main", + "pipeline.workers": 4, + }, + }, + ), + wantErr: false, + }, + { + name: "boolean input", + input: "- pipeline.id: main\n queue.drain: false", + want: MustPipelinesConfig( + []map[string]interface{}{ + { + "pipeline.id": "main", + "queue.drain": false, + }, + }, + ), + wantErr: false, + }, { name: "trim whitespaces between key and value", input: "- pipeline.id : demo \n path.config : /tmp/logstash/*.config ", want: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ { "pipeline.id": "demo", "path.config": "/tmp/logstash/*.config", @@ -85,7 +115,7 @@ func TestParsePipelinesConfig(t *testing.T) { name: "trim newlines", input: "- pipeline.id: demo \n\n- pipeline.id: demo2 \n", want: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"pipeline.id": "demo"}, {"pipeline.id": "demo2"}, }, @@ -96,7 +126,7 @@ func TestParsePipelinesConfig(t *testing.T) { name: "ignore comments", input: "- pipeline.id: demo \n#this is a comment\n pipeline.workers: \"1\"\n", want: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ { "pipeline.id": "demo", "pipeline.workers": "1", @@ -109,7 +139,7 @@ func TestParsePipelinesConfig(t *testing.T) { name: "support quotes", input: `- "pipeline.id": "quote"`, want: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"pipeline.id": "quote"}, }, ), @@ -119,18 +149,12 @@ func TestParsePipelinesConfig(t *testing.T) { name: "support special characters", input: `- config.string: "${node.ip}%.:=+è! /"`, want: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"config.string": `${node.ip}%.:=+è! /`}, }, ), wantErr: false, }, - { - name: "invalid entry", - input: "config: not an array", - want: nil, - wantErr: true, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -172,7 +196,7 @@ func TestPipelinesConfig_Diff(t *testing.T) { name: "lhs nil", c: nil, c2: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"a": "a"}, {"b": "b"}, }, @@ -182,7 +206,7 @@ func TestPipelinesConfig_Diff(t *testing.T) { { name: "rhs nil", c: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"a": "a"}, }, ), @@ -192,13 +216,13 @@ func TestPipelinesConfig_Diff(t *testing.T) { { name: "same multi key value", c: MustPipelinesConfig( - []map[string]string{ - {"a": "a", "b": "b"}, + []map[string]interface{}{ + {"a": "a", "b": "b", "c": 1, "d": true}, }, ), c2: MustPipelinesConfig( - []map[string]string{ - {"b": "b", "a": "a"}, + []map[string]interface{}{ + {"c": 1, "b": "b", "a": "a", "d": true}, }, ), wantDiff: false, @@ -206,12 +230,12 @@ func TestPipelinesConfig_Diff(t *testing.T) { { name: "different value", c: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"a": "a"}, }, ), c2: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"a": "b"}, }, ), @@ -220,12 +244,12 @@ func TestPipelinesConfig_Diff(t *testing.T) { { name: "array size different", c: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"a": "a"}, }, ), c2: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"a": "a"}, {"a": "a"}, }, @@ -235,13 +259,13 @@ func TestPipelinesConfig_Diff(t *testing.T) { { name: "respects list order", c: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"a": "a"}, {"b": "b"}, }, ), c2: MustPipelinesConfig( - []map[string]string{ + []map[string]interface{}{ {"b": "b"}, {"a": "a"}, }, diff --git a/pkg/controller/logstash/pipelines_configref.go b/pkg/controller/logstash/pipelines_configref.go index be59347152..49d6c10bdd 100644 --- a/pkg/controller/logstash/pipelines_configref.go +++ b/pkg/controller/logstash/pipelines_configref.go @@ -7,14 +7,9 @@ package logstash import ( "fmt" - "github.com/pkg/errors" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/events" - commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" @@ -38,16 +33,5 @@ func ParseConfigRef( return nil, err } - if parsed != nil { - if err := checkIsArray(parsed); err != nil { - resourceMeta, _ := meta.Accessor(resource) - namespace := resourceMeta.GetNamespace() - - msg := fmt.Sprintf("unable to parse %s in configRef secret %s/%s", secretKey, namespace, configRef.SecretName) - driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg) - return nil, errors.Wrap(err, msg) - } - } - return (*PipelinesConfig)(parsed), nil } diff --git a/pkg/controller/logstash/pipelines_configref_test.go b/pkg/controller/logstash/pipelines_configref_test.go index 8cda53d5d7..c40dc49955 100644 --- a/pkg/controller/logstash/pipelines_configref_test.go +++ b/pkg/controller/logstash/pipelines_configref_test.go @@ -147,7 +147,7 @@ func TestParseConfigRef(t *testing.T) { &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, Data: map[string][]byte{ - "configFile.yml": []byte(`"this.is": "an invalid array"`), + "configFile.yml": []byte("this.is invalid config"), }}, }, wantErr: true, diff --git a/test/e2e/logstash/logstash_test.go b/test/e2e/logstash/logstash_test.go index 573af6b5f6..7f56b411b2 100644 --- a/test/e2e/logstash/logstash_test.go +++ b/test/e2e/logstash/logstash_test.go @@ -9,11 +9,11 @@ package logstash import ( "testing" - corev1 "k8s.io/api/core/v1" commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/logstash" + corev1 "k8s.io/api/core/v1" ) func TestSingleLogstash(t *testing.T) { @@ -25,7 +25,7 @@ func TestSingleLogstash(t *testing.T) { func TestLogstashWithCustomService(t *testing.T) { name := "test-multiple-custom-logstash" - service := logstashv1alpha1.LogstashService { + service := logstashv1alpha1.LogstashService{ Name: "test", Service: commonv1.ServiceTemplate{ Spec: corev1.ServiceSpec{ @@ -44,7 +44,7 @@ func TestLogstashWithCustomService(t *testing.T) { func TestLogstashWithReworkedApiService(t *testing.T) { name := "test-multiple-custom-logstash" - service := logstashv1alpha1.LogstashService { + service := logstashv1alpha1.LogstashService{ Name: "api", Service: commonv1.ServiceTemplate{ Spec: corev1.ServiceSpec{ @@ -63,7 +63,7 @@ func TestLogstashWithReworkedApiService(t *testing.T) { func TestLogstashWithCustomServiceAndAmendedApi(t *testing.T) { name := "test-multiple-custom-logstash" - customService := logstashv1alpha1.LogstashService { + customService := logstashv1alpha1.LogstashService{ Name: "test", Service: commonv1.ServiceTemplate{ Spec: corev1.ServiceSpec{ @@ -74,7 +74,7 @@ func TestLogstashWithCustomServiceAndAmendedApi(t *testing.T) { }, } - apiService := logstashv1alpha1.LogstashService { + apiService := logstashv1alpha1.LogstashService{ Name: "api", Service: commonv1.ServiceTemplate{ Spec: corev1.ServiceSpec{ @@ -92,7 +92,6 @@ func TestLogstashWithCustomServiceAndAmendedApi(t *testing.T) { test.Sequence(nil, test.EmptySteps, logstashBuilder).RunSequential(t) } - func TestMultipleLogstashes(t *testing.T) { name := "test-multiple-logstashes" logstashBuilder := logstash.NewBuilder(name). diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go index 685945abab..281116e6c8 100644 --- a/test/e2e/logstash/pipeline_test.go +++ b/test/e2e/logstash/pipeline_test.go @@ -27,6 +27,8 @@ func TestPipelineConfigRefLogstash(t *testing.T) { StringData: map[string]string{ "pipelines.yml": ` - pipeline.id: generator + pipeline.workers: 1 + queue.drain: false config.string: input { generator {} } filter { sleep { time => 10 } } output { stdout { codec => dots } } - pipeline.id: demo config.string: input { stdin{} } output { stdout{} }`, @@ -95,14 +97,18 @@ func TestPipelineConfigLogstash(t *testing.T) { b := logstash.NewBuilder(name). WithNodeCount(1). - WithPipelines([]map[string]string{ + WithPipelines([]commonv1.Config{ { - "pipeline.id": "split", - "path.config": mountPath, + Data: map[string]interface{}{ + "pipeline.id": "split", + "path.config": mountPath, + }, }, { - "pipeline.id": "demo", - "config.string": "input { stdin{} } output { stdout{} }", + Data: map[string]interface{}{ + "pipeline.id": "demo", + "config.string": "input { stdin{} } output { stdout{} }", + }, }, }). WithVolumes(corev1.Volume{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index d75a6c2a37..7904a5b786 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -118,7 +118,7 @@ func (b Builder) WithServices(services ...logstashv1alpha1.LogstashService) Buil return b } -func (b Builder) WithPipelines(pipelines []map[string]string) Builder { +func (b Builder) WithPipelines(pipelines []commonv1.Config) Builder { b.Logstash.Spec.Pipelines = pipelines return b } From 092508e7fb61664276f97397bcd81a0fc5e405ad Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 15 Mar 2023 21:07:45 +0000 Subject: [PATCH 111/160] remove pipelinesref watch --- pkg/controller/logstash/logstash_controller.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go index 2eea84378d..3b496744ba 100644 --- a/pkg/controller/logstash/logstash_controller.go +++ b/pkg/controller/logstash/logstash_controller.go @@ -196,5 +196,6 @@ func (r *ReconcileLogstash) validate(ctx context.Context, logstash logstashv1alp func (r *ReconcileLogstash) onDelete(ctx context.Context, obj types.NamespacedName) error { r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj)) r.dynamicWatches.Secrets.RemoveHandlerForKey(common.ConfigRefWatchName(obj)) + r.dynamicWatches.Secrets.RemoveHandlerForKey(PipelinesRefWatchName(obj)) return reconciler.GarbageCollectSoftOwnedSecrets(ctx, r.Client, obj, logstashv1alpha1.Kind) } From 9c8c99915ef921e32d591d8cfe6648910d1b55f9 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Mon, 20 Mar 2023 17:10:35 +0000 Subject: [PATCH 112/160] Update test/e2e/logstash/stack_monitoring_test.go Co-authored-by: Michael Morello --- test/e2e/logstash/stack_monitoring_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 929f3d9cbe..37bb82fe71 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -21,8 +21,7 @@ import ( // correctly delivered to the referenced monitoring Elasticsearch clusters. func TestLogstashStackMonitoring(t *testing.T) { // only execute this test on supported version - err := validations.IsSupportedVersion(test.Ctx().ElasticStackVersion, logstashv1alpha1.MinStackMonVersion) - if err != nil { + if version.MustParse(test.Ctx().ElasticStackVersion).LT(logstashv1alpha1.MinStackMonVersion) { t.SkipNow() } From 76d8756e59303f5777f14f174d6e168feb761dae Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Mon, 20 Mar 2023 17:10:58 +0000 Subject: [PATCH 113/160] Update test/e2e/test/logstash/builder.go Co-authored-by: Michael Morello --- test/e2e/test/logstash/builder.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index cd58857a0c..80e041b685 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -131,15 +131,7 @@ func (b Builder) WithCommand(command []string) Builder { } func (b Builder) GetMetricsIndexPattern() string { - v := version.MustParse(test.Ctx().ElasticStackVersion) - if v.GTE(version.MinFor(8, 3, 0)) { - return ".monitoring-logstash-8-mb" - } - if v.GTE(version.MinFor(8, 0, 0)) { - return fmt.Sprintf("metricbeat-%d.%d.%d*", v.Major, v.Minor, v.Patch) - } - - return ".monitoring-logstash-*" + return ".monitoring-logstash-8-mb" } func (b Builder) Name() string { From 809b32afebb84730665ac3d24fb4cbd350eb5c5a Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Mon, 20 Mar 2023 17:11:12 +0000 Subject: [PATCH 114/160] Update test/e2e/test/logstash/builder.go Co-authored-by: Michael Morello --- test/e2e/test/logstash/builder.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 80e041b685..72978f7bd2 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -125,11 +125,6 @@ func (b Builder) WithMonitoring(metricsESRef commonv1.ObjectSelector, logsESRef return b } -func (b Builder) WithCommand(command []string) Builder { - b.Logstash.Spec.PodTemplate.Spec.Containers = []corev1.Container{{Name: "logstash", Command: command}} - return b -} - func (b Builder) GetMetricsIndexPattern() string { return ".monitoring-logstash-8-mb" } From da2f36e8052043590103220ba47ea859e23255e1 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Mon, 20 Mar 2023 18:23:00 +0000 Subject: [PATCH 115/160] fix comment --- pkg/controller/common/stackmon/validations/validations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/common/stackmon/validations/validations.go b/pkg/controller/common/stackmon/validations/validations.go index bfc6642cb5..c83c2a865e 100644 --- a/pkg/controller/common/stackmon/validations/validations.go +++ b/pkg/controller/common/stackmon/validations/validations.go @@ -54,7 +54,7 @@ func Validate(resource monitoring.HasMonitoring, version string, minVersion vers return errs } -// IsSupportedVersion returns true if the resource version is supported for Stack Monitoring, else returns false +// IsSupportedVersion returns error if the resource version is not supported for Stack Monitoring func IsSupportedVersion(v string, minVersion version.Version) error { ver, err := version.Parse(v) if err != nil { From 94e7c75632873bda3b46fe5c173b7451124ab6eb Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Mon, 20 Mar 2023 18:23:13 +0000 Subject: [PATCH 116/160] fix lint and import --- test/e2e/logstash/stack_monitoring_test.go | 2 +- test/e2e/test/logstash/builder.go | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/test/e2e/logstash/stack_monitoring_test.go b/test/e2e/logstash/stack_monitoring_test.go index 37bb82fe71..599b785f3b 100644 --- a/test/e2e/logstash/stack_monitoring_test.go +++ b/test/e2e/logstash/stack_monitoring_test.go @@ -7,10 +7,10 @@ package logstash import ( + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "testing" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/checks" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test/elasticsearch" diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 72978f7bd2..b92fea66a4 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -5,9 +5,6 @@ package logstash import ( - "fmt" - - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" From 218a1e95100a2757040228dd590bb7b2e15f7e7d Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Mon, 20 Mar 2023 18:51:40 +0000 Subject: [PATCH 117/160] refactor CheckBeatSidecars --- test/e2e/test/beat/builder.go | 6 ++++++ test/e2e/test/checks/monitoring.go | 6 ++++-- test/e2e/test/elasticsearch/builder.go | 5 +++++ test/e2e/test/k8s_client.go | 10 +++++++--- test/e2e/test/kibana/builder.go | 5 +++++ test/e2e/test/logstash/builder.go | 5 +++++ 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/test/e2e/test/beat/builder.go b/test/e2e/test/beat/builder.go index 695adf1b25..5941d30277 100644 --- a/test/e2e/test/beat/builder.go +++ b/test/e2e/test/beat/builder.go @@ -360,3 +360,9 @@ func (b Builder) GetLogsCluster() *types.NamespacedName { metricsCluster := b.Beat.Spec.Monitoring.Logs.ElasticsearchRefs[0].NamespacedName() return &metricsCluster } + +// GetTypeLabel The implementation is for the compatibility of stack monitoring test +// beat does not have such test and only returns a static string "beat" +func (b Builder) GetTypeLabel() string { + return "beat" +} diff --git a/test/e2e/test/checks/monitoring.go b/test/e2e/test/checks/monitoring.go index 604e753cf6..a3c3c689a9 100644 --- a/test/e2e/test/checks/monitoring.go +++ b/test/e2e/test/checks/monitoring.go @@ -27,6 +27,7 @@ type Monitored interface { GetMetricsIndexPattern() string GetLogsCluster() *types.NamespacedName GetMetricsCluster() *types.NamespacedName + GetTypeLabel() string } func MonitoredSteps(monitored Monitored, k8sClient *test.K8sClient) test.StepList { @@ -63,9 +64,10 @@ func (c stackMonitoringChecks) CheckBeatSidecars() test.Step { Name: "Check that beat sidecars are running", Test: test.Eventually(func() error { pods, err := c.k8sClient.GetPods( - test.ESPodListOptions( + test.StackPodListOptions( c.monitored.Namespace(), - c.monitored.Name())..., + c.monitored.Name(), + c.monitored.GetTypeLabel())..., ) if err != nil { return err diff --git a/test/e2e/test/elasticsearch/builder.go b/test/e2e/test/elasticsearch/builder.go index 19eaf85366..99234d4683 100644 --- a/test/e2e/test/elasticsearch/builder.go +++ b/test/e2e/test/elasticsearch/builder.go @@ -20,6 +20,7 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/pointer" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" @@ -536,6 +537,10 @@ func (b Builder) GetMetricsCluster() *types.NamespacedName { return &metricsCluster } +func (b Builder) GetTypeLabel() string { + return label.Type +} + // -- Helper functions func (b Builder) RuntimeObjects() []client.Object { diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index f3b4d13ddf..88333a2662 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -383,10 +383,14 @@ func (k K8sClient) CreateOrUpdate(objs ...client.Object) error { } func ESPodListOptions(esNamespace, esName string) []k8sclient.ListOption { - ns := k8sclient.InNamespace(esNamespace) + return StackPodListOptions(esNamespace, esName, label.Type) +} + +func StackPodListOptions(namespace, name, typeLabel string) []k8sclient.ListOption { + ns := k8sclient.InNamespace(namespace) matchLabels := k8sclient.MatchingLabels(map[string]string{ - commonv1.TypeLabelName: label.Type, - label.ClusterNameLabelName: esName, + commonv1.TypeLabelName: typeLabel, + label.ClusterNameLabelName: name, }) return []k8sclient.ListOption{ns, matchLabels} } diff --git a/test/e2e/test/kibana/builder.go b/test/e2e/test/kibana/builder.go index 9c71332aaf..b140b0d1f1 100644 --- a/test/e2e/test/kibana/builder.go +++ b/test/e2e/test/kibana/builder.go @@ -16,6 +16,7 @@ import ( commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" + kbctl "github.com/elastic/cloud-on-k8s/v2/pkg/controller/kibana" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -276,6 +277,10 @@ func (b Builder) GetMetricsCluster() *types.NamespacedName { return &metricsCluster } +func (b Builder) GetTypeLabel() string { + return kbctl.Type +} + // -- test.Subject impl func (b Builder) NSN() types.NamespacedName { diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index b92fea66a4..18443e845f 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -5,6 +5,7 @@ package logstash import ( + lsctl "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" @@ -150,6 +151,10 @@ func (b Builder) GetMetricsCluster() *types.NamespacedName { return &metricsCluster } +func (b Builder) GetTypeLabel() string { + return lsctl.TypeLabelValue +} + func (b Builder) NSN() types.NamespacedName { return k8s.ExtractNamespacedName(&b.Logstash) } From 21e3c5b71bd0ad62e18f48e86f04f0670950ed2a Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Mon, 20 Mar 2023 20:55:45 +0000 Subject: [PATCH 118/160] fix lint --- test/e2e/test/logstash/builder.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 18443e845f..3774821730 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -5,12 +5,13 @@ package logstash import ( - lsctl "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" "sigs.k8s.io/controller-runtime/pkg/client" + lsctl "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" From 53ed2df7eb5a2913618c2b1cd719e8cb0980ae92 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 21 Mar 2023 18:35:12 +0000 Subject: [PATCH 119/160] Update pkg/controller/logstash/driver.go Co-authored-by: Michael Morello --- pkg/controller/logstash/driver.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/controller/logstash/driver.go b/pkg/controller/logstash/driver.go index 8fe5caea18..9fec5b89e4 100644 --- a/pkg/controller/logstash/driver.go +++ b/pkg/controller/logstash/driver.go @@ -80,8 +80,7 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log configHash := fnv.New32a() // reconcile beats config secrets if Stack Monitoring is defined - err = stackmon.ReconcileConfigSecrets(params.Context, params.Client, params.Logstash) - if err != nil { + if err := stackmon.ReconcileConfigSecrets(params.Context, params.Client, params.Logstash); err != nil { return results.WithError(err), params.Status } From ea84d94e993c3077730b1c54251e88ad9c63cfff Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 21 Mar 2023 18:35:33 +0000 Subject: [PATCH 120/160] Update pkg/apis/logstash/v1alpha1/validations.go Co-authored-by: Michael Morello --- pkg/apis/logstash/v1alpha1/validations.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/apis/logstash/v1alpha1/validations.go b/pkg/apis/logstash/v1alpha1/validations.go index 579456c4b5..5cddf8ca6e 100644 --- a/pkg/apis/logstash/v1alpha1/validations.go +++ b/pkg/apis/logstash/v1alpha1/validations.go @@ -7,9 +7,8 @@ package v1alpha1 import ( "k8s.io/apimachinery/pkg/util/validation/field" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" - commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/stackmon/validations" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" ) From 14563e122f06cd4c95f5b38d9f97b0838b3e0e75 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Mar 2023 18:45:39 +0000 Subject: [PATCH 121/160] Revert "refactor CheckBeatSidecars" This reverts commit 218a1e95100a2757040228dd590bb7b2e15f7e7d. --- test/e2e/test/beat/builder.go | 6 ------ test/e2e/test/checks/monitoring.go | 6 ++---- test/e2e/test/elasticsearch/builder.go | 5 ----- test/e2e/test/k8s_client.go | 10 +++------- test/e2e/test/kibana/builder.go | 5 ----- test/e2e/test/logstash/builder.go | 4 ---- 6 files changed, 5 insertions(+), 31 deletions(-) diff --git a/test/e2e/test/beat/builder.go b/test/e2e/test/beat/builder.go index 5941d30277..695adf1b25 100644 --- a/test/e2e/test/beat/builder.go +++ b/test/e2e/test/beat/builder.go @@ -360,9 +360,3 @@ func (b Builder) GetLogsCluster() *types.NamespacedName { metricsCluster := b.Beat.Spec.Monitoring.Logs.ElasticsearchRefs[0].NamespacedName() return &metricsCluster } - -// GetTypeLabel The implementation is for the compatibility of stack monitoring test -// beat does not have such test and only returns a static string "beat" -func (b Builder) GetTypeLabel() string { - return "beat" -} diff --git a/test/e2e/test/checks/monitoring.go b/test/e2e/test/checks/monitoring.go index a3c3c689a9..604e753cf6 100644 --- a/test/e2e/test/checks/monitoring.go +++ b/test/e2e/test/checks/monitoring.go @@ -27,7 +27,6 @@ type Monitored interface { GetMetricsIndexPattern() string GetLogsCluster() *types.NamespacedName GetMetricsCluster() *types.NamespacedName - GetTypeLabel() string } func MonitoredSteps(monitored Monitored, k8sClient *test.K8sClient) test.StepList { @@ -64,10 +63,9 @@ func (c stackMonitoringChecks) CheckBeatSidecars() test.Step { Name: "Check that beat sidecars are running", Test: test.Eventually(func() error { pods, err := c.k8sClient.GetPods( - test.StackPodListOptions( + test.ESPodListOptions( c.monitored.Namespace(), - c.monitored.Name(), - c.monitored.GetTypeLabel())..., + c.monitored.Name())..., ) if err != nil { return err diff --git a/test/e2e/test/elasticsearch/builder.go b/test/e2e/test/elasticsearch/builder.go index 99234d4683..19eaf85366 100644 --- a/test/e2e/test/elasticsearch/builder.go +++ b/test/e2e/test/elasticsearch/builder.go @@ -20,7 +20,6 @@ import ( esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/container" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/pointer" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" @@ -537,10 +536,6 @@ func (b Builder) GetMetricsCluster() *types.NamespacedName { return &metricsCluster } -func (b Builder) GetTypeLabel() string { - return label.Type -} - // -- Helper functions func (b Builder) RuntimeObjects() []client.Object { diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index 88333a2662..f3b4d13ddf 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -383,14 +383,10 @@ func (k K8sClient) CreateOrUpdate(objs ...client.Object) error { } func ESPodListOptions(esNamespace, esName string) []k8sclient.ListOption { - return StackPodListOptions(esNamespace, esName, label.Type) -} - -func StackPodListOptions(namespace, name, typeLabel string) []k8sclient.ListOption { - ns := k8sclient.InNamespace(namespace) + ns := k8sclient.InNamespace(esNamespace) matchLabels := k8sclient.MatchingLabels(map[string]string{ - commonv1.TypeLabelName: typeLabel, - label.ClusterNameLabelName: name, + commonv1.TypeLabelName: label.Type, + label.ClusterNameLabelName: esName, }) return []k8sclient.ListOption{ns, matchLabels} } diff --git a/test/e2e/test/kibana/builder.go b/test/e2e/test/kibana/builder.go index b140b0d1f1..9c71332aaf 100644 --- a/test/e2e/test/kibana/builder.go +++ b/test/e2e/test/kibana/builder.go @@ -16,7 +16,6 @@ import ( commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" kbv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" - kbctl "github.com/elastic/cloud-on-k8s/v2/pkg/controller/kibana" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" @@ -277,10 +276,6 @@ func (b Builder) GetMetricsCluster() *types.NamespacedName { return &metricsCluster } -func (b Builder) GetTypeLabel() string { - return kbctl.Type -} - // -- test.Subject impl func (b Builder) NSN() types.NamespacedName { diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 3774821730..a6a472b145 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -152,10 +152,6 @@ func (b Builder) GetMetricsCluster() *types.NamespacedName { return &metricsCluster } -func (b Builder) GetTypeLabel() string { - return lsctl.TypeLabelValue -} - func (b Builder) NSN() types.NamespacedName { return k8s.ExtractNamespacedName(&b.Logstash) } From 62463ac9f9dd2f239af2450b6d1a9f4a78b937b0 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Mar 2023 18:51:34 +0000 Subject: [PATCH 122/160] rename CheckBeatSidecars to CheckBeatSidecarsInElasticsearch --- test/e2e/test/checks/monitoring.go | 4 ++-- test/e2e/test/logstash/builder.go | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/test/e2e/test/checks/monitoring.go b/test/e2e/test/checks/monitoring.go index 604e753cf6..d2ab0f3ff4 100644 --- a/test/e2e/test/checks/monitoring.go +++ b/test/e2e/test/checks/monitoring.go @@ -52,13 +52,13 @@ type stackMonitoringChecks struct { func (c stackMonitoringChecks) Steps() test.StepList { return test.StepList{ - c.CheckBeatSidecars(), + c.CheckBeatSidecarsInElasticsearch(), c.CheckMonitoringMetricsIndex(), c.CheckFilebeatIndex(), } } -func (c stackMonitoringChecks) CheckBeatSidecars() test.Step { +func (c stackMonitoringChecks) CheckBeatSidecarsInElasticsearch() test.Step { return test.Step{ Name: "Check that beat sidecars are running", Test: test.Eventually(func() error { diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index a6a472b145..e88d2ba3c8 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -5,19 +5,16 @@ package logstash import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/rand" - "sigs.k8s.io/controller-runtime/pkg/client" - - lsctl "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash" - commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" ) type Builder struct { From 85bc3e20dac7bc0af52b1dbcd9eebf19128390d3 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Mar 2023 19:00:02 +0000 Subject: [PATCH 123/160] lint --- test/e2e/test/logstash/builder.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index e88d2ba3c8..b92fea66a4 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -5,16 +5,17 @@ package logstash import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" + commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/cmd/run" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/rand" - "sigs.k8s.io/controller-runtime/pkg/client" ) type Builder struct { From 44c9afa5b99bf96cbd2a24481ea58859b0ab9418 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Mar 2023 19:50:53 +0000 Subject: [PATCH 124/160] add monitoring status check --- test/e2e/test/logstash/checks.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 84ebad6019..93a4b3964d 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -9,11 +9,11 @@ import ( "encoding/json" "fmt" - corev1 "k8s.io/api/core/v1" - + v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" + corev1 "k8s.io/api/core/v1" ) type logstashStatus struct { @@ -51,6 +51,7 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { logstash.Status.ObservedGeneration = 0 + // pod status expected := logstashv1alpha1.LogstashStatus{ ExpectedNodes: b.Logstash.Spec.Count, AvailableNodes: b.Logstash.Spec.Count, @@ -62,6 +63,19 @@ func CheckStatus(b Builder, k *test.K8sClient) test.Step { (logstash.Status.Version != expected.Version) { return fmt.Errorf("expected status %+v but got %+v", expected, logstash.Status) } + + // monitoring status + expectedMonitoringInStatus := len(logstash.Spec.Monitoring.Metrics.ElasticsearchRefs) + len(logstash.Spec.Monitoring.Metrics.ElasticsearchRefs) + actualMonitoringInStatus := len(logstash.Status.MonitoringAssociationStatus) + if expectedMonitoringInStatus != actualMonitoringInStatus { + return fmt.Errorf("expected %d monitoring associations in status but got %d", expectedMonitoringInStatus, actualMonitoringInStatus) + } + for a, s := range logstash.Status.MonitoringAssociationStatus { + if s != v1.AssociationEstablished { + return fmt.Errorf("monitoring association %s has status %s ", a, s) + } + } + return nil }), } From c9d059b8a049f044eb3be5ccd2d48fc54cfc448b Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 21 Mar 2023 21:24:45 +0000 Subject: [PATCH 125/160] lint --- test/e2e/test/logstash/checks.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 93a4b3964d..9d5e900498 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -9,11 +9,12 @@ import ( "encoding/json" "fmt" + corev1 "k8s.io/api/core/v1" + v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" - corev1 "k8s.io/api/core/v1" ) type logstashStatus struct { From 0cd242e112833eb4810b0632a4e21f6382c4c3a5 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Mar 2023 18:16:08 +0000 Subject: [PATCH 126/160] rename configRef to pipelinesRef --- pkg/controller/logstash/config.go | 2 +- pkg/controller/logstash/pipeline.go | 2 +- pkg/controller/logstash/pipeline_test.go | 22 +++---- .../logstash/pipelines_configref.go | 10 +-- .../logstash/pipelines_configref_test.go | 62 +++++++++---------- 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index 5a0409dbb6..cb6cbc91a1 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -63,7 +63,7 @@ func buildConfig(params Params) ([]byte, error) { } // getUserConfig extracts the config either from the spec `config` field or from the Secret referenced by spec -// `configRef` field. +// `pipelinesRef` field. func getUserConfig(params Params) (*settings.CanonicalConfig, error) { if params.Logstash.Spec.Config != nil { return settings.NewCanonicalConfigFrom(params.Logstash.Spec.Config.Data) diff --git a/pkg/controller/logstash/pipeline.go b/pkg/controller/logstash/pipeline.go index 0cc2c25156..532a700385 100644 --- a/pkg/controller/logstash/pipeline.go +++ b/pkg/controller/logstash/pipeline.go @@ -68,7 +68,7 @@ func getUserPipeline(params Params) (*PipelinesConfig, error) { } return NewPipelinesConfigFrom(pipelines) } - return ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) + return ParsePipelinesRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) } func defaultPipeline() *PipelinesConfig { diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go index 916ba37a54..f078accead 100644 --- a/pkg/controller/logstash/pipeline_test.go +++ b/pkg/controller/logstash/pipeline_test.go @@ -30,12 +30,12 @@ func Test_buildPipeline(t *testing.T) { ) for _, tt := range []struct { - name string - pipelines []commonv1.Config - configRef *commonv1.ConfigSource - client k8s.Client - want *PipelinesConfig - wantErr bool + name string + pipelines []commonv1.Config + pipelinesRef *commonv1.ConfigSource + client k8s.Client + want *PipelinesConfig + wantErr bool }{ { name: "no user pipeline", @@ -50,7 +50,7 @@ func Test_buildPipeline(t *testing.T) { }, { name: "configref populated - no secret", - configRef: &commonv1.ConfigSource{ + pipelinesRef: &commonv1.ConfigSource{ SecretRef: commonv1.SecretRef{ SecretName: "my-secret-pipeline", }, @@ -61,7 +61,7 @@ func Test_buildPipeline(t *testing.T) { }, { name: "configref populated - no secret key", - configRef: &commonv1.ConfigSource{ + pipelinesRef: &commonv1.ConfigSource{ SecretRef: commonv1.SecretRef{ SecretName: "my-secret-pipeline", }, @@ -76,7 +76,7 @@ func Test_buildPipeline(t *testing.T) { }, { name: "configref populated - malformed config", - configRef: &commonv1.ConfigSource{ + pipelinesRef: &commonv1.ConfigSource{ SecretRef: commonv1.SecretRef{ SecretName: "my-secret-pipeline-2", }, @@ -92,7 +92,7 @@ func Test_buildPipeline(t *testing.T) { }, { name: "configref populated", - configRef: &commonv1.ConfigSource{ + pipelinesRef: &commonv1.ConfigSource{ SecretRef: commonv1.SecretRef{ SecretName: "my-secret-pipeline-2", }, @@ -115,7 +115,7 @@ func Test_buildPipeline(t *testing.T) { Logstash: logstashv1alpha1.Logstash{ Spec: logstashv1alpha1.LogstashSpec{ Pipelines: tt.pipelines, - PipelinesRef: tt.configRef, + PipelinesRef: tt.pipelinesRef, }, }, } diff --git a/pkg/controller/logstash/pipelines_configref.go b/pkg/controller/logstash/pipelines_configref.go index 49d6c10bdd..b2c28e1360 100644 --- a/pkg/controller/logstash/pipelines_configref.go +++ b/pkg/controller/logstash/pipelines_configref.go @@ -15,20 +15,20 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" ) -// PipelinesRefWatchName returns the name of the watch registered on the secret referenced in `configRef`. +// PipelinesRefWatchName returns the name of the watch registered on the secret referenced in `pipelinesRef`. func PipelinesRefWatchName(resource types.NamespacedName) string { return fmt.Sprintf("%s-%s-pipelinesref", resource.Namespace, resource.Name) } -// ParseConfigRef retrieves the content of a secret referenced in `configRef`, sets up dynamic watches for that secret, +// ParsePipelinesRef retrieves the content of a secret referenced in `pipelinesRef`, sets up dynamic watches for that secret, // and parses the secret content into a PipelinesConfig. -func ParseConfigRef( +func ParsePipelinesRef( driver driver.Interface, resource runtime.Object, - configRef *commonv1.ConfigSource, + pipelinesRef *commonv1.ConfigSource, secretKey string, // retrieve config data from that entry in the secret ) (*PipelinesConfig, error) { - parsed, err := common.ParseConfigRefToConfig(driver, resource, configRef, secretKey, PipelinesRefWatchName, Options) + parsed, err := common.ParseConfigRefToConfig(driver, resource, pipelinesRef, secretKey, PipelinesRefWatchName, Options) if err != nil { return nil, err } diff --git a/pkg/controller/logstash/pipelines_configref_test.go b/pkg/controller/logstash/pipelines_configref_test.go index c40dc49955..42c86c0c9f 100644 --- a/pkg/controller/logstash/pipelines_configref_test.go +++ b/pkg/controller/logstash/pipelines_configref_test.go @@ -40,7 +40,7 @@ func (f fakeDriver) Recorder() record.EventRecorder { var _ driver.Interface = fakeDriver{} -func TestParseConfigRef(t *testing.T) { +func TestParsePipelinesRef(t *testing.T) { // any resource Kind would work here (eg. Beat, EnterpriseSearch, etc.) resNsn := types.NamespacedName{Namespace: "ns", Name: "resource"} res := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: resNsn.Namespace, Name: resNsn.Name}} @@ -48,7 +48,7 @@ func TestParseConfigRef(t *testing.T) { tests := []struct { name string - configRef *commonv1.ConfigSource + pipelinesRef *commonv1.ConfigSource secretKey string runtimeObjs []runtime.Object want *PipelinesConfig @@ -58,9 +58,9 @@ func TestParseConfigRef(t *testing.T) { wantEvent string }{ { - name: "happy path", - configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, - secretKey: "configFile.yml", + name: "happy path", + pipelinesRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", runtimeObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, @@ -72,9 +72,9 @@ func TestParseConfigRef(t *testing.T) { wantWatches: []string{watchName}, }, { - name: "happy path, secret already watched", - configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, - secretKey: "configFile.yml", + name: "happy path, secret already watched", + pipelinesRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", runtimeObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, @@ -87,9 +87,9 @@ func TestParseConfigRef(t *testing.T) { wantWatches: []string{watchName}, }, { - name: "no configRef specified", - configRef: nil, - secretKey: "configFile.yml", + name: "no pipelinesRef specified", + pipelinesRef: nil, + secretKey: "configFile.yml", runtimeObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, @@ -101,9 +101,9 @@ func TestParseConfigRef(t *testing.T) { wantWatches: []string{}, }, { - name: "no configRef specified: clear existing watches", - configRef: nil, - secretKey: "configFile.yml", + name: "no pipelinesRef specified: clear existing watches", + pipelinesRef: nil, + secretKey: "configFile.yml", runtimeObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, @@ -116,18 +116,18 @@ func TestParseConfigRef(t *testing.T) { wantWatches: []string{}, }, { - name: "secret not found: error out but watch the future secret", - configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, - secretKey: "configFile.yml", - runtimeObjs: []runtime.Object{}, - want: nil, - wantErr: true, - wantWatches: []string{watchName}, + name: "secret not found: error out but watch the future secret", + pipelinesRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", + runtimeObjs: []runtime.Object{}, + want: nil, + wantErr: true, + wantWatches: []string{watchName}, }, { - name: "missing key in the referenced secret: error out, watch the secret and emit an event", - configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, - secretKey: "configFile.yml", + name: "missing key in the referenced secret: error out, watch the secret and emit an event", + pipelinesRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", runtimeObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, @@ -137,12 +137,12 @@ func TestParseConfigRef(t *testing.T) { }, wantErr: true, wantWatches: []string{watchName}, - wantEvent: "Warning Unexpected unable to parse configRef secret ns/my-secret: missing key configFile.yml", + wantEvent: "Warning Unexpected unable to parse pipelinesRef secret ns/my-secret: missing key configFile.yml", }, { - name: "invalid config the referenced secret: error out, watch the secret and emit an event", - configRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, - secretKey: "configFile.yml", + name: "invalid config the referenced secret: error out, watch the secret and emit an event", + pipelinesRef: &commonv1.ConfigSource{SecretRef: commonv1.SecretRef{SecretName: "my-secret"}}, + secretKey: "configFile.yml", runtimeObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "my-secret"}, @@ -152,7 +152,7 @@ func TestParseConfigRef(t *testing.T) { }, wantErr: true, wantWatches: []string{watchName}, - wantEvent: "Warning Unexpected unable to parse configFile.yml in configRef secret ns/my-secret", + wantEvent: "Warning Unexpected unable to parse configFile.yml in pipelinesRef secret ns/my-secret", }, } for _, tt := range tests { @@ -167,9 +167,9 @@ func TestParseConfigRef(t *testing.T) { watches: w, recorder: fakeRecorder, } - got, err := ParseConfigRef(d, &res, tt.configRef, tt.secretKey) + got, err := ParsePipelinesRef(d, &res, tt.pipelinesRef, tt.secretKey) if (err != nil) != tt.wantErr { - t.Errorf("ParseConfigRef() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ParsePipelinesRef() error = %v, wantErr %v", err, tt.wantErr) return } require.Equal(t, tt.want, got) From f7ea88193177cf1e8d7dfce87386eacc2299ecbd Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Mar 2023 19:05:27 +0000 Subject: [PATCH 127/160] fix metrics check in test --- test/e2e/test/logstash/checks.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 26396d33fe..a22fdc2ec7 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -97,11 +97,11 @@ func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { b.CheckMetricsRequest(k, Request{ Name: "default pipeline", - Path: "/_node/pipelines/demo", + Path: "/_node/pipelines/main", }, Want{ Status: "green", - Match: map[string]string{"pipelines.demo.workers": "2"}, + Match: map[string]string{"pipelines.main.workers": "2"}, }), } } From 80ad3e1de731b772e604ae490bc95c2e94edb29e Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Mar 2023 19:17:38 +0000 Subject: [PATCH 128/160] generate crd --- config/crds/v1/all-crds.yaml | 17 +++++++++++++++++ .../logstash.k8s.elastic.co_logstashes.yaml | 17 +++++++++++++++++ .../eck-operator-crds/templates/all-crds.yaml | 17 +++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 4f30dd94d3..74a2cb9579 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9223,6 +9223,23 @@ spec: type: array type: object type: object + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 5d330d10e2..775c2d4a4a 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -179,6 +179,23 @@ spec: type: array type: object type: object + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index 74932dc3e2..ba9f9f1814 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9277,6 +9277,23 @@ spec: type: array type: object type: object + pipelines: + description: Pipelines holds the Logstash Pipelines. At most one of + [`Pipelines`, `PipelinesRef`] can be specified. + items: + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + pipelinesRef: + description: PipelinesRef contains a reference to an existing Kubernetes + Secret holding the Logstash Pipelines. Logstash pipelines must be + specified as yaml, under a single "pipeline.yml" entry. At most + one of [`Pipelines`, `PipelinesRef`] can be specified. + properties: + secretName: + description: SecretName is the name of the secret. + type: string + type: object podTemplate: description: PodTemplate provides customisation options for the Logstash pods. From 569b319d172ce86c2400ec18ada49b7c1b076b10 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Mar 2023 19:23:28 +0000 Subject: [PATCH 129/160] rename configRef to pipelinesRef --- pkg/controller/logstash/pipelines_configref_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/controller/logstash/pipelines_configref_test.go b/pkg/controller/logstash/pipelines_configref_test.go index 42c86c0c9f..fe10285959 100644 --- a/pkg/controller/logstash/pipelines_configref_test.go +++ b/pkg/controller/logstash/pipelines_configref_test.go @@ -137,7 +137,7 @@ func TestParsePipelinesRef(t *testing.T) { }, wantErr: true, wantWatches: []string{watchName}, - wantEvent: "Warning Unexpected unable to parse pipelinesRef secret ns/my-secret: missing key configFile.yml", + wantEvent: "Warning Unexpected unable to parse configRef secret ns/my-secret: missing key configFile.yml", }, { name: "invalid config the referenced secret: error out, watch the secret and emit an event", @@ -152,7 +152,7 @@ func TestParsePipelinesRef(t *testing.T) { }, wantErr: true, wantWatches: []string{watchName}, - wantEvent: "Warning Unexpected unable to parse configFile.yml in pipelinesRef secret ns/my-secret", + wantEvent: "Warning Unexpected unable to parse configFile.yml in configRef secret ns/my-secret", }, } for _, tt := range tests { From 7057ed393e74d36f9ab9ea775488e857831e6f67 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 22 Mar 2023 22:42:48 +0000 Subject: [PATCH 130/160] fix generate --- config/webhook/manifests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 51bcda4259..2870ef1880 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -226,7 +226,6 @@ webhooks: - logstashes sideEffects: None - admissionReviewVersions: - - v1alpha1 - v1 - v1beta1 clientConfig: From e2a4831d30914db734c96b64f34376f9101d041d Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:43:09 +0000 Subject: [PATCH 131/160] Update pkg/controller/logstash/pipeline_test.go Co-authored-by: Rob Bavey --- pkg/controller/logstash/pipeline_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go index f078accead..6a0c40873d 100644 --- a/pkg/controller/logstash/pipeline_test.go +++ b/pkg/controller/logstash/pipeline_test.go @@ -49,7 +49,7 @@ func Test_buildPipeline(t *testing.T) { want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), }, { - name: "configref populated - no secret", + name: "pipelinesref populated - no secret", pipelinesRef: &commonv1.ConfigSource{ SecretRef: commonv1.SecretRef{ SecretName: "my-secret-pipeline", From 2b8056cada58c70332af7058acb09244d599066a Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:43:18 +0000 Subject: [PATCH 132/160] Update pkg/controller/logstash/pipeline_test.go Co-authored-by: Rob Bavey --- pkg/controller/logstash/pipeline_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go index 6a0c40873d..8716d16bc7 100644 --- a/pkg/controller/logstash/pipeline_test.go +++ b/pkg/controller/logstash/pipeline_test.go @@ -91,7 +91,7 @@ func Test_buildPipeline(t *testing.T) { wantErr: true, }, { - name: "configref populated", + name: "pipelinesref populated", pipelinesRef: &commonv1.ConfigSource{ SecretRef: commonv1.SecretRef{ SecretName: "my-secret-pipeline-2", From eba35e80b7380793c1692f1ce2ba24141556fbde Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:43:26 +0000 Subject: [PATCH 133/160] Update pkg/controller/logstash/pipeline_test.go Co-authored-by: Rob Bavey --- pkg/controller/logstash/pipeline_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go index 8716d16bc7..19c37a72c0 100644 --- a/pkg/controller/logstash/pipeline_test.go +++ b/pkg/controller/logstash/pipeline_test.go @@ -75,7 +75,7 @@ func Test_buildPipeline(t *testing.T) { wantErr: true, }, { - name: "configref populated - malformed config", + name: "pipelinesref populated - malformed config", pipelinesRef: &commonv1.ConfigSource{ SecretRef: commonv1.SecretRef{ SecretName: "my-secret-pipeline-2", From 677be46a05e88fc21f4d7d308a24e7f0c1d9005c Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:43:33 +0000 Subject: [PATCH 134/160] Update pkg/controller/logstash/pipeline_test.go Co-authored-by: Rob Bavey --- pkg/controller/logstash/pipeline_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go index 19c37a72c0..7772957e04 100644 --- a/pkg/controller/logstash/pipeline_test.go +++ b/pkg/controller/logstash/pipeline_test.go @@ -60,7 +60,7 @@ func Test_buildPipeline(t *testing.T) { wantErr: true, }, { - name: "configref populated - no secret key", + name: "pipelinesref populated - no secret key", pipelinesRef: &commonv1.ConfigSource{ SecretRef: commonv1.SecretRef{ SecretName: "my-secret-pipeline", From 0a57f0774e46ad39a2160fa40a66a19de6b583f7 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 23 Mar 2023 15:37:27 +0000 Subject: [PATCH 135/160] fix rename --- pkg/controller/logstash/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/config.go b/pkg/controller/logstash/config.go index cb6cbc91a1..5a0409dbb6 100644 --- a/pkg/controller/logstash/config.go +++ b/pkg/controller/logstash/config.go @@ -63,7 +63,7 @@ func buildConfig(params Params) ([]byte, error) { } // getUserConfig extracts the config either from the spec `config` field or from the Secret referenced by spec -// `pipelinesRef` field. +// `configRef` field. func getUserConfig(params Params) (*settings.CanonicalConfig, error) { if params.Logstash.Spec.Config != nil { return settings.NewCanonicalConfigFrom(params.Logstash.Spec.Config.Data) From 9a4af9b68248cf67d52ccd21a601b1bf3b0effcb Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 30 Mar 2023 14:12:49 +0100 Subject: [PATCH 136/160] change metric check to eventually --- test/e2e/test/logstash/checks.go | 38 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 80355a828c..550d23e708 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -8,9 +8,6 @@ import ( "context" "encoding/json" "fmt" - "testing" - - "github.com/stretchr/testify/require" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings" @@ -127,40 +124,51 @@ func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { func (b Builder) CheckMetricsRequest(k *test.K8sClient, req Request, want Want) test.Step { return test.Step{ Name: fmt.Sprintf("Logstash should respond to %s requests", req.Name), - Test: func(t *testing.T) { - t.Helper() - + Test: test.Eventually(func() error { // send request and parse to map obj client, err := NewLogstashClient(b.Logstash, k) - require.NoError(t, err) + if err != nil { + return err + } bytes, err := DoRequest(client, b.Logstash, "GET", req.Path) - require.NoError(t, err) + if err != nil { + return err + } var response map[string]interface{} err = json.Unmarshal(bytes, &response) - require.NoError(t, err) + if err != nil { + return err + } // parse response to ucfg.Config for traverse res, err := settings.NewCanonicalConfigFrom(response) - require.NoError(t, err) + if err != nil { + return err + } // check status status, err := res.String("status") - require.NoError(t, err) + if err != nil { + return err + } if status != want.Status { - require.NoError(t, fmt.Errorf("expected %s but got %s", want.Status, status)) + return fmt.Errorf("expected %s but got %s", want.Status, status) } // check expected string for k, v := range want.Match { str, err := res.String(k) - require.NoError(t, err) + if err != nil { + return err + } if str != v { - require.NoError(t, fmt.Errorf("expected %s to be %s but got %s", k, v, str)) + return fmt.Errorf("expected %s to be %s but got %s", k, v, str) } } - }, + return nil + }), } } From f012dcbf31f9a3f738793adc4c14b7d675613ff5 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 30 Mar 2023 21:37:58 +0100 Subject: [PATCH 137/160] fix pipeline id in test --- test/e2e/logstash/pipeline_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go index 281116e6c8..8e5dda9784 100644 --- a/test/e2e/logstash/pipeline_test.go +++ b/test/e2e/logstash/pipeline_test.go @@ -30,7 +30,7 @@ func TestPipelineConfigRefLogstash(t *testing.T) { pipeline.workers: 1 queue.drain: false config.string: input { generator {} } filter { sleep { time => 10 } } output { stdout { codec => dots } } -- pipeline.id: demo +- pipeline.id: main config.string: input { stdin{} } output { stdout{} }`, }, } @@ -106,7 +106,7 @@ func TestPipelineConfigLogstash(t *testing.T) { }, { Data: map[string]interface{}{ - "pipeline.id": "demo", + "pipeline.id": "main", "config.string": "input { stdin{} } output { stdout{} }", }, }, From 8943822ebe418c97114cfc247504f559a4c4a534 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:17:36 +0100 Subject: [PATCH 138/160] Update pkg/controller/logstash/pipelines_config.go Co-authored-by: Michael Morello --- pkg/controller/logstash/pipelines_config.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/controller/logstash/pipelines_config.go b/pkg/controller/logstash/pipelines_config.go index 1f1de61466..820052b4e5 100644 --- a/pkg/controller/logstash/pipelines_config.go +++ b/pkg/controller/logstash/pipelines_config.go @@ -27,8 +27,8 @@ func NewPipelinesConfig() *PipelinesConfig { } // NewPipelinesConfigFrom creates a new pipeline from spec. -func NewPipelinesConfigFrom(data []map[string]interface{}) (*PipelinesConfig, error) { - config, err := ucfg.NewFrom(data, Options...) +func NewPipelinesConfigFrom(cfg interface{}) (*PipelinesConfig, error) { + config, err := ucfg.NewFrom(cfg, Options...) if err != nil { return nil, err } @@ -38,11 +38,11 @@ func NewPipelinesConfigFrom(data []map[string]interface{}) (*PipelinesConfig, er // MustPipelinesConfig creates a new pipeline and panics on errors. // Use for testing only. func MustPipelinesConfig(cfg interface{}) *PipelinesConfig { - config, err := ucfg.NewFrom(cfg, Options...) + config, err := NewPipelinesConfigFrom(cfg) if err != nil { panic(err) } - return fromConfig(config) + return config } // ParsePipelinesConfig parses the given pipeline content into a PipelinesConfig. From 980a505da24f2456c9db217ae11051e297814dfc Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:17:44 +0100 Subject: [PATCH 139/160] Update pkg/controller/logstash/pipelines_config.go Co-authored-by: Michael Morello --- pkg/controller/logstash/pipelines_config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/controller/logstash/pipelines_config.go b/pkg/controller/logstash/pipelines_config.go index 820052b4e5..1c8801662b 100644 --- a/pkg/controller/logstash/pipelines_config.go +++ b/pkg/controller/logstash/pipelines_config.go @@ -8,9 +8,9 @@ import ( "fmt" "reflect" - ucfg "github.com/elastic/go-ucfg" + "github.com/elastic/go-ucfg" uyaml "github.com/elastic/go-ucfg/yaml" - yaml "gopkg.in/yaml.v3" + "gopkg.in/yaml.v3" ) // PipelinesConfig contains configuration for Logstash pipeline ("pipelines.yml"), From 124d7746475dac1a586e0aae9b6f0aec5e7ee46d Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:18:43 +0100 Subject: [PATCH 140/160] Update pkg/controller/logstash/pipeline.go Co-authored-by: Michael Morello --- pkg/controller/logstash/pipeline.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/controller/logstash/pipeline.go b/pkg/controller/logstash/pipeline.go index 532a700385..d28c50d109 100644 --- a/pkg/controller/logstash/pipeline.go +++ b/pkg/controller/logstash/pipeline.go @@ -71,13 +71,11 @@ func getUserPipeline(params Params) (*PipelinesConfig, error) { return ParsePipelinesRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) } -func defaultPipeline() *PipelinesConfig { - pipelines := []map[string]string{ +var ( + defaultPipeline = MustPipelinesConfig([]map[string]string{ { "pipeline.id": "main", "path.config": "/usr/share/logstash/pipeline", }, - } - - return MustPipelinesConfig(pipelines) -} + }) +) From 9089f79e73812e0fe1152ead347c8d70f81336ce Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:18:53 +0100 Subject: [PATCH 141/160] Update pkg/controller/logstash/pipeline.go Co-authored-by: Michael Morello --- pkg/controller/logstash/pipeline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipeline.go b/pkg/controller/logstash/pipeline.go index d28c50d109..5df2bd69a4 100644 --- a/pkg/controller/logstash/pipeline.go +++ b/pkg/controller/logstash/pipeline.go @@ -62,7 +62,7 @@ func buildPipeline(params Params) ([]byte, error) { // `pipelineRef` field. func getUserPipeline(params Params) (*PipelinesConfig, error) { if params.Logstash.Spec.Pipelines != nil { - var pipelines []map[string]interface{} + pipelines := make([]map[string]interface{}, 0, len(params.Logstash.Spec.Pipelines)) for _, p := range params.Logstash.Spec.Pipelines { pipelines = append(pipelines, p.Data) } From 8cdb763016e6a2c1f46104b25e0ca5d0eb895def Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:20:19 +0100 Subject: [PATCH 142/160] Update test/e2e/test/logstash/builder.go Co-authored-by: Michael Morello --- test/e2e/test/logstash/builder.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 202fdfe65a..07d0ee21de 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -140,12 +140,14 @@ func (b Builder) WithVolumeMounts(mounts ...corev1.VolumeMount) Builder { VolumeMounts: mounts, }, } - } else { - if b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts == nil { - b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{} - } - b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts = append(b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts, mounts...) + return b + } + + if b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts == nil { + b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{} } + b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts = append(b.Logstash.Spec.PodTemplate.Spec.Containers[0].VolumeMounts, mounts...) + return b } From 6ceda8c8926004293ab9b7ebcfca524397bf87cd Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 4 Apr 2023 11:59:53 +0100 Subject: [PATCH 143/160] move test func to test class fix syntax --- pkg/controller/logstash/pipeline.go | 2 +- pkg/controller/logstash/pipeline_test.go | 60 +++++++++++++++++---- pkg/controller/logstash/pipelines_config.go | 50 ----------------- 3 files changed, 51 insertions(+), 61 deletions(-) diff --git a/pkg/controller/logstash/pipeline.go b/pkg/controller/logstash/pipeline.go index 5df2bd69a4..bcd8e7283f 100644 --- a/pkg/controller/logstash/pipeline.go +++ b/pkg/controller/logstash/pipeline.go @@ -54,7 +54,7 @@ func buildPipeline(params Params) ([]byte, error) { return userProvidedCfg.Render() } - cfg := defaultPipeline() + cfg := defaultPipeline return cfg.Render() } diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go index 7772957e04..f0ec9478ed 100644 --- a/pkg/controller/logstash/pipeline_test.go +++ b/pkg/controller/logstash/pipeline_test.go @@ -6,6 +6,8 @@ package logstash import ( "context" + "fmt" + "reflect" "testing" "github.com/stretchr/testify/require" @@ -20,15 +22,6 @@ import ( ) func Test_buildPipeline(t *testing.T) { - defaultPipelinesConfig := MustPipelinesConfig( - []map[string]interface{}{ - { - "pipeline.id": "main", - "path.config": "/usr/share/logstash/pipeline", - }, - }, - ) - for _, tt := range []struct { name string pipelines []commonv1.Config @@ -39,7 +32,7 @@ func Test_buildPipeline(t *testing.T) { }{ { name: "no user pipeline", - want: defaultPipelinesConfig, + want: defaultPipeline, }, { name: "pipeline populated", @@ -130,3 +123,50 @@ func Test_buildPipeline(t *testing.T) { }) } } + +// Diff returns true if the key/value or the sequence of two PipelinesConfig are different +// Use for testing only. +func (c *PipelinesConfig) Diff(c2 *PipelinesConfig) (bool, error) { + if c == c2 { + return false, nil + } + if c == nil && c2 != nil { + return true, fmt.Errorf("empty lhs config %s", c2.asUCfg().FlattenedKeys(Options...)) + } + if c != nil && c2 == nil { + return true, fmt.Errorf("empty rhs config %s", c.asUCfg().FlattenedKeys(Options...)) + } + + var s []map[string]interface{} + var s2 []map[string]interface{} + err := c.asUCfg().Unpack(&s, Options...) + if err != nil { + return true, err + } + err = c2.asUCfg().Unpack(&s2, Options...) + if err != nil { + return true, err + } + + return diffSlice(s, s2) +} + +// diffSlice returns true if the key/value or the sequence of two PipelinesConfig are different +func diffSlice(s1, s2 []map[string]interface{}) (bool, error) { + if len(s1) != len(s2) { + return true, fmt.Errorf("array size doesn't match %d, %d", len(s1), len(s2)) + } + var diff []string + for i, m := range s1 { + m2 := s2[i] + if eq := reflect.DeepEqual(m, m2); !eq { + diff = append(diff, fmt.Sprintf("%s vs %s, ", m, m2)) + } + } + + if len(diff) > 0 { + return true, fmt.Errorf("there are %d differences. %s", len(diff), diff) + } + + return false, nil +} diff --git a/pkg/controller/logstash/pipelines_config.go b/pkg/controller/logstash/pipelines_config.go index 1c8801662b..89e593b130 100644 --- a/pkg/controller/logstash/pipelines_config.go +++ b/pkg/controller/logstash/pipelines_config.go @@ -5,9 +5,6 @@ package logstash import ( - "fmt" - "reflect" - "github.com/elastic/go-ucfg" uyaml "github.com/elastic/go-ucfg/yaml" "gopkg.in/yaml.v3" @@ -78,53 +75,6 @@ func (c *PipelinesConfig) Render() ([]byte, error) { return yaml.Marshal(out) } -// Diff returns true if the key/value or the sequence of two PipelinesConfig are different -// Use for testing only. -func (c *PipelinesConfig) Diff(c2 *PipelinesConfig) (bool, error) { - if c == c2 { - return false, nil - } - if c == nil && c2 != nil { - return true, fmt.Errorf("empty lhs config %s", c2.asUCfg().FlattenedKeys(Options...)) - } - if c != nil && c2 == nil { - return true, fmt.Errorf("empty rhs config %s", c.asUCfg().FlattenedKeys(Options...)) - } - - var s []map[string]interface{} - var s2 []map[string]interface{} - err := c.asUCfg().Unpack(&s, Options...) - if err != nil { - return true, err - } - err = c2.asUCfg().Unpack(&s2, Options...) - if err != nil { - return true, err - } - - return diffSlice(s, s2) -} - -// diffSlice returns true if the key/value or the sequence of two PipelinesConfig are different -func diffSlice(s1, s2 []map[string]interface{}) (bool, error) { - if len(s1) != len(s2) { - return true, fmt.Errorf("array size doesn't match %d, %d", len(s1), len(s2)) - } - var diff []string - for i, m := range s1 { - m2 := s2[i] - if eq := reflect.DeepEqual(m, m2); !eq { - diff = append(diff, fmt.Sprintf("%s vs %s, ", m, m2)) - } - } - - if len(diff) > 0 { - return true, fmt.Errorf("there are %d differences. %s", len(diff), diff) - } - - return false, nil -} - func (c *PipelinesConfig) asUCfg() *ucfg.Config { return (*ucfg.Config)(c) } From 9922520c33c5c40cb15dcf5bab2f161185aff627 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 4 Apr 2023 13:51:58 +0100 Subject: [PATCH 144/160] Update pkg/apis/logstash/v1alpha1/logstash_types.go Co-authored-by: Michael Morello --- pkg/apis/logstash/v1alpha1/logstash_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/logstash/v1alpha1/logstash_types.go b/pkg/apis/logstash/v1alpha1/logstash_types.go index ce731f2ef7..bf595c3c3a 100644 --- a/pkg/apis/logstash/v1alpha1/logstash_types.go +++ b/pkg/apis/logstash/v1alpha1/logstash_types.go @@ -48,7 +48,7 @@ type LogstashSpec struct { Pipelines []commonv1.Config `json:"pipelines,omitempty"` // PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. - // Logstash pipelines must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] + // Logstash pipelines must be specified as yaml, under a single "pipelines.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] // can be specified. // +kubebuilder:validation:Optional PipelinesRef *commonv1.ConfigSource `json:"pipelinesRef,omitempty"` From 7a0072d3a02782d867d38cbb6eaf43feb9fa7411 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 4 Apr 2023 14:49:26 +0100 Subject: [PATCH 145/160] Update test/e2e/logstash/pipeline_test.go Co-authored-by: Michael Morello --- test/e2e/logstash/pipeline_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go index 8e5dda9784..e758135b56 100644 --- a/test/e2e/logstash/pipeline_test.go +++ b/test/e2e/logstash/pipeline_test.go @@ -62,6 +62,7 @@ func TestPipelineConfigRefLogstash(t *testing.T) { }, logstash.Want{ Status: "green", + Match: map[string]string{"pipelines.generator.workers": "1"}, }), } }) From 4a47fb4e3616304ef1b6aadc44f221ed5d47e86f Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Tue, 4 Apr 2023 14:49:39 +0100 Subject: [PATCH 146/160] Update test/e2e/logstash/pipeline_test.go Co-authored-by: Michael Morello --- test/e2e/logstash/pipeline_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go index e758135b56..a54a4013f5 100644 --- a/test/e2e/logstash/pipeline_test.go +++ b/test/e2e/logstash/pipeline_test.go @@ -134,6 +134,7 @@ func TestPipelineConfigLogstash(t *testing.T) { }, logstash.Want{ Status: "green", + Match: map[string]string{"pipelines.split.workers": "2"}, }), } }) From 754a74e4898f7d66452921f88630851c9826952f Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 4 Apr 2023 21:37:19 +0100 Subject: [PATCH 147/160] update metrics api checking add comment to e2e --- test/e2e/logstash/pipeline_test.go | 4 +++- test/e2e/test/logstash/checks.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go index a54a4013f5..0d5998598b 100644 --- a/test/e2e/logstash/pipeline_test.go +++ b/test/e2e/logstash/pipeline_test.go @@ -16,6 +16,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// TestPipelineConfigRefLogstash PipelineRef should be able to take pipelines.yaml from Secret func TestPipelineConfigRefLogstash(t *testing.T) { secretName := "ls-generator-pipeline" @@ -70,6 +71,7 @@ func TestPipelineConfigRefLogstash(t *testing.T) { test.Sequence(before, steps, b).RunSequential(t) } +// TestPipelineConfigLogstash Pipeline should be able to pass to Logstash via VolumeMount func TestPipelineConfigLogstash(t *testing.T) { secretName := "ls-split-pipe" @@ -134,7 +136,7 @@ func TestPipelineConfigLogstash(t *testing.T) { }, logstash.Want{ Status: "green", - Match: map[string]string{"pipelines.split.workers": "2"}, + Match: map[string]string{"pipelines.split.batch_size": "125"}, }), } }) diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 550d23e708..6648b50630 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -116,7 +116,7 @@ func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { }, Want{ Status: "green", - Match: map[string]string{"pipelines.main.workers": "2"}, + Match: map[string]string{"pipelines.main.batch_size": "125"}, }), } } From d8cf0667da464d2f4373ef88f72afe970181e3aa Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 4 Apr 2023 22:05:24 +0100 Subject: [PATCH 148/160] fix naming pipelines.yml --- config/crds/v1/all-crds.yaml | 2 +- config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml | 2 +- .../charts/eck-operator-crds/templates/all-crds.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/crds/v1/all-crds.yaml b/config/crds/v1/all-crds.yaml index 74a2cb9579..ffa0083c17 100644 --- a/config/crds/v1/all-crds.yaml +++ b/config/crds/v1/all-crds.yaml @@ -9233,7 +9233,7 @@ spec: pipelinesRef: description: PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be - specified as yaml, under a single "pipeline.yml" entry. At most + specified as yaml, under a single "pipelines.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified. properties: secretName: diff --git a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml index 775c2d4a4a..f92a4a038c 100644 --- a/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml +++ b/config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml @@ -189,7 +189,7 @@ spec: pipelinesRef: description: PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be - specified as yaml, under a single "pipeline.yml" entry. At most + specified as yaml, under a single "pipelines.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified. properties: secretName: diff --git a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml index ba9f9f1814..06f46ea7a2 100644 --- a/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml +++ b/deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml @@ -9287,7 +9287,7 @@ spec: pipelinesRef: description: PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be - specified as yaml, under a single "pipeline.yml" entry. At most + specified as yaml, under a single "pipelines.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified. properties: secretName: From a976bda4a0ef829a142462299a8f57457bdbe4ee Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 4 Apr 2023 22:07:36 +0100 Subject: [PATCH 149/160] delete pipeline secret at the end of test --- test/e2e/logstash/pipeline_test.go | 12 ++++++++++++ test/e2e/test/k8s_client.go | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go index 0d5998598b..6af2223794 100644 --- a/test/e2e/logstash/pipeline_test.go +++ b/test/e2e/logstash/pipeline_test.go @@ -65,6 +65,12 @@ func TestPipelineConfigRefLogstash(t *testing.T) { Status: "green", Match: map[string]string{"pipelines.generator.workers": "1"}, }), + test.Step{ + Name: "Delete pipeline secret", + Test: test.Eventually(func() error { + return k.DeleteSecrets(pipelineSecret) + }), + }, } }) @@ -138,6 +144,12 @@ func TestPipelineConfigLogstash(t *testing.T) { Status: "green", Match: map[string]string{"pipelines.split.batch_size": "125"}, }), + test.Step{ + Name: "Delete pipeline secret", + Test: test.Eventually(func() error { + return k.DeleteSecrets(pipelineSecret) + }), + }, } }) diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index f3b4d13ddf..bb56fee30b 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -363,6 +363,15 @@ func (k K8sClient) CreateOrUpdateSecrets(secrets ...corev1.Secret) error { return nil } +func (k *K8sClient) DeleteSecrets(secrets ...corev1.Secret) error { + for i := range secrets { + if err := k.Client.Delete(context.Background(), &secrets[i]); err != nil { + return err + } + } + return nil +} + func (k K8sClient) CreateOrUpdate(objs ...client.Object) error { for _, obj := range objs { // create a copy to ensure that the original object is not modified From b6b4ad0bd4a5c77356f859821a28e0a226875a92 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 4 Apr 2023 22:46:25 +0100 Subject: [PATCH 150/160] fix naming pipelines.yml --- docs/reference/api-docs.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/api-docs.asciidoc b/docs/reference/api-docs.asciidoc index abc9faa1e1..040a1e3058 100644 --- a/docs/reference/api-docs.asciidoc +++ b/docs/reference/api-docs.asciidoc @@ -1898,7 +1898,7 @@ LogstashSpec defines the desired state of Logstash | *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified. | *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified. | *`pipelines`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$] array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified. -| *`pipelinesRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be specified as yaml, under a single "pipeline.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified. +| *`pipelinesRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be specified as yaml, under a single "pipelines.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified. | *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs | *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster. | *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods. From eebc8a64a06cd33727a8a53e98c9788b3c533838 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Tue, 4 Apr 2023 23:05:05 +0100 Subject: [PATCH 151/160] move pipelines_*.go to pipelines package --- .../logstash/logstash_controller.go | 3 +- pkg/controller/logstash/pipeline.go | 14 +- pkg/controller/logstash/pipeline_test.go | 64 ++------- pkg/controller/logstash/pipelines/config.go | 134 ++++++++++++++++++ .../config_test.go} | 54 +++---- .../configref.go} | 16 +-- .../configref_test.go} | 14 +- pkg/controller/logstash/pipelines_config.go | 84 ----------- 8 files changed, 194 insertions(+), 189 deletions(-) create mode 100644 pkg/controller/logstash/pipelines/config.go rename pkg/controller/logstash/{pipelines_config_test.go => pipelines/config_test.go} (85%) rename pkg/controller/logstash/{pipelines_configref.go => pipelines/configref.go} (66%) rename pkg/controller/logstash/{pipelines_configref_test.go => pipelines/configref_test.go} (93%) delete mode 100644 pkg/controller/logstash/pipelines_config.go diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go index 3b496744ba..f08afd0fb4 100644 --- a/pkg/controller/logstash/logstash_controller.go +++ b/pkg/controller/logstash/logstash_controller.go @@ -27,6 +27,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/pipelines" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" logconf "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log" ) @@ -196,6 +197,6 @@ func (r *ReconcileLogstash) validate(ctx context.Context, logstash logstashv1alp func (r *ReconcileLogstash) onDelete(ctx context.Context, obj types.NamespacedName) error { r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj)) r.dynamicWatches.Secrets.RemoveHandlerForKey(common.ConfigRefWatchName(obj)) - r.dynamicWatches.Secrets.RemoveHandlerForKey(PipelinesRefWatchName(obj)) + r.dynamicWatches.Secrets.RemoveHandlerForKey(pipelines.ConfigRefWatchName(obj)) return reconciler.GarbageCollectSoftOwnedSecrets(ctx, r.Client, obj, logstashv1alpha1.Kind) } diff --git a/pkg/controller/logstash/pipeline.go b/pkg/controller/logstash/pipeline.go index bcd8e7283f..9dfd86c293 100644 --- a/pkg/controller/logstash/pipeline.go +++ b/pkg/controller/logstash/pipeline.go @@ -14,6 +14,7 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/pipelines" ) func reconcilePipeline(params Params, configHash hash.Hash) error { @@ -60,19 +61,20 @@ func buildPipeline(params Params) ([]byte, error) { // getUserPipeline extracts the pipeline either from the spec `pipeline` field or from the Secret referenced by spec // `pipelineRef` field. -func getUserPipeline(params Params) (*PipelinesConfig, error) { +func getUserPipeline(params Params) (*pipelines.Config, error) { if params.Logstash.Spec.Pipelines != nil { - pipelines := make([]map[string]interface{}, 0, len(params.Logstash.Spec.Pipelines)) + pipes := make([]map[string]interface{}, 0, len(params.Logstash.Spec.Pipelines)) for _, p := range params.Logstash.Spec.Pipelines { - pipelines = append(pipelines, p.Data) + pipes = append(pipes, p.Data) } - return NewPipelinesConfigFrom(pipelines) + + return pipelines.FromSpec(pipes) } - return ParsePipelinesRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) + return pipelines.ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) } var ( - defaultPipeline = MustPipelinesConfig([]map[string]string{ + defaultPipeline = pipelines.MustFromSpec([]map[string]string{ { "pipeline.id": "main", "path.config": "/usr/share/logstash/pipeline", diff --git a/pkg/controller/logstash/pipeline_test.go b/pkg/controller/logstash/pipeline_test.go index f0ec9478ed..59d28a5bf2 100644 --- a/pkg/controller/logstash/pipeline_test.go +++ b/pkg/controller/logstash/pipeline_test.go @@ -6,8 +6,6 @@ package logstash import ( "context" - "fmt" - "reflect" "testing" "github.com/stretchr/testify/require" @@ -18,6 +16,7 @@ import ( commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/pipelines" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" ) @@ -27,7 +26,7 @@ func Test_buildPipeline(t *testing.T) { pipelines []commonv1.Config pipelinesRef *commonv1.ConfigSource client k8s.Client - want *PipelinesConfig + want *pipelines.Config wantErr bool }{ { @@ -39,7 +38,7 @@ func Test_buildPipeline(t *testing.T) { pipelines: []commonv1.Config{ {Data: map[string]interface{}{"pipeline.id": "main"}}, }, - want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + want: pipelines.MustParse([]byte(`- "pipeline.id": "main"`)), }, { name: "pipelinesref populated - no secret", @@ -49,7 +48,7 @@ func Test_buildPipeline(t *testing.T) { }, }, client: k8s.NewFakeClient(), - want: NewPipelinesConfig(), + want: pipelines.EmptyConfig(), wantErr: true, }, { @@ -64,7 +63,7 @@ func Test_buildPipeline(t *testing.T) { Name: "my-secret-pipeline", }, }), - want: NewPipelinesConfig(), + want: pipelines.EmptyConfig(), wantErr: true, }, { @@ -80,7 +79,7 @@ func Test_buildPipeline(t *testing.T) { }, Data: map[string][]byte{"pipelines.yml": []byte("something:bad:value")}, }), - want: NewPipelinesConfig(), + want: pipelines.EmptyConfig(), wantErr: true, }, { @@ -96,7 +95,7 @@ func Test_buildPipeline(t *testing.T) { }, Data: map[string][]byte{"pipelines.yml": []byte(`- "pipeline.id": "main"`)}, }), - want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + want: pipelines.MustParse([]byte(`- "pipeline.id": "main"`)), }, } { t.Run(tt.name, func(t *testing.T) { @@ -114,7 +113,7 @@ func Test_buildPipeline(t *testing.T) { } gotYaml, gotErr := buildPipeline(params) - diff, err := tt.want.Diff(MustParsePipelineConfig(gotYaml)) + diff, err := tt.want.Diff(pipelines.MustParse(gotYaml)) if diff { t.Errorf("buildPipeline() got unexpected differences: %v", err) } @@ -123,50 +122,3 @@ func Test_buildPipeline(t *testing.T) { }) } } - -// Diff returns true if the key/value or the sequence of two PipelinesConfig are different -// Use for testing only. -func (c *PipelinesConfig) Diff(c2 *PipelinesConfig) (bool, error) { - if c == c2 { - return false, nil - } - if c == nil && c2 != nil { - return true, fmt.Errorf("empty lhs config %s", c2.asUCfg().FlattenedKeys(Options...)) - } - if c != nil && c2 == nil { - return true, fmt.Errorf("empty rhs config %s", c.asUCfg().FlattenedKeys(Options...)) - } - - var s []map[string]interface{} - var s2 []map[string]interface{} - err := c.asUCfg().Unpack(&s, Options...) - if err != nil { - return true, err - } - err = c2.asUCfg().Unpack(&s2, Options...) - if err != nil { - return true, err - } - - return diffSlice(s, s2) -} - -// diffSlice returns true if the key/value or the sequence of two PipelinesConfig are different -func diffSlice(s1, s2 []map[string]interface{}) (bool, error) { - if len(s1) != len(s2) { - return true, fmt.Errorf("array size doesn't match %d, %d", len(s1), len(s2)) - } - var diff []string - for i, m := range s1 { - m2 := s2[i] - if eq := reflect.DeepEqual(m, m2); !eq { - diff = append(diff, fmt.Sprintf("%s vs %s, ", m, m2)) - } - } - - if len(diff) > 0 { - return true, fmt.Errorf("there are %d differences. %s", len(diff), diff) - } - - return false, nil -} diff --git a/pkg/controller/logstash/pipelines/config.go b/pkg/controller/logstash/pipelines/config.go new file mode 100644 index 0000000000..23d3fb02fb --- /dev/null +++ b/pkg/controller/logstash/pipelines/config.go @@ -0,0 +1,134 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License 2.0; +// you may not use this file except in compliance with the Elastic License 2.0. + +package pipelines + +import ( + "fmt" + "reflect" + + "github.com/elastic/go-ucfg" + uyaml "github.com/elastic/go-ucfg/yaml" + "gopkg.in/yaml.v3" +) + +// Config contains configuration for Logstash pipeline ("pipelines.yml"), +// `.` in between the key, pipeline.id, is treated as string +// pipelines.yml is expected an array of pipeline definition +type Config ucfg.Config + +// Options are config options for the YAML file. +var Options = []ucfg.Option{ucfg.AppendValues} + +// EmptyConfig creates a new empty config. +func EmptyConfig() *Config { + return fromConfig(ucfg.New()) +} + +// FromSpec creates a new pipeline from spec. +func FromSpec(cfg interface{}) (*Config, error) { + config, err := ucfg.NewFrom(cfg, Options...) + if err != nil { + return nil, err + } + return fromConfig(config), nil +} + +// MustFromSpec creates a new pipeline and panics on errors. +// Use for testing only. +func MustFromSpec(cfg interface{}) *Config { + config, err := FromSpec(cfg) + if err != nil { + panic(err) + } + return config +} + +// Parse parses the given pipeline content into a PipelinesConfig. +// Expects content to be in YAML format. +func Parse(yml []byte) (*Config, error) { + config, err := uyaml.NewConfig(yml, Options...) + if err != nil { + return nil, err + } + return fromConfig(config), nil +} + +// MustParse parses the given pipeline content into a Pipelines. +// Expects content to be in YAML format. Panics on error. +func MustParse(yml []byte) *Config { + config, err := uyaml.NewConfig(yml, Options...) + if err != nil { + panic(err) + } + return fromConfig(config) +} + +// Render returns the content of the configuration file, +// with fields sorted alphabetically +func (c *Config) Render() ([]byte, error) { + if c == nil { + return []byte{}, nil + } + var out []interface{} + if err := c.asUCfg().Unpack(&out); err != nil { + return []byte{}, err + } + return yaml.Marshal(out) +} + +func (c *Config) asUCfg() *ucfg.Config { + return (*ucfg.Config)(c) +} + +func fromConfig(in *ucfg.Config) *Config { + return (*Config)(in) +} + +// Diff returns true if the key/value or the sequence of two PipelinesConfig are different +// Use for testing only. +func (c *Config) Diff(c2 *Config) (bool, error) { + if c == c2 { + return false, nil + } + if c == nil && c2 != nil { + return true, fmt.Errorf("empty lhs config %s", c2.asUCfg().FlattenedKeys(Options...)) + } + if c != nil && c2 == nil { + return true, fmt.Errorf("empty rhs config %s", c.asUCfg().FlattenedKeys(Options...)) + } + + var s []map[string]interface{} + var s2 []map[string]interface{} + err := c.asUCfg().Unpack(&s, Options...) + if err != nil { + return true, err + } + err = c2.asUCfg().Unpack(&s2, Options...) + if err != nil { + return true, err + } + + return diffSlice(s, s2) +} + +// diffSlice returns true if the key/value or the sequence of two PipelinesConfig are different +func diffSlice(s1, s2 []map[string]interface{}) (bool, error) { + if len(s1) != len(s2) { + return true, fmt.Errorf("array size doesn't match %d, %d", len(s1), len(s2)) + } + var diff []string + for i, m := range s1 { + m2 := s2[i] + if eq := reflect.DeepEqual(m, m2); !eq { + diff = append(diff, fmt.Sprintf("%s vs %s, ", m, m2)) + } + } + + if len(diff) > 0 { + return true, fmt.Errorf("there are %d differences. %s", len(diff), diff) + } + + return false, nil +} diff --git a/pkg/controller/logstash/pipelines_config_test.go b/pkg/controller/logstash/pipelines/config_test.go similarity index 85% rename from pkg/controller/logstash/pipelines_config_test.go rename to pkg/controller/logstash/pipelines/config_test.go index f1107c2ce3..43c16835bb 100644 --- a/pkg/controller/logstash/pipelines_config_test.go +++ b/pkg/controller/logstash/pipelines/config_test.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License 2.0; // you may not use this file except in compliance with the Elastic License 2.0. -package logstash +package pipelines import ( "testing" @@ -11,7 +11,7 @@ import ( ) func TestPipelinesConfig_Render(t *testing.T) { - config := MustPipelinesConfig( + config := MustFromSpec( []map[string]interface{}{ { "pipeline.id": "demo", @@ -45,19 +45,19 @@ func TestParsePipelinesConfig(t *testing.T) { tests := []struct { name string input string - want *PipelinesConfig + want *Config wantErr bool }{ { name: "no input", input: "", - want: NewPipelinesConfig(), + want: EmptyConfig(), wantErr: false, }, { name: "simple input", input: "- pipeline.id: demo\n config.string: input { exec { command => \"${ENV}\" interval => 5 } }", - want: MustPipelinesConfig( + want: MustFromSpec( []map[string]interface{}{ { "pipeline.id": "demo", @@ -70,7 +70,7 @@ func TestParsePipelinesConfig(t *testing.T) { { name: "number input", input: "- pipeline.id: main\n pipeline.workers: 4", - want: MustPipelinesConfig( + want: MustFromSpec( []map[string]interface{}{ { "pipeline.id": "main", @@ -83,7 +83,7 @@ func TestParsePipelinesConfig(t *testing.T) { { name: "boolean input", input: "- pipeline.id: main\n queue.drain: false", - want: MustPipelinesConfig( + want: MustFromSpec( []map[string]interface{}{ { "pipeline.id": "main", @@ -96,7 +96,7 @@ func TestParsePipelinesConfig(t *testing.T) { { name: "trim whitespaces between key and value", input: "- pipeline.id : demo \n path.config : /tmp/logstash/*.config ", - want: MustPipelinesConfig( + want: MustFromSpec( []map[string]interface{}{ { "pipeline.id": "demo", @@ -114,7 +114,7 @@ func TestParsePipelinesConfig(t *testing.T) { { name: "trim newlines", input: "- pipeline.id: demo \n\n- pipeline.id: demo2 \n", - want: MustPipelinesConfig( + want: MustFromSpec( []map[string]interface{}{ {"pipeline.id": "demo"}, {"pipeline.id": "demo2"}, @@ -125,7 +125,7 @@ func TestParsePipelinesConfig(t *testing.T) { { name: "ignore comments", input: "- pipeline.id: demo \n#this is a comment\n pipeline.workers: \"1\"\n", - want: MustPipelinesConfig( + want: MustFromSpec( []map[string]interface{}{ { "pipeline.id": "demo", @@ -138,7 +138,7 @@ func TestParsePipelinesConfig(t *testing.T) { { name: "support quotes", input: `- "pipeline.id": "quote"`, - want: MustPipelinesConfig( + want: MustFromSpec( []map[string]interface{}{ {"pipeline.id": "quote"}, }, @@ -148,7 +148,7 @@ func TestParsePipelinesConfig(t *testing.T) { { name: "support special characters", input: `- config.string: "${node.ip}%.:=+è! /"`, - want: MustPipelinesConfig( + want: MustFromSpec( []map[string]interface{}{ {"config.string": `${node.ip}%.:=+è! /`}, }, @@ -158,9 +158,9 @@ func TestParsePipelinesConfig(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := ParsePipelinesConfig([]byte(tt.input)) + got, err := Parse([]byte(tt.input)) if (err != nil) != tt.wantErr { - t.Errorf("ParsePipelinesConfig() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr) return } @@ -173,7 +173,7 @@ func TestParsePipelinesConfig(t *testing.T) { require.NoError(t, err) wantRendered, err := tt.want.Render() require.NoError(t, err) - t.Errorf("ParsePipelinesConfig(), want: %s, got: %s", wantRendered, gotRendered) + t.Errorf("Parse(), want: %s, got: %s", wantRendered, gotRendered) } }) } @@ -182,8 +182,8 @@ func TestParsePipelinesConfig(t *testing.T) { func TestPipelinesConfig_Diff(t *testing.T) { tests := []struct { name string - c *PipelinesConfig - c2 *PipelinesConfig + c *Config + c2 *Config wantDiff bool }{ { @@ -195,7 +195,7 @@ func TestPipelinesConfig_Diff(t *testing.T) { { name: "lhs nil", c: nil, - c2: MustPipelinesConfig( + c2: MustFromSpec( []map[string]interface{}{ {"a": "a"}, {"b": "b"}, @@ -205,7 +205,7 @@ func TestPipelinesConfig_Diff(t *testing.T) { }, { name: "rhs nil", - c: MustPipelinesConfig( + c: MustFromSpec( []map[string]interface{}{ {"a": "a"}, }, @@ -215,12 +215,12 @@ func TestPipelinesConfig_Diff(t *testing.T) { }, { name: "same multi key value", - c: MustPipelinesConfig( + c: MustFromSpec( []map[string]interface{}{ {"a": "a", "b": "b", "c": 1, "d": true}, }, ), - c2: MustPipelinesConfig( + c2: MustFromSpec( []map[string]interface{}{ {"c": 1, "b": "b", "a": "a", "d": true}, }, @@ -229,12 +229,12 @@ func TestPipelinesConfig_Diff(t *testing.T) { }, { name: "different value", - c: MustPipelinesConfig( + c: MustFromSpec( []map[string]interface{}{ {"a": "a"}, }, ), - c2: MustPipelinesConfig( + c2: MustFromSpec( []map[string]interface{}{ {"a": "b"}, }, @@ -243,12 +243,12 @@ func TestPipelinesConfig_Diff(t *testing.T) { }, { name: "array size different", - c: MustPipelinesConfig( + c: MustFromSpec( []map[string]interface{}{ {"a": "a"}, }, ), - c2: MustPipelinesConfig( + c2: MustFromSpec( []map[string]interface{}{ {"a": "a"}, {"a": "a"}, @@ -258,13 +258,13 @@ func TestPipelinesConfig_Diff(t *testing.T) { }, { name: "respects list order", - c: MustPipelinesConfig( + c: MustFromSpec( []map[string]interface{}{ {"a": "a"}, {"b": "b"}, }, ), - c2: MustPipelinesConfig( + c2: MustFromSpec( []map[string]interface{}{ {"b": "b"}, {"a": "a"}, diff --git a/pkg/controller/logstash/pipelines_configref.go b/pkg/controller/logstash/pipelines/configref.go similarity index 66% rename from pkg/controller/logstash/pipelines_configref.go rename to pkg/controller/logstash/pipelines/configref.go index b2c28e1360..234012fbcd 100644 --- a/pkg/controller/logstash/pipelines_configref.go +++ b/pkg/controller/logstash/pipelines/configref.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License 2.0; // you may not use this file except in compliance with the Elastic License 2.0. -package logstash +package pipelines import ( "fmt" @@ -15,23 +15,23 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" ) -// PipelinesRefWatchName returns the name of the watch registered on the secret referenced in `pipelinesRef`. -func PipelinesRefWatchName(resource types.NamespacedName) string { +// ConfigRefWatchName returns the name of the watch registered on the secret referenced in `pipelinesRef`. +func ConfigRefWatchName(resource types.NamespacedName) string { return fmt.Sprintf("%s-%s-pipelinesref", resource.Namespace, resource.Name) } -// ParsePipelinesRef retrieves the content of a secret referenced in `pipelinesRef`, sets up dynamic watches for that secret, +// ParseConfigRef retrieves the content of a secret referenced in `pipelinesRef`, sets up dynamic watches for that secret, // and parses the secret content into a PipelinesConfig. -func ParsePipelinesRef( +func ParseConfigRef( driver driver.Interface, resource runtime.Object, pipelinesRef *commonv1.ConfigSource, secretKey string, // retrieve config data from that entry in the secret -) (*PipelinesConfig, error) { - parsed, err := common.ParseConfigRefToConfig(driver, resource, pipelinesRef, secretKey, PipelinesRefWatchName, Options) +) (*Config, error) { + parsed, err := common.ParseConfigRefToConfig(driver, resource, pipelinesRef, secretKey, ConfigRefWatchName, Options) if err != nil { return nil, err } - return (*PipelinesConfig)(parsed), nil + return (*Config)(parsed), nil } diff --git a/pkg/controller/logstash/pipelines_configref_test.go b/pkg/controller/logstash/pipelines/configref_test.go similarity index 93% rename from pkg/controller/logstash/pipelines_configref_test.go rename to pkg/controller/logstash/pipelines/configref_test.go index fe10285959..ec95df0470 100644 --- a/pkg/controller/logstash/pipelines_configref_test.go +++ b/pkg/controller/logstash/pipelines/configref_test.go @@ -2,7 +2,7 @@ // or more contributor license agreements. Licensed under the Elastic License 2.0; // you may not use this file except in compliance with the Elastic License 2.0. -package logstash +package pipelines import ( "testing" @@ -44,14 +44,14 @@ func TestParsePipelinesRef(t *testing.T) { // any resource Kind would work here (eg. Beat, EnterpriseSearch, etc.) resNsn := types.NamespacedName{Namespace: "ns", Name: "resource"} res := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: resNsn.Namespace, Name: resNsn.Name}} - watchName := PipelinesRefWatchName(resNsn) + watchName := ConfigRefWatchName(resNsn) tests := []struct { name string pipelinesRef *commonv1.ConfigSource secretKey string runtimeObjs []runtime.Object - want *PipelinesConfig + want *Config wantErr bool existingWatches []string wantWatches []string @@ -68,7 +68,7 @@ func TestParsePipelinesRef(t *testing.T) { "configFile.yml": []byte(`- "pipeline.id": "main"`), }}, }, - want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + want: MustParse([]byte(`- "pipeline.id": "main"`)), wantWatches: []string{watchName}, }, { @@ -82,7 +82,7 @@ func TestParsePipelinesRef(t *testing.T) { "configFile.yml": []byte(`- "pipeline.id": "main"`), }}, }, - want: MustParsePipelineConfig([]byte(`- "pipeline.id": "main"`)), + want: MustParse([]byte(`- "pipeline.id": "main"`)), existingWatches: []string{watchName}, wantWatches: []string{watchName}, }, @@ -167,9 +167,9 @@ func TestParsePipelinesRef(t *testing.T) { watches: w, recorder: fakeRecorder, } - got, err := ParsePipelinesRef(d, &res, tt.pipelinesRef, tt.secretKey) + got, err := ParseConfigRef(d, &res, tt.pipelinesRef, tt.secretKey) if (err != nil) != tt.wantErr { - t.Errorf("ParsePipelinesRef() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ParseConfigRef() error = %v, wantErr %v", err, tt.wantErr) return } require.Equal(t, tt.want, got) diff --git a/pkg/controller/logstash/pipelines_config.go b/pkg/controller/logstash/pipelines_config.go deleted file mode 100644 index 89e593b130..0000000000 --- a/pkg/controller/logstash/pipelines_config.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License 2.0; -// you may not use this file except in compliance with the Elastic License 2.0. - -package logstash - -import ( - "github.com/elastic/go-ucfg" - uyaml "github.com/elastic/go-ucfg/yaml" - "gopkg.in/yaml.v3" -) - -// PipelinesConfig contains configuration for Logstash pipeline ("pipelines.yml"), -// `.` in between the key, pipeline.id, is treated as string -// pipelines.yml is expected an array of pipeline definition -type PipelinesConfig ucfg.Config - -// Options are config options for the YAML file. -var Options = []ucfg.Option{ucfg.AppendValues} - -// NewPipelinesConfig creates a new empty config. -func NewPipelinesConfig() *PipelinesConfig { - return fromConfig(ucfg.New()) -} - -// NewPipelinesConfigFrom creates a new pipeline from spec. -func NewPipelinesConfigFrom(cfg interface{}) (*PipelinesConfig, error) { - config, err := ucfg.NewFrom(cfg, Options...) - if err != nil { - return nil, err - } - return fromConfig(config), nil -} - -// MustPipelinesConfig creates a new pipeline and panics on errors. -// Use for testing only. -func MustPipelinesConfig(cfg interface{}) *PipelinesConfig { - config, err := NewPipelinesConfigFrom(cfg) - if err != nil { - panic(err) - } - return config -} - -// ParsePipelinesConfig parses the given pipeline content into a PipelinesConfig. -// Expects content to be in YAML format. -func ParsePipelinesConfig(yml []byte) (*PipelinesConfig, error) { - config, err := uyaml.NewConfig(yml, Options...) - if err != nil { - return nil, err - } - return fromConfig(config), nil -} - -// MustParsePipelineConfig parses the given pipeline content into a Pipelines. -// Expects content to be in YAML format. Panics on error. -func MustParsePipelineConfig(yml []byte) *PipelinesConfig { - config, err := uyaml.NewConfig(yml, Options...) - if err != nil { - panic(err) - } - return fromConfig(config) -} - -// Render returns the content of the configuration file, -// with fields sorted alphabetically -func (c *PipelinesConfig) Render() ([]byte, error) { - if c == nil { - return []byte{}, nil - } - var out []interface{} - if err := c.asUCfg().Unpack(&out); err != nil { - return []byte{}, err - } - return yaml.Marshal(out) -} - -func (c *PipelinesConfig) asUCfg() *ucfg.Config { - return (*ucfg.Config)(c) -} - -func fromConfig(in *ucfg.Config) *PipelinesConfig { - return (*PipelinesConfig)(in) -} From 8d524210d4700c2a8114c5e5df2af63b127902f2 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 5 Apr 2023 17:33:30 +0100 Subject: [PATCH 152/160] rename & comment --- pkg/controller/logstash/logstash_controller.go | 2 +- pkg/controller/logstash/pipeline.go | 2 +- pkg/controller/logstash/pipelines/config.go | 1 + .../pipelines/{configref.go => pipelinesref.go} | 10 +++++----- .../{configref_test.go => pipelinesref_test.go} | 6 +++--- 5 files changed, 11 insertions(+), 10 deletions(-) rename pkg/controller/logstash/pipelines/{configref.go => pipelinesref.go} (72%) rename pkg/controller/logstash/pipelines/{configref_test.go => pipelinesref_test.go} (96%) diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go index f08afd0fb4..f99b61620f 100644 --- a/pkg/controller/logstash/logstash_controller.go +++ b/pkg/controller/logstash/logstash_controller.go @@ -197,6 +197,6 @@ func (r *ReconcileLogstash) validate(ctx context.Context, logstash logstashv1alp func (r *ReconcileLogstash) onDelete(ctx context.Context, obj types.NamespacedName) error { r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj)) r.dynamicWatches.Secrets.RemoveHandlerForKey(common.ConfigRefWatchName(obj)) - r.dynamicWatches.Secrets.RemoveHandlerForKey(pipelines.ConfigRefWatchName(obj)) + r.dynamicWatches.Secrets.RemoveHandlerForKey(pipelines.PipelinesRefWatchName(obj)) return reconciler.GarbageCollectSoftOwnedSecrets(ctx, r.Client, obj, logstashv1alpha1.Kind) } diff --git a/pkg/controller/logstash/pipeline.go b/pkg/controller/logstash/pipeline.go index 9dfd86c293..ddc696b29d 100644 --- a/pkg/controller/logstash/pipeline.go +++ b/pkg/controller/logstash/pipeline.go @@ -70,7 +70,7 @@ func getUserPipeline(params Params) (*pipelines.Config, error) { return pipelines.FromSpec(pipes) } - return pipelines.ParseConfigRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) + return pipelines.ParsePipelinesRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) } var ( diff --git a/pkg/controller/logstash/pipelines/config.go b/pkg/controller/logstash/pipelines/config.go index 23d3fb02fb..ffa97e3d7b 100644 --- a/pkg/controller/logstash/pipelines/config.go +++ b/pkg/controller/logstash/pipelines/config.go @@ -57,6 +57,7 @@ func Parse(yml []byte) (*Config, error) { // MustParse parses the given pipeline content into a Pipelines. // Expects content to be in YAML format. Panics on error. +// Use for testing only. func MustParse(yml []byte) *Config { config, err := uyaml.NewConfig(yml, Options...) if err != nil { diff --git a/pkg/controller/logstash/pipelines/configref.go b/pkg/controller/logstash/pipelines/pipelinesref.go similarity index 72% rename from pkg/controller/logstash/pipelines/configref.go rename to pkg/controller/logstash/pipelines/pipelinesref.go index 234012fbcd..1f6a0d16cb 100644 --- a/pkg/controller/logstash/pipelines/configref.go +++ b/pkg/controller/logstash/pipelines/pipelinesref.go @@ -15,20 +15,20 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" ) -// ConfigRefWatchName returns the name of the watch registered on the secret referenced in `pipelinesRef`. -func ConfigRefWatchName(resource types.NamespacedName) string { +// PipelinesRefWatchName returns the name of the watch registered on the secret referenced in `pipelinesRef`. +func PipelinesRefWatchName(resource types.NamespacedName) string { return fmt.Sprintf("%s-%s-pipelinesref", resource.Namespace, resource.Name) } -// ParseConfigRef retrieves the content of a secret referenced in `pipelinesRef`, sets up dynamic watches for that secret, +// ParsePipelinesRef retrieves the content of a secret referenced in `pipelinesRef`, sets up dynamic watches for that secret, // and parses the secret content into a PipelinesConfig. -func ParseConfigRef( +func ParsePipelinesRef( driver driver.Interface, resource runtime.Object, pipelinesRef *commonv1.ConfigSource, secretKey string, // retrieve config data from that entry in the secret ) (*Config, error) { - parsed, err := common.ParseConfigRefToConfig(driver, resource, pipelinesRef, secretKey, ConfigRefWatchName, Options) + parsed, err := common.ParseConfigRefToConfig(driver, resource, pipelinesRef, secretKey, PipelinesRefWatchName, Options) if err != nil { return nil, err } diff --git a/pkg/controller/logstash/pipelines/configref_test.go b/pkg/controller/logstash/pipelines/pipelinesref_test.go similarity index 96% rename from pkg/controller/logstash/pipelines/configref_test.go rename to pkg/controller/logstash/pipelines/pipelinesref_test.go index ec95df0470..c666611e76 100644 --- a/pkg/controller/logstash/pipelines/configref_test.go +++ b/pkg/controller/logstash/pipelines/pipelinesref_test.go @@ -44,7 +44,7 @@ func TestParsePipelinesRef(t *testing.T) { // any resource Kind would work here (eg. Beat, EnterpriseSearch, etc.) resNsn := types.NamespacedName{Namespace: "ns", Name: "resource"} res := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: resNsn.Namespace, Name: resNsn.Name}} - watchName := ConfigRefWatchName(resNsn) + watchName := PipelinesRefWatchName(resNsn) tests := []struct { name string @@ -167,9 +167,9 @@ func TestParsePipelinesRef(t *testing.T) { watches: w, recorder: fakeRecorder, } - got, err := ParseConfigRef(d, &res, tt.pipelinesRef, tt.secretKey) + got, err := ParsePipelinesRef(d, &res, tt.pipelinesRef, tt.secretKey) if (err != nil) != tt.wantErr { - t.Errorf("ParseConfigRef() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ParsePipelinesRef() error = %v, wantErr %v", err, tt.wantErr) return } require.Equal(t, tt.want, got) From 991e63601aed80ff8b7faf6c68f3ad4d387d4c41 Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Wed, 5 Apr 2023 17:46:12 +0100 Subject: [PATCH 153/160] lint --- pkg/controller/logstash/logstash_controller.go | 2 +- .../logstash/pipelines/{pipelinesref.go => ref.go} | 6 +++--- .../pipelines/{pipelinesref_test.go => ref_test.go} | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename pkg/controller/logstash/pipelines/{pipelinesref.go => ref.go} (83%) rename pkg/controller/logstash/pipelines/{pipelinesref_test.go => ref_test.go} (99%) diff --git a/pkg/controller/logstash/logstash_controller.go b/pkg/controller/logstash/logstash_controller.go index f99b61620f..6c71683b51 100644 --- a/pkg/controller/logstash/logstash_controller.go +++ b/pkg/controller/logstash/logstash_controller.go @@ -197,6 +197,6 @@ func (r *ReconcileLogstash) validate(ctx context.Context, logstash logstashv1alp func (r *ReconcileLogstash) onDelete(ctx context.Context, obj types.NamespacedName) error { r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj)) r.dynamicWatches.Secrets.RemoveHandlerForKey(common.ConfigRefWatchName(obj)) - r.dynamicWatches.Secrets.RemoveHandlerForKey(pipelines.PipelinesRefWatchName(obj)) + r.dynamicWatches.Secrets.RemoveHandlerForKey(pipelines.RefWatchName(obj)) return reconciler.GarbageCollectSoftOwnedSecrets(ctx, r.Client, obj, logstashv1alpha1.Kind) } diff --git a/pkg/controller/logstash/pipelines/pipelinesref.go b/pkg/controller/logstash/pipelines/ref.go similarity index 83% rename from pkg/controller/logstash/pipelines/pipelinesref.go rename to pkg/controller/logstash/pipelines/ref.go index 1f6a0d16cb..4cf753c19b 100644 --- a/pkg/controller/logstash/pipelines/pipelinesref.go +++ b/pkg/controller/logstash/pipelines/ref.go @@ -15,8 +15,8 @@ import ( "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/driver" ) -// PipelinesRefWatchName returns the name of the watch registered on the secret referenced in `pipelinesRef`. -func PipelinesRefWatchName(resource types.NamespacedName) string { +// RefWatchName returns the name of the watch registered on the secret referenced in `pipelinesRef`. +func RefWatchName(resource types.NamespacedName) string { return fmt.Sprintf("%s-%s-pipelinesref", resource.Namespace, resource.Name) } @@ -28,7 +28,7 @@ func ParsePipelinesRef( pipelinesRef *commonv1.ConfigSource, secretKey string, // retrieve config data from that entry in the secret ) (*Config, error) { - parsed, err := common.ParseConfigRefToConfig(driver, resource, pipelinesRef, secretKey, PipelinesRefWatchName, Options) + parsed, err := common.ParseConfigRefToConfig(driver, resource, pipelinesRef, secretKey, RefWatchName, Options) if err != nil { return nil, err } diff --git a/pkg/controller/logstash/pipelines/pipelinesref_test.go b/pkg/controller/logstash/pipelines/ref_test.go similarity index 99% rename from pkg/controller/logstash/pipelines/pipelinesref_test.go rename to pkg/controller/logstash/pipelines/ref_test.go index c666611e76..f71cdd1dae 100644 --- a/pkg/controller/logstash/pipelines/pipelinesref_test.go +++ b/pkg/controller/logstash/pipelines/ref_test.go @@ -44,7 +44,7 @@ func TestParsePipelinesRef(t *testing.T) { // any resource Kind would work here (eg. Beat, EnterpriseSearch, etc.) resNsn := types.NamespacedName{Namespace: "ns", Name: "resource"} res := corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: resNsn.Namespace, Name: resNsn.Name}} - watchName := PipelinesRefWatchName(resNsn) + watchName := RefWatchName(resNsn) tests := []struct { name string From 7bb3f5d29069332e824258ff1c4a3e000fe32f7d Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:12:13 +0100 Subject: [PATCH 154/160] Update pkg/controller/logstash/pipelines/config.go Co-authored-by: Michael Morello --- pkg/controller/logstash/pipelines/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipelines/config.go b/pkg/controller/logstash/pipelines/config.go index ffa97e3d7b..67f3ebb524 100644 --- a/pkg/controller/logstash/pipelines/config.go +++ b/pkg/controller/logstash/pipelines/config.go @@ -15,7 +15,7 @@ import ( // Config contains configuration for Logstash pipeline ("pipelines.yml"), // `.` in between the key, pipeline.id, is treated as string -// pipelines.yml is expected an array of pipeline definition +// pipelines.yml is expected an array of pipeline definition. type Config ucfg.Config // Options are config options for the YAML file. From 7e816daa68809e16ca1ac4790624f268408798aa Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:12:27 +0100 Subject: [PATCH 155/160] Update pkg/controller/logstash/pipelines/config.go Co-authored-by: Michael Morello --- pkg/controller/logstash/pipelines/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipelines/config.go b/pkg/controller/logstash/pipelines/config.go index 67f3ebb524..eb7c4c8e58 100644 --- a/pkg/controller/logstash/pipelines/config.go +++ b/pkg/controller/logstash/pipelines/config.go @@ -67,7 +67,7 @@ func MustParse(yml []byte) *Config { } // Render returns the content of the configuration file, -// with fields sorted alphabetically +// with fields sorted alphabetically. func (c *Config) Render() ([]byte, error) { if c == nil { return []byte{}, nil From 791e02d2ac1f9d45753e65a0575a824b2a3ce23b Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:12:38 +0100 Subject: [PATCH 156/160] Update pkg/controller/logstash/pipelines/config.go Co-authored-by: Michael Morello --- pkg/controller/logstash/pipelines/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipelines/config.go b/pkg/controller/logstash/pipelines/config.go index eb7c4c8e58..4e3c9ae189 100644 --- a/pkg/controller/logstash/pipelines/config.go +++ b/pkg/controller/logstash/pipelines/config.go @@ -87,7 +87,7 @@ func fromConfig(in *ucfg.Config) *Config { return (*Config)(in) } -// Diff returns true if the key/value or the sequence of two PipelinesConfig are different +// Diff returns true if the key/value or the sequence of two PipelinesConfig are different. // Use for testing only. func (c *Config) Diff(c2 *Config) (bool, error) { if c == c2 { From 9967ca46d81f428e1c540ca4ccdf978f576005c8 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:12:46 +0100 Subject: [PATCH 157/160] Update pkg/controller/logstash/pipelines/config.go Co-authored-by: Michael Morello --- pkg/controller/logstash/pipelines/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/logstash/pipelines/config.go b/pkg/controller/logstash/pipelines/config.go index 4e3c9ae189..f92de18aa5 100644 --- a/pkg/controller/logstash/pipelines/config.go +++ b/pkg/controller/logstash/pipelines/config.go @@ -114,7 +114,7 @@ func (c *Config) Diff(c2 *Config) (bool, error) { return diffSlice(s, s2) } -// diffSlice returns true if the key/value or the sequence of two PipelinesConfig are different +// diffSlice returns true if the key/value or the sequence of two PipelinesConfig are different. func diffSlice(s1, s2 []map[string]interface{}) (bool, error) { if len(s1) != len(s2) { return true, fmt.Errorf("array size doesn't match %d, %d", len(s1), len(s2)) From 203a3b4c4b3a65e07fb4517f4a0b5d1dbecac6bd Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:13:06 +0100 Subject: [PATCH 158/160] Update test/e2e/logstash/pipeline_test.go Co-authored-by: Michael Morello --- test/e2e/logstash/pipeline_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go index 6af2223794..be11d02228 100644 --- a/test/e2e/logstash/pipeline_test.go +++ b/test/e2e/logstash/pipeline_test.go @@ -16,7 +16,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// TestPipelineConfigRefLogstash PipelineRef should be able to take pipelines.yaml from Secret +// TestPipelineConfigRefLogstash PipelineRef should be able to take pipelines.yaml from Secret. func TestPipelineConfigRefLogstash(t *testing.T) { secretName := "ls-generator-pipeline" From f7563148fa4bcefa4e15d6021f7ebf1ca759ddf4 Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:13:15 +0100 Subject: [PATCH 159/160] Update test/e2e/logstash/pipeline_test.go Co-authored-by: Michael Morello --- test/e2e/logstash/pipeline_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/logstash/pipeline_test.go b/test/e2e/logstash/pipeline_test.go index be11d02228..576dd11a77 100644 --- a/test/e2e/logstash/pipeline_test.go +++ b/test/e2e/logstash/pipeline_test.go @@ -77,7 +77,7 @@ func TestPipelineConfigRefLogstash(t *testing.T) { test.Sequence(before, steps, b).RunSequential(t) } -// TestPipelineConfigLogstash Pipeline should be able to pass to Logstash via VolumeMount +// TestPipelineConfigLogstash Pipeline should be able to pass to Logstash via VolumeMount. func TestPipelineConfigLogstash(t *testing.T) { secretName := "ls-split-pipe" From 3cc5964940c2f893d24f2042feff686e883aec1b Mon Sep 17 00:00:00 2001 From: Kaise Cheng Date: Thu, 6 Apr 2023 11:44:39 +0100 Subject: [PATCH 160/160] import grouping --- test/e2e/test/logstash/checks.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/e2e/test/logstash/checks.go b/test/e2e/test/logstash/checks.go index 6648b50630..19524fa3fd 100644 --- a/test/e2e/test/logstash/checks.go +++ b/test/e2e/test/logstash/checks.go @@ -9,12 +9,11 @@ import ( "encoding/json" "fmt" - "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings" - corev1 "k8s.io/api/core/v1" v1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1" logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" + "github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/v2/test/e2e/test" )