From 0b2b18629c852deb29d7dbc4767ef99ac626b400 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Tue, 16 Jul 2024 14:54:37 -0500 Subject: [PATCH 01/12] :bug: add addon reported errors to the dashboard. (#728) Signed-off-by: Jeff Ortel --- api/task.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/task.go b/api/task.go index 2f4aaec95..886efa41a 100644 --- a/api/task.go +++ b/api/task.go @@ -934,4 +934,7 @@ func (r *TaskDashboard) With(m *model.Task) { r.Started = m.Started r.Terminated = m.Terminated r.Errors = len(m.Errors) + if m.Report != nil { + r.Errors += len(m.Report.Errors) + } } From 3ea1d8c3eabefa7b5458eef5e4eec09ece666877 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Wed, 17 Jul 2024 07:46:52 -0500 Subject: [PATCH 02/12] :bug: Analysis created in transaction. (#729) Analysis created in a transaction. More efficient and prevents partial reports. Signed-off-by: Jeff Ortel --- api/analysis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/analysis.go b/api/analysis.go index 547040f52..03e98f845 100644 --- a/api/analysis.go +++ b/api/analysis.go @@ -89,7 +89,7 @@ func (h AnalysisHandler) AddRoutes(e *gin.Engine) { // Application routeGroup = e.Group("/") routeGroup.Use(Required("applications.analyses")) - routeGroup.POST(AppAnalysesRoot, h.AppCreate) + routeGroup.POST(AppAnalysesRoot, Transaction, h.AppCreate) routeGroup.GET(AppAnalysesRoot, h.AppList) routeGroup.GET(AppAnalysisRoot, h.AppLatest) routeGroup.GET(AppAnalysisReportRoot, h.AppLatestReport) From cddd0c8803067b63883c8d0713919cb2130ad469 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Thu, 18 Jul 2024 10:04:30 -0500 Subject: [PATCH 03/12] :bug: Add new addon alpha2 fields as optional to alpha1. (#730) Signed-off-by: Jeff Ortel --- generated/crd/tackle.konveyor.io_addons.yaml | 1208 +++++++++++++++++ k8s/api/tackle/v1alpha1/addon.go | 10 + .../tackle/v1alpha1/zz_generated.deepcopy.go | 2 + .../tackle/v1alpha2/zz_generated.deepcopy.go | 2 +- 4 files changed, 1221 insertions(+), 1 deletion(-) diff --git a/generated/crd/tackle.konveyor.io_addons.yaml b/generated/crd/tackle.konveyor.io_addons.yaml index 55b94c779..ac7d70427 100644 --- a/generated/crd/tackle.konveyor.io_addons.yaml +++ b/generated/crd/tackle.konveyor.io_addons.yaml @@ -35,6 +35,1204 @@ spec: spec: description: Spec defines the desired state of the resource. properties: + container: + description: Container defines the addon container. + 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: + 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 image: description: Addon fqin. type: string @@ -46,6 +1244,10 @@ spec: - Always - Never type: string + metadata: + description: Metadata details. + type: object + x-kubernetes-preserve-unknown-fields: true resources: description: Resource requirements. properties: @@ -72,6 +1274,12 @@ spec: to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' type: object type: object + selector: + description: Selector defines criteria to be selected for a task. + type: string + task: + description: Task declares task (kind) compatibility. + type: string required: - image type: object diff --git a/k8s/api/tackle/v1alpha1/addon.go b/k8s/api/tackle/v1alpha1/addon.go index 9dbbd2ea4..0493e4686 100644 --- a/k8s/api/tackle/v1alpha1/addon.go +++ b/k8s/api/tackle/v1alpha1/addon.go @@ -19,6 +19,7 @@ package v1alpha1 import ( core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) // AddonSpec defines the desired state of an Addon. @@ -31,6 +32,15 @@ type AddonSpec struct { ImagePullPolicy core.PullPolicy `json:"imagePullPolicy,omitempty"` // Resource requirements. Resources core.ResourceRequirements `json:"resources,omitempty"` + // + // Task declares task (kind) compatibility. + Task string `json:"task,omitempty"` + // Selector defines criteria to be selected for a task. + Selector string `json:"selector,omitempty"` + // Container defines the addon container. + Container core.Container `json:"container,omitempty"` + // Metadata details. + Metadata runtime.RawExtension `json:"metadata,omitempty"` } // AddonStatus defines the observed state of an Addon. diff --git a/k8s/api/tackle/v1alpha1/zz_generated.deepcopy.go b/k8s/api/tackle/v1alpha1/zz_generated.deepcopy.go index ec96a5bfa..d5e524a56 100644 --- a/k8s/api/tackle/v1alpha1/zz_generated.deepcopy.go +++ b/k8s/api/tackle/v1alpha1/zz_generated.deepcopy.go @@ -88,6 +88,8 @@ func (in *AddonList) DeepCopyObject() runtime.Object { func (in *AddonSpec) DeepCopyInto(out *AddonSpec) { *out = *in in.Resources.DeepCopyInto(&out.Resources) + in.Container.DeepCopyInto(&out.Container) + in.Metadata.DeepCopyInto(&out.Metadata) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddonSpec. diff --git a/k8s/api/tackle/v1alpha2/zz_generated.deepcopy.go b/k8s/api/tackle/v1alpha2/zz_generated.deepcopy.go index 16db1de34..244028496 100644 --- a/k8s/api/tackle/v1alpha2/zz_generated.deepcopy.go +++ b/k8s/api/tackle/v1alpha2/zz_generated.deepcopy.go @@ -22,7 +22,7 @@ limitations under the License. package v1alpha2 import ( - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" ) From fd9c5cf5d88ceabf83fd8f1b8ab5360bad86a775 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Thu, 18 Jul 2024 10:55:40 -0500 Subject: [PATCH 04/12] :bug: MTA-3209 fix effort on app-issues report. (#731) Fixes https://issues.redhat.com/browse/MTA-3209 Signed-off-by: Jeff Ortel --- api/analysis.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/analysis.go b/api/analysis.go index 03e98f845..eb115113e 100644 --- a/api/analysis.go +++ b/api/analysis.go @@ -1300,7 +1300,7 @@ func (h AnalysisHandler) IssueAppReports(ctx *gin.Context) { "app.Name", "app.Description", "b.Name BusinessService", - "a.Effort", + "i.Effort", "COUNT(n.ID) Incidents", "COUNT(distinct n.File) Files", "i.ID IssueID", @@ -1350,7 +1350,7 @@ func (h AnalysisHandler) IssueAppReports(ctx *gin.Context) { r.Name = m.Name r.Description = m.Description r.BusinessService = m.BusinessService - r.Effort = m.Effort + r.Effort = m.Effort * m.Incidents r.Incidents = m.Incidents r.Files = m.Files r.Issue.ID = m.IssueID From ca8c3913403fcb24c37f390f1f6552563166da0a Mon Sep 17 00:00:00 2001 From: Dylan Murray Date: Thu, 18 Jul 2024 15:55:17 -0400 Subject: [PATCH 05/12] :bug: fix proxy test to update back to the original (#732) Signed-off-by: Dylan Murray --- test/api/proxy/api_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/api/proxy/api_test.go b/test/api/proxy/api_test.go index b4f003ec8..09066d1d6 100644 --- a/test/api/proxy/api_test.go +++ b/test/api/proxy/api_test.go @@ -15,11 +15,11 @@ func TestProxyGetUpdate(t *testing.T) { } // Update. - update := orig + update := *orig update.Host = "127.0.0.1" update.Port = 8081 update.Enabled = true - err = Proxy.Update(update) + err = Proxy.Update(&update) if err != nil { t.Errorf(err.Error()) } From 73a06684327fab3b1889fe4b50a3efaac52eb493 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Wed, 24 Jul 2024 09:22:25 -0500 Subject: [PATCH 06/12] :bug: Revert alpha2 crd (#735) Removed v1alpha2. Adds 0.5 fields to v1alpha1 as optional. Update the hub to use v1alpah1. Updates CR status to support conditions. The addon controller will perform migration to ensure the addon.Container is populated. The task manager will wait until resources have been reconciled. --- Moved api/reflect/field.go Fields() to new _reflect_ package at the root. Added new functions: - HasField() - Select() - Omit My main concern was the the task manager is using Select() to restrict Save() specific fields. The "Error" fields as incorrect (should be "Errors") and silently didn't update the field. --- This won't pass CI without operator changes. --------- Signed-off-by: Jeff Ortel --- api/addon.go | 2 +- api/base.go | 2 +- api/sort/sort.go | 2 +- api/taskgroup.go | 2 +- controller/addon.go | 108 +- generated/crd/tackle.konveyor.io_addons.yaml | 1352 +---------------- .../crd/tackle.konveyor.io_extensions.yaml | 22 - generated/crd/tackle.konveyor.io_tackles.yaml | 30 - generated/crd/tackle.konveyor.io_tasks.yaml | 22 - k8s/api/all.go | 6 +- k8s/api/tackle/v1alpha1/addon.go | 77 +- k8s/api/tackle/v1alpha1/extension.go | 27 +- k8s/api/tackle/v1alpha1/pkg.go | 23 + k8s/api/tackle/v1alpha1/tackle.go | 1 + k8s/api/tackle/v1alpha1/task.go | 48 +- .../tackle/v1alpha1/zz_generated.deepcopy.go | 99 +- k8s/api/tackle/v1alpha2/addon.go | 78 - k8s/api/tackle/v1alpha2/extension.go | 69 - k8s/api/tackle/v1alpha2/register.go | 35 - k8s/api/tackle/v1alpha2/tackle.go | 42 - k8s/api/tackle/v1alpha2/task.go | 90 -- .../tackle/v1alpha2/zz_generated.deepcopy.go | 378 ----- reflect/db.go | 27 + reflect/error.go | 25 + {api/reflect => reflect}/fields.go | 56 + task/error.go | 45 + task/manager.go | 38 +- task/task_test.go | 2 +- trigger/pkg.go | 2 +- 29 files changed, 581 insertions(+), 2129 deletions(-) create mode 100644 k8s/api/tackle/v1alpha1/pkg.go delete mode 100644 k8s/api/tackle/v1alpha2/addon.go delete mode 100644 k8s/api/tackle/v1alpha2/extension.go delete mode 100644 k8s/api/tackle/v1alpha2/register.go delete mode 100644 k8s/api/tackle/v1alpha2/tackle.go delete mode 100644 k8s/api/tackle/v1alpha2/task.go delete mode 100644 k8s/api/tackle/v1alpha2/zz_generated.deepcopy.go create mode 100644 reflect/db.go create mode 100644 reflect/error.go rename {api/reflect => reflect}/fields.go (58%) diff --git a/api/addon.go b/api/addon.go index 152fa57ef..d08d5cb1a 100644 --- a/api/addon.go +++ b/api/addon.go @@ -6,7 +6,7 @@ import ( "net/http" "github.com/gin-gonic/gin" - crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2" + crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" core "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" k8s "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/api/base.go b/api/base.go index 0b8ca1dfa..602ac3be4 100644 --- a/api/base.go +++ b/api/base.go @@ -14,10 +14,10 @@ import ( "github.com/gin-gonic/gin/binding" liberr "github.com/jortel/go-utils/error" "github.com/jortel/go-utils/logr" - "github.com/konveyor/tackle2-hub/api/reflect" "github.com/konveyor/tackle2-hub/api/sort" "github.com/konveyor/tackle2-hub/auth" "github.com/konveyor/tackle2-hub/model" + "github.com/konveyor/tackle2-hub/reflect" "gopkg.in/yaml.v2" "gorm.io/gorm" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/api/sort/sort.go b/api/sort/sort.go index 7654ae6d5..2e577a13a 100644 --- a/api/sort/sort.go +++ b/api/sort/sort.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/gin-gonic/gin" - "github.com/konveyor/tackle2-hub/api/reflect" + "github.com/konveyor/tackle2-hub/reflect" "gorm.io/gorm" ) diff --git a/api/taskgroup.go b/api/taskgroup.go index 58a007a4c..2423d304b 100644 --- a/api/taskgroup.go +++ b/api/taskgroup.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/gin-gonic/gin" - crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2" + crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" "github.com/konveyor/tackle2-hub/model" tasking "github.com/konveyor/tackle2-hub/task" "gorm.io/gorm/clause" diff --git a/controller/addon.go b/controller/addon.go index 0e5e4705b..35f12f71e 100644 --- a/controller/addon.go +++ b/controller/addon.go @@ -2,13 +2,15 @@ package controller import ( "context" + "strings" "github.com/go-logr/logr" logr2 "github.com/jortel/go-utils/logr" - api "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2" + api "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" "github.com/konveyor/tackle2-hub/settings" "gorm.io/gorm" k8serr "k8s.io/apimachinery/pkg/api/errors" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apiserver/pkg/storage/names" "k8s.io/client-go/tools/record" k8s "sigs.k8s.io/controller-runtime/pkg/client" @@ -32,9 +34,10 @@ var Settings = &settings.Settings // Add the controller. func Add(mgr manager.Manager, db *gorm.DB) error { reconciler := &Reconciler{ - Client: mgr.GetClient(), - Log: log, - DB: db, + history: make(map[string]byte), + Client: mgr.GetClient(), + Log: log, + DB: db, } cnt, err := controller.New( Name, @@ -59,15 +62,18 @@ func Add(mgr manager.Manager, db *gorm.DB) error { } // Reconciler reconciles addon CRs. +// The history is used to ensure resources are reconciled +// at least once at startup. type Reconciler struct { record.EventRecorder k8s.Client - DB *gorm.DB - Log logr.Logger + DB *gorm.DB + Log logr.Logger + history map[string]byte } // Reconcile a Addon CR. -// Note: Must not a pointer receiver to ensure that the +// Note: Must not be a pointer receiver to ensure that the // logger and other state is not shared. func (r Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (result reconcile.Result, err error) { r.Log = logr2.WithName( @@ -86,18 +92,23 @@ func (r Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (r } return } - // migrate - migrated, err := r.alpha2Migration(addon) - if migrated || err != nil { + _, found := r.history[addon.Name] + if found && addon.Reconciled() { return } - // changed. - err = r.addonChanged(addon) - if err != nil { + r.history[addon.Name] = 1 + addon.Status.Conditions = nil + addon.Status.ObservedGeneration = addon.Generation + // Changed + migrated, err := r.addonChanged(addon) + if migrated || err != nil { return } + // Ready condition. + addon.Status.Conditions = append( + addon.Status.Conditions, + r.ready(addon)) // Apply changes. - addon.Status.ObservedGeneration = addon.Generation err = r.Status().Update(context.TODO(), addon) if err != nil { return @@ -106,47 +117,50 @@ func (r Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (r return } -// addonChanged an addon has been created/updated. -func (r *Reconciler) addonChanged(addon *api.Addon) (err error) { - return -} - -// addonDeleted an addon has been deleted. -func (r *Reconciler) addonDeleted(name string) (err error) { - return -} - -// alpha2Migration migrates to alpha2. -func (r *Reconciler) alpha2Migration(addon *api.Addon) (migrated bool, err error) { - if addon.Spec.Image != nil { - if addon.Spec.Container.Image == "" { - addon.Spec.Container.Image = *addon.Spec.Image +// ready returns the ready condition. +func (r *Reconciler) ready(addon *api.Addon) (ready v1.Condition) { + ready = api.Ready + ready.LastTransitionTime = v1.Now() + ready.ObservedGeneration = addon.Status.ObservedGeneration + err := make([]string, 0) + for i := range addon.Status.Conditions { + cnd := &addon.Status.Conditions[i] + if cnd.Type == api.ValidationError { + err = append(err, cnd.Message) } - addon.Spec.Image = nil - migrated = true } - if addon.Spec.Resources != nil { - if len(addon.Spec.Container.Resources.Limits) == 0 { - addon.Spec.Container.Resources.Limits = (*addon.Spec.Resources).Limits - } - if len(addon.Spec.Container.Resources.Requests) == 0 { - addon.Spec.Container.Resources.Requests = (*addon.Spec.Resources).Requests - } - addon.Spec.Resources = nil - migrated = true - } - if addon.Spec.ImagePullPolicy != nil { - if addon.Spec.Container.ImagePullPolicy == "" { - addon.Spec.Container.ImagePullPolicy = *addon.Spec.ImagePullPolicy - } - addon.Spec.ImagePullPolicy = nil - migrated = true + if len(err) == 0 { + ready.Status = v1.ConditionTrue + ready.Reason = api.Validated + ready.Message = strings.Join(err, ";") + } else { + ready.Status = v1.ConditionFalse + ready.Reason = api.ValidationError } + return +} + +// addonChanged an addon has been created/updated. +func (r *Reconciler) addonChanged(addon *api.Addon) (migrated bool, err error) { + migrated = addon.Migrate() if migrated { err = r.Update(context.TODO(), addon) if err != nil { return } } + if addon.Spec.Container.Image == "" { + cnd := api.ImageNotDefined + cnd.LastTransitionTime = v1.Now() + cnd.ObservedGeneration = addon.Status.ObservedGeneration + addon.Status.Conditions = append( + addon.Status.Conditions, + cnd) + } + return +} + +// addonDeleted an addon has been deleted. +func (r *Reconciler) addonDeleted(name string) (err error) { return } diff --git a/generated/crd/tackle.konveyor.io_addons.yaml b/generated/crd/tackle.konveyor.io_addons.yaml index ac7d70427..8e2771521 100644 --- a/generated/crd/tackle.konveyor.io_addons.yaml +++ b/generated/crd/tackle.konveyor.io_addons.yaml @@ -16,1287 +16,6 @@ spec: scope: Namespaced versions: - name: v1alpha1 - schema: - openAPIV3Schema: - description: Addon defines an addon. - 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: Spec defines the desired state of the resource. - properties: - container: - description: Container defines the addon container. - 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: - 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 - image: - description: Addon fqin. - type: string - imagePullPolicy: - default: IfNotPresent - description: ImagePullPolicy an optional image pull policy. - enum: - - IfNotPresent - - Always - - Never - type: string - metadata: - description: Metadata details. - type: object - x-kubernetes-preserve-unknown-fields: true - resources: - description: Resource requirements. - properties: - 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 defines criteria to be selected for a task. - type: string - task: - description: Task declares task (kind) compatibility. - type: string - required: - - image - type: object - status: - description: Status defines the observed state of the resource. - properties: - observedGeneration: - description: The most recent generation observed by the controller. - format: int64 - type: integer - type: object - type: object - served: false - storage: false - subresources: - status: {} - - name: v1alpha2 schema: openAPIV3Schema: properties: @@ -2555,12 +1274,79 @@ spec: task: description: Task declares task (kind) compatibility. type: string - required: - - container type: object status: description: Status defines the observed state of the resource. properties: + conditions: + description: Resource conditions. + items: + description: "Condition contains details for one aspect of the current + state of this API Resource. --- This struct is intended for direct + use as an array at the field path .status.conditions. For example, + \n type FooStatus struct{ // Represents the observations of a + foo's current state. // Known .status.conditions.type are: \"Available\", + \"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge + // +listType=map // +listMapKey=type Conditions []metav1.Condition + `json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\" + protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }" + properties: + lastTransitionTime: + description: lastTransitionTime is the last time the condition + transitioned from one status to another. This should be when + the underlying condition changed. If that is not known, then + using the time when the API field changed is acceptable. + format: date-time + type: string + message: + description: message is a human readable message indicating + details about the transition. This may be an empty string. + maxLength: 32768 + type: string + observedGeneration: + description: observedGeneration represents the .metadata.generation + that the condition was set based upon. For instance, if .metadata.generation + is currently 12, but the .status.conditions[x].observedGeneration + is 9, the condition is out of date with respect to the current + state of the instance. + format: int64 + minimum: 0 + type: integer + reason: + description: reason contains a programmatic identifier indicating + the reason for the condition's last transition. Producers + of specific condition types may define expected values and + meanings for this field, and whether the values are considered + a guaranteed API. The value should be a CamelCase string. + This field may not be empty. + maxLength: 1024 + minLength: 1 + pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ + type: string + status: + description: status of the condition, one of True, False, Unknown. + enum: + - "True" + - "False" + - Unknown + type: string + type: + description: type of condition in CamelCase or in foo.example.com/CamelCase. + --- Many .condition.type values are consistent across resources + like Available, but because arbitrary conditions can be useful + (see .node.status.conditions), the ability to deconflict is + important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) + maxLength: 316 + pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + type: array observedGeneration: description: The most recent generation observed by the controller. format: int64 diff --git a/generated/crd/tackle.konveyor.io_extensions.yaml b/generated/crd/tackle.konveyor.io_extensions.yaml index 9d9ab9cc3..8d893b9e2 100644 --- a/generated/crd/tackle.konveyor.io_extensions.yaml +++ b/generated/crd/tackle.konveyor.io_extensions.yaml @@ -16,28 +16,6 @@ spec: scope: Namespaced versions: - name: v1alpha1 - schema: - openAPIV3Schema: - description: Extension defines an addon extension. - 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 - type: object - served: false - storage: false - subresources: - status: {} - - name: v1alpha2 schema: openAPIV3Schema: description: Extension defines an addon extension. diff --git a/generated/crd/tackle.konveyor.io_tackles.yaml b/generated/crd/tackle.konveyor.io_tackles.yaml index c1b8af719..00987585c 100644 --- a/generated/crd/tackle.konveyor.io_tackles.yaml +++ b/generated/crd/tackle.konveyor.io_tackles.yaml @@ -16,36 +16,6 @@ spec: scope: Namespaced versions: - name: v1alpha1 - schema: - openAPIV3Schema: - description: Tackle defines a tackle application. - 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: Spec defines the desired state of the resource. - type: object - x-kubernetes-preserve-unknown-fields: true - status: - description: Status defines the observed state of the resource. - type: object - x-kubernetes-preserve-unknown-fields: true - type: object - served: true - storage: false - subresources: - status: {} - - name: v1alpha2 schema: openAPIV3Schema: description: Tackle defines a tackle application. diff --git a/generated/crd/tackle.konveyor.io_tasks.yaml b/generated/crd/tackle.konveyor.io_tasks.yaml index 9f4258947..3e0c175ff 100644 --- a/generated/crd/tackle.konveyor.io_tasks.yaml +++ b/generated/crd/tackle.konveyor.io_tasks.yaml @@ -16,28 +16,6 @@ spec: scope: Namespaced versions: - name: v1alpha1 - schema: - openAPIV3Schema: - description: Task defines a hub task. - 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 - type: object - served: false - storage: false - subresources: - status: {} - - name: v1alpha2 schema: openAPIV3Schema: description: Task defines a hub task. diff --git a/k8s/api/all.go b/k8s/api/all.go index 83ccee910..8e3aa14b3 100644 --- a/k8s/api/all.go +++ b/k8s/api/all.go @@ -6,7 +6,7 @@ you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - +` Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,7 +18,6 @@ package api import ( "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" - "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2" "k8s.io/apimachinery/pkg/runtime" ) @@ -27,8 +26,7 @@ var AddToSchemes runtime.SchemeBuilder func init() { AddToSchemes = append( AddToSchemes, - v1alpha1.SchemeBuilder.AddToScheme, - v1alpha2.SchemeBuilder.AddToScheme) + v1alpha1.SchemeBuilder.AddToScheme) } func AddToScheme(s *runtime.Scheme) error { diff --git a/k8s/api/tackle/v1alpha1/addon.go b/k8s/api/tackle/v1alpha1/addon.go index 0493e4686..c06e64e70 100644 --- a/k8s/api/tackle/v1alpha1/addon.go +++ b/k8s/api/tackle/v1alpha1/addon.go @@ -22,16 +22,17 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -// AddonSpec defines the desired state of an Addon. +// AddonSpec defines the desired state of the resource. type AddonSpec struct { - // Addon fqin. - Image string `json:"image"` - // ImagePullPolicy an optional image pull policy. - // +kubebuilder:default=IfNotPresent - // +kubebuilder:validation:Enum=IfNotPresent;Always;Never - ImagePullPolicy core.PullPolicy `json:"imagePullPolicy,omitempty"` - // Resource requirements. - Resources core.ResourceRequirements `json:"resources,omitempty"` + // Deprecated: Addon is deprecated. + // +kubebuilder:validation:Optional + Image *string `json:"image,omitempty"` + // Deprecated: ImagePullPolicy is deprecated. + // +kubebuilder:validation:Optional + ImagePullPolicy *core.PullPolicy `json:"imagePullPolicy,omitempty"` + // Deprecated: Resources is deprecated. + // +kubebuilder:validation:Optional + Resources *core.ResourceRequirements `json:"resources,omitempty"` // // Task declares task (kind) compatibility. Task string `json:"task,omitempty"` @@ -43,28 +44,78 @@ type AddonSpec struct { Metadata runtime.RawExtension `json:"metadata,omitempty"` } -// AddonStatus defines the observed state of an Addon. +// AddonStatus defines the observed state of the resource. type AddonStatus struct { // The most recent generation observed by the controller. // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` + // Resource conditions. + Conditions []meta.Condition `json:"conditions,omitempty"` } -// Addon defines an addon. // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:openapi-gen=true -// +kubebuilder:unservedversion +// +kubebuilder:storageversion // +kubebuilder:subresource:status type Addon struct { meta.TypeMeta `json:",inline"` meta.ObjectMeta `json:"metadata,omitempty"` // Spec defines the desired state of the resource. - Spec AddonSpec `json:"spec,omitempty"` + Spec AddonSpec `json:"spec"` // Status defines the observed state of the resource. Status AddonStatus `json:"status,omitempty"` } +// Reconciled returns true when the resource has been reconciled. +func (r *Addon) Reconciled() (b bool) { + return r.Generation == r.Status.ObservedGeneration +} + +// Ready returns true when resource has the ready condition. +func (r *Addon) Ready() (ready bool) { + for _, cnd := range r.Status.Conditions { + if cnd.Type == Ready.Type && cnd.Status == meta.ConditionTrue { + ready = true + break + } + } + return +} + +// Migrate specification as needed. +func (r *Addon) Migrate() (updated bool) { + if r.Spec.Image != nil { + if r.Spec.Container.Image == "" { + r.Spec.Container.Image = *r.Spec.Image + } + r.Spec.Image = nil + updated = true + } + if r.Spec.Resources != nil { + if len(r.Spec.Container.Resources.Limits) == 0 { + r.Spec.Container.Resources.Limits = (*r.Spec.Resources).Limits + } + if len(r.Spec.Container.Resources.Requests) == 0 { + r.Spec.Container.Resources.Requests = (*r.Spec.Resources).Requests + } + r.Spec.Resources = nil + updated = true + } + if r.Spec.ImagePullPolicy != nil { + if r.Spec.Container.ImagePullPolicy == "" { + r.Spec.Container.ImagePullPolicy = *r.Spec.ImagePullPolicy + } + r.Spec.ImagePullPolicy = nil + updated = true + } + if r.Spec.Container.Name == "" { + r.Spec.Container.Name = "addon" + updated = true + } + return +} + // AddonList is a list of Addon. // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type AddonList struct { diff --git a/k8s/api/tackle/v1alpha1/extension.go b/k8s/api/tackle/v1alpha1/extension.go index 03a3fb367..c6826b586 100644 --- a/k8s/api/tackle/v1alpha1/extension.go +++ b/k8s/api/tackle/v1alpha1/extension.go @@ -17,18 +17,43 @@ limitations under the License. package v1alpha1 import ( + core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) +// ExtensionSpec defines the desired state of the resource. +type ExtensionSpec struct { + // Addon (name) declares addon compatibility. + Addon string `json:"addon"` + // Container defines the extension container. + Container core.Container `json:"container"` + // Selector defines criteria to be included in the addon pod. + Selector string `json:"selector,omitempty"` + // Metadata details. + Metadata runtime.RawExtension `json:"metadata,omitempty"` +} + +// ExtensionStatus defines the observed state of the resource. +type ExtensionStatus struct { + // The most recent generation observed by the controller. + // +optional + ObservedGeneration int64 `json:"observedGeneration,omitempty"` +} + // Extension defines an addon extension. // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:openapi-gen=true -// +kubebuilder:unservedversion +// +kubebuilder:storageversion // +kubebuilder:subresource:status type Extension struct { meta.TypeMeta `json:",inline"` meta.ObjectMeta `json:"metadata,omitempty"` + // pec defines the desired state of the resource. + Spec ExtensionSpec `json:"spec"` + // Status defines the observed state of the resource. + Status ExtensionStatus `json:"status,omitempty"` } // ExtensionList is a list of Extension. diff --git a/k8s/api/tackle/v1alpha1/pkg.go b/k8s/api/tackle/v1alpha1/pkg.go new file mode 100644 index 000000000..9f7a3982b --- /dev/null +++ b/k8s/api/tackle/v1alpha1/pkg.go @@ -0,0 +1,23 @@ +package v1alpha1 + +import ( + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + ValidationError = "ValidationError" + Validated = "Validated" +) + +var ( + Ready = meta.Condition{ + Type: "Ready", + Status: meta.ConditionTrue, + } + ImageNotDefined = meta.Condition{ + Type: ValidationError, + Status: meta.ConditionTrue, + Reason: "ImageNotDefined", + Message: "Either image or container.image must be specified.", + } +) diff --git a/k8s/api/tackle/v1alpha1/tackle.go b/k8s/api/tackle/v1alpha1/tackle.go index b237e1475..ea3e1666f 100644 --- a/k8s/api/tackle/v1alpha1/tackle.go +++ b/k8s/api/tackle/v1alpha1/tackle.go @@ -25,6 +25,7 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:openapi-gen=true +// +kubebuilder:storageversion // +kubebuilder:subresource:status type Tackle struct { meta.TypeMeta `json:",inline"` diff --git a/k8s/api/tackle/v1alpha1/task.go b/k8s/api/tackle/v1alpha1/task.go index 4751b639f..fd92b9fe7 100644 --- a/k8s/api/tackle/v1alpha1/task.go +++ b/k8s/api/tackle/v1alpha1/task.go @@ -17,18 +17,64 @@ limitations under the License. package v1alpha1 import ( + "encoding/json" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) +// TaskSpec defines the desired state the resource. +type TaskSpec struct { + // Priority defines the task priority (0-n). + Priority int `json:"priority,omitempty"` + // Dependencies defines a list of task names on which this task depends. + Dependencies []string `json:"dependencies,omitempty"` + // Data object passed to the addon. + Data runtime.RawExtension `json:"data,omitempty"` +} + +// TaskStatus defines the observed state the resource. +type TaskStatus struct { + // The most recent generation observed by the controller. + // +optional + ObservedGeneration int64 `json:"observedGeneration,omitempty"` +} + // Task defines a hub task. // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:openapi-gen=true -// +kubebuilder:unservedversion +// +kubebuilder:storageversion // +kubebuilder:subresource:status type Task struct { meta.TypeMeta `json:",inline"` meta.ObjectMeta `json:"metadata,omitempty"` + // Spec defines the desired state the resource. + Spec TaskSpec `json:"spec,omitempty"` + // Status defines the observed state the resource. + Status TaskStatus `json:"status,omitempty"` +} + +// HasDep return true if the task has the dependency. +func (r *Task) HasDep(name string) (found bool) { + for i := range r.Spec.Dependencies { + n := r.Spec.Dependencies[i] + if n == name { + found = true + break + } + } + return +} + +// Data returns the task Data as map[string]any. +func (r *Task) Data() (mp map[string]any) { + b := r.Spec.Data.Raw + if b == nil { + return + } + _ = json.Unmarshal(b, &mp) + return } // TaskList is a list of Task. diff --git a/k8s/api/tackle/v1alpha1/zz_generated.deepcopy.go b/k8s/api/tackle/v1alpha1/zz_generated.deepcopy.go index d5e524a56..abc30ac83 100644 --- a/k8s/api/tackle/v1alpha1/zz_generated.deepcopy.go +++ b/k8s/api/tackle/v1alpha1/zz_generated.deepcopy.go @@ -22,6 +22,8 @@ limitations under the License. package v1alpha1 import ( + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -31,7 +33,7 @@ func (in *Addon) DeepCopyInto(out *Addon) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Addon. @@ -87,7 +89,21 @@ func (in *AddonList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AddonSpec) DeepCopyInto(out *AddonSpec) { *out = *in - in.Resources.DeepCopyInto(&out.Resources) + if in.Image != nil { + in, out := &in.Image, &out.Image + *out = new(string) + **out = **in + } + if in.ImagePullPolicy != nil { + in, out := &in.ImagePullPolicy, &out.ImagePullPolicy + *out = new(v1.PullPolicy) + **out = **in + } + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = new(v1.ResourceRequirements) + (*in).DeepCopyInto(*out) + } in.Container.DeepCopyInto(&out.Container) in.Metadata.DeepCopyInto(&out.Metadata) } @@ -105,6 +121,13 @@ func (in *AddonSpec) DeepCopy() *AddonSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AddonStatus) DeepCopyInto(out *AddonStatus) { *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]metav1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddonStatus. @@ -122,6 +145,8 @@ func (in *Extension) DeepCopyInto(out *Extension) { *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 Extension. @@ -174,6 +199,38 @@ func (in *ExtensionList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExtensionSpec) DeepCopyInto(out *ExtensionSpec) { + *out = *in + in.Container.DeepCopyInto(&out.Container) + in.Metadata.DeepCopyInto(&out.Metadata) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExtensionSpec. +func (in *ExtensionSpec) DeepCopy() *ExtensionSpec { + if in == nil { + return nil + } + out := new(ExtensionSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExtensionStatus) DeepCopyInto(out *ExtensionStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExtensionStatus. +func (in *ExtensionStatus) DeepCopy() *ExtensionStatus { + if in == nil { + return nil + } + out := new(ExtensionStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Tackle) DeepCopyInto(out *Tackle) { *out = *in @@ -238,6 +295,8 @@ func (in *Task) DeepCopyInto(out *Task) { *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 Task. @@ -289,3 +348,39 @@ func (in *TaskList) DeepCopyObject() runtime.Object { } return nil } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TaskSpec) DeepCopyInto(out *TaskSpec) { + *out = *in + if in.Dependencies != nil { + in, out := &in.Dependencies, &out.Dependencies + *out = make([]string, len(*in)) + copy(*out, *in) + } + in.Data.DeepCopyInto(&out.Data) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskSpec. +func (in *TaskSpec) DeepCopy() *TaskSpec { + if in == nil { + return nil + } + out := new(TaskSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TaskStatus) DeepCopyInto(out *TaskStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskStatus. +func (in *TaskStatus) DeepCopy() *TaskStatus { + if in == nil { + return nil + } + out := new(TaskStatus) + in.DeepCopyInto(out) + return out +} diff --git a/k8s/api/tackle/v1alpha2/addon.go b/k8s/api/tackle/v1alpha2/addon.go deleted file mode 100644 index e7689f221..000000000 --- a/k8s/api/tackle/v1alpha2/addon.go +++ /dev/null @@ -1,78 +0,0 @@ -/* -Copyright 2019 Red Hat Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha2 - -import ( - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" -) - -// AddonSpec defines the desired state of the resource. -type AddonSpec struct { - // Deprecated: Addon is deprecated. - // +kubebuilder:validation:Optional - Image *string `json:"image,omitempty"` - // Deprecated: ImagePullPolicy is deprecated. - // +kubebuilder:validation:Optional - ImagePullPolicy *core.PullPolicy `json:"imagePullPolicy,omitempty"` - // Deprecated: Resources is deprecated. - // +kubebuilder:validation:Optional - Resources *core.ResourceRequirements `json:"resources,omitempty"` - // - // Task declares task (kind) compatibility. - Task string `json:"task,omitempty"` - // Selector defines criteria to be selected for a task. - Selector string `json:"selector,omitempty"` - // Container defines the addon container. - Container core.Container `json:"container"` - // Metadata details. - Metadata runtime.RawExtension `json:"metadata,omitempty"` -} - -// AddonStatus defines the observed state of the resource. -type AddonStatus struct { - // The most recent generation observed by the controller. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` -} - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:openapi-gen=true -// +kubebuilder:storageversion -// +kubebuilder:subresource:status -type Addon struct { - meta.TypeMeta `json:",inline"` - meta.ObjectMeta `json:"metadata,omitempty"` - // Spec defines the desired state of the resource. - Spec AddonSpec `json:"spec"` - // Status defines the observed state of the resource. - Status AddonStatus `json:"status,omitempty"` -} - -// AddonList is a list of Addon. -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type AddonList struct { - meta.TypeMeta `json:",inline"` - meta.ListMeta `json:"metadata,omitempty"` - Items []Addon `json:"items"` -} - -func init() { - SchemeBuilder.Register(&Addon{}, &AddonList{}) -} diff --git a/k8s/api/tackle/v1alpha2/extension.go b/k8s/api/tackle/v1alpha2/extension.go deleted file mode 100644 index c2857fdc8..000000000 --- a/k8s/api/tackle/v1alpha2/extension.go +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright 2019 Red Hat Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha2 - -import ( - core "k8s.io/api/core/v1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" -) - -// ExtensionSpec defines the desired state of the resource. -type ExtensionSpec struct { - // Addon (name) declares addon compatibility. - Addon string `json:"addon"` - // Container defines the extension container. - Container core.Container `json:"container"` - // Selector defines criteria to be included in the addon pod. - Selector string `json:"selector,omitempty"` - // Metadata details. - Metadata runtime.RawExtension `json:"metadata,omitempty"` -} - -// ExtensionStatus defines the observed state of the resource. -type ExtensionStatus struct { - // The most recent generation observed by the controller. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` -} - -// Extension defines an addon extension. -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:openapi-gen=true -// +kubebuilder:storageversion -// +kubebuilder:subresource:status -type Extension struct { - meta.TypeMeta `json:",inline"` - meta.ObjectMeta `json:"metadata,omitempty"` - // pec defines the desired state of the resource. - Spec ExtensionSpec `json:"spec"` - // Status defines the observed state of the resource. - Status ExtensionStatus `json:"status,omitempty"` -} - -// ExtensionList is a list of Extension. -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type ExtensionList struct { - meta.TypeMeta `json:",inline"` - meta.ListMeta `json:"metadata,omitempty"` - Items []Extension `json:"items"` -} - -func init() { - SchemeBuilder.Register(&Extension{}, &ExtensionList{}) -} diff --git a/k8s/api/tackle/v1alpha2/register.go b/k8s/api/tackle/v1alpha2/register.go deleted file mode 100644 index 4d8dd0a30..000000000 --- a/k8s/api/tackle/v1alpha2/register.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2019 Red Hat Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v1alpha1 contains API Schema definitions for the migration v1alpha1 API group. -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=github.com/konveyor/tackle2-controller/pkg/apis/migration -// +k8s:defaulter-gen=TypeMeta -// +groupName=tackle.konveyor.io -package v1alpha2 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" -) - -var SchemeGroupVersion = schema.GroupVersion{ - Group: "tackle.konveyor.io", - Version: "v1alpha2", -} - -var SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} diff --git a/k8s/api/tackle/v1alpha2/tackle.go b/k8s/api/tackle/v1alpha2/tackle.go deleted file mode 100644 index 92cdcf12b..000000000 --- a/k8s/api/tackle/v1alpha2/tackle.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2019 Red Hat Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha2 - -import ( - "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// Tackle defines a tackle application. -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:openapi-gen=true -// +kubebuilder:storageversion -// +kubebuilder:subresource:status -type Tackle v1alpha1.Tackle - -// TackleList is a list of Tackle. -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type TackleList struct { - meta.TypeMeta `json:",inline"` - meta.ListMeta `json:"metadata,omitempty"` - Items []Tackle `json:"items"` -} - -func init() { - SchemeBuilder.Register(&TackleList{}, &Tackle{}) -} diff --git a/k8s/api/tackle/v1alpha2/task.go b/k8s/api/tackle/v1alpha2/task.go deleted file mode 100644 index 2e5180dcf..000000000 --- a/k8s/api/tackle/v1alpha2/task.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2019 Red Hat Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha2 - -import ( - "encoding/json" - - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" -) - -// TaskSpec defines the desired state the resource. -type TaskSpec struct { - // Priority defines the task priority (0-n). - Priority int `json:"priority,omitempty"` - // Dependencies defines a list of task names on which this task depends. - Dependencies []string `json:"dependencies,omitempty"` - // Data object passed to the addon. - Data runtime.RawExtension `json:"data,omitempty"` -} - -// TaskStatus defines the observed state the resource. -type TaskStatus struct { - // The most recent generation observed by the controller. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` -} - -// Task defines a hub task. -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:openapi-gen=true -// +kubebuilder:storageversion -// +kubebuilder:subresource:status -type Task struct { - meta.TypeMeta `json:",inline"` - meta.ObjectMeta `json:"metadata,omitempty"` - // Spec defines the desired state the resource. - Spec TaskSpec `json:"spec,omitempty"` - // Status defines the observed state the resource. - Status TaskStatus `json:"status,omitempty"` -} - -// HasDep return true if the task has the dependency. -func (r *Task) HasDep(name string) (found bool) { - for i := range r.Spec.Dependencies { - n := r.Spec.Dependencies[i] - if n == name { - found = true - break - } - } - return -} - -// Data returns the task Data as map[string]any. -func (r *Task) Data() (mp map[string]any) { - b := r.Spec.Data.Raw - if b == nil { - return - } - _ = json.Unmarshal(b, &mp) - return -} - -// TaskList is a list of Task. -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type TaskList struct { - meta.TypeMeta `json:",inline"` - meta.ListMeta `json:"metadata,omitempty"` - Items []Task `json:"items"` -} - -func init() { - SchemeBuilder.Register(&Task{}, &TaskList{}) -} diff --git a/k8s/api/tackle/v1alpha2/zz_generated.deepcopy.go b/k8s/api/tackle/v1alpha2/zz_generated.deepcopy.go deleted file mode 100644 index 244028496..000000000 --- a/k8s/api/tackle/v1alpha2/zz_generated.deepcopy.go +++ /dev/null @@ -1,378 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright 2019 Red Hat Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1alpha2 - -import ( - "k8s.io/api/core/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 *Addon) DeepCopyInto(out *Addon) { - *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 Addon. -func (in *Addon) DeepCopy() *Addon { - if in == nil { - return nil - } - out := new(Addon) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Addon) 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 *AddonList) DeepCopyInto(out *AddonList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Addon, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddonList. -func (in *AddonList) DeepCopy() *AddonList { - if in == nil { - return nil - } - out := new(AddonList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *AddonList) 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 *AddonSpec) DeepCopyInto(out *AddonSpec) { - *out = *in - if in.Image != nil { - in, out := &in.Image, &out.Image - *out = new(string) - **out = **in - } - if in.ImagePullPolicy != nil { - in, out := &in.ImagePullPolicy, &out.ImagePullPolicy - *out = new(v1.PullPolicy) - **out = **in - } - if in.Resources != nil { - in, out := &in.Resources, &out.Resources - *out = new(v1.ResourceRequirements) - (*in).DeepCopyInto(*out) - } - in.Container.DeepCopyInto(&out.Container) - in.Metadata.DeepCopyInto(&out.Metadata) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddonSpec. -func (in *AddonSpec) DeepCopy() *AddonSpec { - if in == nil { - return nil - } - out := new(AddonSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AddonStatus) DeepCopyInto(out *AddonStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddonStatus. -func (in *AddonStatus) DeepCopy() *AddonStatus { - if in == nil { - return nil - } - out := new(AddonStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Extension) DeepCopyInto(out *Extension) { - *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 Extension. -func (in *Extension) DeepCopy() *Extension { - if in == nil { - return nil - } - out := new(Extension) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Extension) 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 *ExtensionList) DeepCopyInto(out *ExtensionList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Extension, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExtensionList. -func (in *ExtensionList) DeepCopy() *ExtensionList { - if in == nil { - return nil - } - out := new(ExtensionList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ExtensionList) 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 *ExtensionSpec) DeepCopyInto(out *ExtensionSpec) { - *out = *in - in.Container.DeepCopyInto(&out.Container) - in.Metadata.DeepCopyInto(&out.Metadata) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExtensionSpec. -func (in *ExtensionSpec) DeepCopy() *ExtensionSpec { - if in == nil { - return nil - } - out := new(ExtensionSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ExtensionStatus) DeepCopyInto(out *ExtensionStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExtensionStatus. -func (in *ExtensionStatus) DeepCopy() *ExtensionStatus { - if in == nil { - return nil - } - out := new(ExtensionStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Tackle) DeepCopyInto(out *Tackle) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Tackle. -func (in *Tackle) DeepCopy() *Tackle { - if in == nil { - return nil - } - out := new(Tackle) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Tackle) 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 *TackleList) DeepCopyInto(out *TackleList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Tackle, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TackleList. -func (in *TackleList) DeepCopy() *TackleList { - if in == nil { - return nil - } - out := new(TackleList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TackleList) 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 *Task) DeepCopyInto(out *Task) { - *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 Task. -func (in *Task) DeepCopy() *Task { - if in == nil { - return nil - } - out := new(Task) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Task) 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 *TaskList) DeepCopyInto(out *TaskList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Task, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskList. -func (in *TaskList) DeepCopy() *TaskList { - if in == nil { - return nil - } - out := new(TaskList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TaskList) 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 *TaskSpec) DeepCopyInto(out *TaskSpec) { - *out = *in - if in.Dependencies != nil { - in, out := &in.Dependencies, &out.Dependencies - *out = make([]string, len(*in)) - copy(*out, *in) - } - in.Data.DeepCopyInto(&out.Data) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskSpec. -func (in *TaskSpec) DeepCopy() *TaskSpec { - if in == nil { - return nil - } - out := new(TaskSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TaskStatus) DeepCopyInto(out *TaskStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskStatus. -func (in *TaskStatus) DeepCopy() *TaskStatus { - if in == nil { - return nil - } - out := new(TaskStatus) - in.DeepCopyInto(out) - return out -} diff --git a/reflect/db.go b/reflect/db.go new file mode 100644 index 000000000..6b100ef3c --- /dev/null +++ b/reflect/db.go @@ -0,0 +1,27 @@ +package reflect + +import ( + "gorm.io/gorm" +) + +// Select returns DB.Select() with validated fields. +func Select(in *gorm.DB, m any, fields ...string) (out *gorm.DB) { + fields, err := HasFields(m, fields...) + out = in.Select(fields) + if err != nil { + out.Statement.Error = err + return + } + return +} + +// Omit returns DB.Omit() with validated fields. +func Omit(in *gorm.DB, m any, fields ...string) (out *gorm.DB) { + fields, err := HasFields(m, fields...) + out = in.Omit(fields...) + if err != nil { + out.Statement.Error = err + return + } + return +} diff --git a/reflect/error.go b/reflect/error.go new file mode 100644 index 000000000..c4a369c25 --- /dev/null +++ b/reflect/error.go @@ -0,0 +1,25 @@ +package reflect + +import ( + "errors" + "fmt" +) + +// FieldNotValid report field not valid. +type FieldNotValid struct { + Kind string + Name string +} + +func (e *FieldNotValid) Error() string { + return fmt.Sprintf( + "(%s) '%s' not valid.", + e.Kind, + e.Name) +} + +func (e *FieldNotValid) Is(err error) (matched bool) { + var inst *FieldNotValid + matched = errors.As(err, &inst) + return +} diff --git a/api/reflect/fields.go b/reflect/fields.go similarity index 58% rename from api/reflect/fields.go rename to reflect/fields.go index 933c7e73d..73e593c2f 100644 --- a/api/reflect/fields.go +++ b/reflect/fields.go @@ -3,9 +3,13 @@ package reflect import ( "reflect" "time" + + liberr "github.com/jortel/go-utils/error" ) // Fields returns a map of fields. +// Used for: +// - db.Updates() func Fields(m any) (mp map[string]any) { var inspect func(r any) inspect = func(r any) { @@ -82,3 +86,55 @@ func NameOf(m any) (name string) { } return } + +// HasFields returns the validated field names. +// Used for: +// - db.Omit() +// - db.Select() +func HasFields(m any, in ...string) (out []string, err error) { + mp := make(map[string]any) + var inspect func(r any) + inspect = func(r any) { + mt := reflect.TypeOf(r) + mv := reflect.ValueOf(r) + if mt.Kind() == reflect.Ptr { + mt = mt.Elem() + mv = mv.Elem() + } + for i := 0; i < mt.NumField(); i++ { + ft := mt.Field(i) + fv := mv.Field(i) + if !ft.IsExported() { + continue + } + switch fv.Kind() { + case reflect.Ptr: + inst := fv.Interface() + mp[ft.Name] = inst + case reflect.Struct: + if ft.Anonymous { + inspect(fv.Addr().Interface()) + continue + } + inst := fv.Interface() + mp[ft.Name] = inst + default: + mp[ft.Name] = fv.Interface() + } + } + } + inspect(m) + for _, name := range in { + _, found := mp[name] + if !found { + err = &FieldNotValid{ + Kind: NameOf(m), + Name: name, + } + err = liberr.Wrap(err) + return + } + } + out = in + return +} diff --git a/task/error.go b/task/error.go index b6786c86b..5063de5d1 100644 --- a/task/error.go +++ b/task/error.go @@ -110,6 +110,51 @@ func (e *AddonNotSelected) Retry() (r bool) { return } +// NotReady report that a resource does not have the ready condition. +type NotReady struct { + Kind string + Name string + Reason string +} + +func (e *NotReady) Error() string { + return fmt.Sprintf( + "(%s) '%s' not ready: %s.", + e.Kind, + e.Name, + e.Reason) +} + +func (e *NotReady) Is(err error) (matched bool) { + var inst *NotReady + matched = errors.As(err, &inst) + return +} + +func (e *NotReady) Retry() (r bool) { + return +} + +// NotReconciled report as resource has not been reconciled. +type NotReconciled struct { + Kind string + Name string +} + +func (e *NotReconciled) Error() string { + return fmt.Sprintf("(%s) '%s' not reconciled.", e.Kind, e.Name) +} + +func (e *NotReconciled) Is(err error) (matched bool) { + var inst *NotReconciled + matched = errors.As(err, &inst) + return +} + +func (e *NotReconciled) Retry() (r bool) { + return +} + // ExtensionNotFound used to report an extension referenced // by a task but cannot be found. type ExtensionNotFound struct { diff --git a/task/manager.go b/task/manager.go index 6d2f8a4c6..914c23999 100644 --- a/task/manager.go +++ b/task/manager.go @@ -2,6 +2,7 @@ package task import ( "context" + "errors" "fmt" "io" "os" @@ -17,9 +18,10 @@ import ( "github.com/jortel/go-utils/logr" "github.com/konveyor/tackle2-hub/auth" k8s2 "github.com/konveyor/tackle2-hub/k8s" - crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2" + crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" "github.com/konveyor/tackle2-hub/metrics" "github.com/konveyor/tackle2-hub/model" + "github.com/konveyor/tackle2-hub/reflect" "github.com/konveyor/tackle2-hub/settings" "gopkg.in/yaml.v2" "gorm.io/gorm" @@ -124,7 +126,11 @@ func (m *Manager) Run(ctx context.Context) { m.startReady() m.pause() } else { - Log.Error(err, "") + if errors.Is(err, &NotReconciled{}) { + Log.Info(err.Error()) + } else { + Log.Error(err, "") + } m.pause() } } @@ -182,7 +188,9 @@ func (m *Manager) Update(db *gorm.DB, requested *Task) (err error) { } switch found.State { case Created: - db = db.Select( + db = reflect.Select( + db, + requested, "UpdateUser", "Name", "Kind", @@ -209,7 +217,9 @@ func (m *Manager) Update(db *gorm.DB, requested *Task) (err error) { Pending, QuotaBlocked, Postponed: - db = db.Select( + db = reflect.Select( + db, + requested, "UpdateUser", "Name", "Locator", @@ -518,6 +528,13 @@ func (m *Manager) selectAddon(task *Task) (addon *crd.Addon, err error) { err = &AddonNotSelected{} return } + if !selected.Ready() { + err = &NotReady{ + Kind: "Addon", + Name: selected.Name, + } + return + } task.Addon = selected.Name task.Event(AddonSelected, selected) return @@ -1643,7 +1660,9 @@ func (r *Task) containsAny(str string, substr ...string) (matched bool) { // update manager controlled fields. func (r *Task) update(db *gorm.DB) (err error) { - db = db.Select( + db = reflect.Select( + db, + r.Task, "Addon", "Extensions", "State", @@ -1651,7 +1670,7 @@ func (r *Task) update(db *gorm.DB) (err error) { "Started", "Terminated", "Events", - "Error", + "Errors", "Retries", "Attached", "Pod") @@ -1903,6 +1922,13 @@ func (k *Cluster) getAddons() (err error) { for i := range list.Items { r := &list.Items[i] k.addons[r.Name] = r + if !r.Reconciled() { + err = &NotReconciled{ + Kind: r.Kind, + Name: r.Name, + } + return + } } return } diff --git a/task/task_test.go b/task/task_test.go index 80fe29bb3..e088769e0 100644 --- a/task/task_test.go +++ b/task/task_test.go @@ -3,7 +3,7 @@ package task import ( "testing" - crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2" + crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" "github.com/konveyor/tackle2-hub/model" "github.com/onsi/gomega" ) diff --git a/trigger/pkg.go b/trigger/pkg.go index 20bd344e5..189a598ad 100644 --- a/trigger/pkg.go +++ b/trigger/pkg.go @@ -4,7 +4,7 @@ import ( "context" liberr "github.com/jortel/go-utils/error" - crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2" + crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" "github.com/konveyor/tackle2-hub/settings" tasking "github.com/konveyor/tackle2-hub/task" "gorm.io/gorm" From 15b11a8846363b54b071cb90a3c85f29448c3803 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Wed, 24 Jul 2024 12:30:47 -0500 Subject: [PATCH 07/12] :bug: Fix reflect HasField() with anonymous pointer field. (#736) Signed-off-by: Jeff Ortel --- reflect/fields.go | 17 ++++++++++ reflect/reflect_test.go | 72 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 reflect/reflect_test.go diff --git a/reflect/fields.go b/reflect/fields.go index 73e593c2f..a220de448 100644 --- a/reflect/fields.go +++ b/reflect/fields.go @@ -1,6 +1,7 @@ package reflect import ( + "fmt" "reflect" "time" @@ -92,6 +93,18 @@ func NameOf(m any) (name string) { // - db.Omit() // - db.Select() func HasFields(m any, in ...string) (out []string, err error) { + defer func() { + p := recover() + if p != nil { + if pe, cast := p.(error); cast { + err = pe + } else { + err = fmt.Errorf( + "(paniced) failed: %#v", + p) + } + } + }() mp := make(map[string]any) var inspect func(r any) inspect = func(r any) { @@ -109,6 +122,10 @@ func HasFields(m any, in ...string) (out []string, err error) { } switch fv.Kind() { case reflect.Ptr: + if ft.Anonymous { + inspect(fv.Interface()) + continue + } inst := fv.Interface() mp[ft.Name] = inst case reflect.Struct: diff --git a/reflect/reflect_test.go b/reflect/reflect_test.go new file mode 100644 index 000000000..7b2431042 --- /dev/null +++ b/reflect/reflect_test.go @@ -0,0 +1,72 @@ +package reflect + +import ( + "errors" + "testing" + + "github.com/onsi/gomega" +) + +func TestHasField(t *testing.T) { + g := gomega.NewGomegaWithT(t) + type B struct { + Name string + Age string + } + type B2 struct { + Name2 string + Age2 string + } + type M struct { + B + *B2 + Ptr *B + Object B + Int int + IntPtr *int + List []string + } + + // Test expected. + _, err := HasFields( + &M{B2: &B2{}}, + "Name", + "Age", + "Name2", + "Age2", + "Ptr", + "Object", + "Int", + "IntPtr", + "List") + g.Expect(err).To(gomega.BeNil()) + + // Test anonymous NIL pointer. + _, err = HasFields( + &M{}, // PROBLEM HERE. + "Name", + "Age", + "Name2", + "Age2", + "Ptr", + "Object", + "Int", + "IntPtr", + "List") + g.Expect(err).ToNot(gomega.BeNil()) + + // Invalid field. + _, err = HasFields( + &M{B2: &B2{}}, + "Name", + "Age", + "Name2", + "Age2", + "Ptr", + "NOT-VALID", // PROBLEM HERE + "Object", + "Int", + "IntPtr", + "List") + g.Expect(errors.Is(err, &FieldNotValid{})).To(gomega.BeTrue()) +} From 8bb3c0911660ef31873ba7a30a4c06f5a71a81f1 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Fri, 26 Jul 2024 07:55:02 -0500 Subject: [PATCH 08/12] :bug: Fix task reaper using TTL.Failed. (#734) Signed-off-by: Jeff Ortel --- reaper/task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reaper/task.go b/reaper/task.go index b78f06a17..3f73432f1 100644 --- a/reaper/task.go +++ b/reaper/task.go @@ -113,7 +113,7 @@ func (r *TaskReaper) Run() { if m.Terminated != nil { mark = *m.Terminated } - if m.TTL.Succeeded > 0 { + if m.TTL.Failed > 0 { d := time.Duration(m.TTL.Failed) * Unit if time.Since(mark) > d { r.delete(m) From 65d0910fd6addb6761fa38d752c18108dbf5ced0 Mon Sep 17 00:00:00 2001 From: Samuel Lucidi Date: Fri, 26 Jul 2024 15:29:20 -0400 Subject: [PATCH 09/12] :seedling: Omit associations during Create operations (#733) When inserting a new record, GORM will also attempt to insert records into tables refered to by many-to-many relationships on the inserted record. This commit attempts to ensure that associations are omitted when inserting records, and then the associations are added to the join tables separately. Also fixes some spots where the Transaction handler was in the wrong spot in the chain or missing entirely. Fixes https://github.com/konveyor/tackle2-hub/issues/727 --------- Signed-off-by: Sam Lucidi --- api/application.go | 39 +++++++++++++++++++++++++++++++-------- api/archetype.go | 35 +++++++++++++++++++++++++++++++++-- api/group.go | 12 +++++++++++- api/identity.go | 2 +- api/migrationwave.go | 17 ++++++++++++++++- api/stakeholder.go | 22 +++++++++++++++++++++- 6 files changed, 113 insertions(+), 14 deletions(-) diff --git a/api/application.go b/api/application.go index 7169d1c2e..3d4940c89 100644 --- a/api/application.go +++ b/api/application.go @@ -58,22 +58,22 @@ func (h ApplicationHandler) AddRoutes(e *gin.Engine) { routeGroup.DELETE(ApplicationRoot, h.Delete) // Tags routeGroup = e.Group("/") - routeGroup.Use(Required("applications")) + routeGroup.Use(Required("applications"), Transaction) routeGroup.GET(ApplicationTagsRoot, h.TagList) routeGroup.GET(ApplicationTagsRoot+"/", h.TagList) routeGroup.POST(ApplicationTagsRoot, h.TagAdd) routeGroup.DELETE(ApplicationTagRoot, h.TagDelete) - routeGroup.PUT(ApplicationTagsRoot, h.TagReplace, Transaction) + routeGroup.PUT(ApplicationTagsRoot, h.TagReplace) // Facts routeGroup = e.Group("/") - routeGroup.Use(Required("applications.facts")) + routeGroup.Use(Required("applications.facts"), Transaction) routeGroup.GET(ApplicationFactsRoot, h.FactGet) routeGroup.GET(ApplicationFactsRoot+"/", h.FactGet) routeGroup.POST(ApplicationFactsRoot, h.FactCreate) routeGroup.GET(ApplicationFactRoot, h.FactGet) routeGroup.PUT(ApplicationFactRoot, h.FactPut) routeGroup.DELETE(ApplicationFactRoot, h.FactDelete) - routeGroup.PUT(ApplicationFactsRoot, h.FactPut, Transaction) + routeGroup.PUT(ApplicationFactsRoot, h.FactPut) // Bucket routeGroup = e.Group("/") routeGroup.Use(Required("applications.bucket")) @@ -84,11 +84,11 @@ func (h ApplicationHandler) AddRoutes(e *gin.Engine) { routeGroup.DELETE(AppBucketContentRoot, h.BucketDelete) // Stakeholders routeGroup = e.Group("/") - routeGroup.Use(Required("applications.stakeholders")) + routeGroup.Use(Required("applications.stakeholders"), Transaction) routeGroup.PUT(AppStakeholdersRoot, h.StakeholdersUpdate) // Assessments routeGroup = e.Group("/") - routeGroup.Use(Required("applications.assessments")) + routeGroup.Use(Required("applications.assessments"), Transaction) routeGroup.GET(AppAssessmentsRoot, h.AssessmentList) routeGroup.POST(AppAssessmentsRoot, h.AssessmentCreate) } @@ -210,11 +210,23 @@ func (h ApplicationHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.BaseHandler.CurrentUser(ctx) - result := h.DB(ctx).Omit("Tags").Create(m) + result := h.DB(ctx).Omit(clause.Associations).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + db := h.DB(ctx).Model(m) + err = db.Association("Identities").Replace(m.Identities) + if err != nil { + _ = ctx.Error(err) + return + } + db = h.DB(ctx).Model(m) + err = db.Association("Contributors").Replace(m.Contributors) + if err != nil { + _ = ctx.Error(err) + return + } tags := []model.ApplicationTag{} if len(r.Tags) > 0 { @@ -1078,11 +1090,21 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) { assessment.PrepareForApplication(resolver, application, m) newAssessment = true } - result = h.DB(ctx).Create(m) + result = h.DB(ctx).Omit(clause.Associations).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups) + if err != nil { + _ = ctx.Error(err) + return + } if newAssessment { metrics.AssessmentsInitiated.Inc() } @@ -1138,6 +1160,7 @@ func (r *Application) With(m *model.Application, tags []model.ApplicationTag) { r.Identities, ref) } + r.Tags = []TagRef{} for i := range tags { ref := TagRef{} ref.With(tags[i].TagID, tags[i].Tag.Name, tags[i].Source, false) diff --git a/api/archetype.go b/api/archetype.go index d62d88a13..bcadf05cd 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -136,12 +136,33 @@ func (h ArchetypeHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.CurrentUser(ctx) - result := h.DB(ctx).Create(m) + result := h.DB(ctx).Omit(clause.Associations).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("CriteriaTags").Replace("CriteriaTags", m.CriteriaTags) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("Tags").Replace("Tags", m.Tags) + if err != nil { + _ = ctx.Error(err) + return + } + archetypes := []model.Archetype{} db := h.preLoad(h.DB(ctx), "Tags", "CriteriaTags") result = db.Find(&archetypes) @@ -319,11 +340,21 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) { assessment.PrepareForArchetype(resolver, archetype, m) newAssessment = true } - result = h.DB(ctx).Create(m) + result = h.DB(ctx).Omit(clause.Associations).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups) + if err != nil { + _ = ctx.Error(err) + return + } if newAssessment { metrics.AssessmentsInitiated.Inc() } diff --git a/api/group.go b/api/group.go index 4e92337b3..dee59ff97 100644 --- a/api/group.go +++ b/api/group.go @@ -97,11 +97,21 @@ func (h StakeholderGroupHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.BaseHandler.CurrentUser(ctx) - result := h.DB(ctx).Create(m) + result := h.DB(ctx).Omit(clause.Associations).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + err = h.DB(ctx).Model(m).Association("Stakeholders").Replace(m.Stakeholders) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("MigrationWaves").Replace(m.MigrationWaves) + if err != nil { + _ = ctx.Error(err) + return + } r.With(m) h.Respond(ctx, http.StatusCreated, r) diff --git a/api/identity.go b/api/identity.go index dbaf606dd..8c631c6f7 100644 --- a/api/identity.go +++ b/api/identity.go @@ -34,7 +34,7 @@ func (h IdentityHandler) AddRoutes(e *gin.Engine) { routeGroup.GET(IdentitiesRoot+"/", h.setDecrypted, h.List) routeGroup.POST(IdentitiesRoot, h.Create) routeGroup.GET(IdentityRoot, h.setDecrypted, h.Get) - routeGroup.PUT(IdentityRoot, h.Update, Transaction) + routeGroup.PUT(IdentityRoot, Transaction, h.Update) routeGroup.DELETE(IdentityRoot, h.Delete) } diff --git a/api/migrationwave.go b/api/migrationwave.go index 8651a369e..128bb485f 100644 --- a/api/migrationwave.go +++ b/api/migrationwave.go @@ -98,11 +98,26 @@ func (h MigrationWaveHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.CurrentUser(ctx) - result := h.DB(ctx).Create(m) + result := h.DB(ctx).Omit(clause.Associations).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + err = h.DB(ctx).Model(m).Association("Applications").Replace("Applications", m.Applications) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups) + if err != nil { + _ = ctx.Error(err) + return + } r.With(m) h.Respond(ctx, http.StatusCreated, r) diff --git a/api/stakeholder.go b/api/stakeholder.go index 4cb659310..1a551cf4d 100644 --- a/api/stakeholder.go +++ b/api/stakeholder.go @@ -97,11 +97,31 @@ func (h StakeholderHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.BaseHandler.CurrentUser(ctx) - result := h.DB(ctx).Create(m) + result := h.DB(ctx).Omit(clause.Associations).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + err = h.DB(ctx).Model(m).Association("Groups").Replace(m.Groups) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("Owns").Replace(m.Owns) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("Contributes").Replace(m.Contributes) + if err != nil { + _ = ctx.Error(err) + return + } + err = h.DB(ctx).Model(m).Association("MigrationWaves").Replace(m.MigrationWaves) + if err != nil { + _ = ctx.Error(err) + return + } r.With(m) h.Respond(ctx, http.StatusCreated, r) From f30698af848fd2854374139763c69bce3f851e4a Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Mon, 5 Aug 2024 08:08:57 -0500 Subject: [PATCH 10/12] :bug: preempted-postpone even when preemption disabled. (#738) When a task is preempted, it needs to be postponed for a short duration to prevent thrashing. Since individual tasks may override the _global_ preempt policy, the postpone must happen regardless. Signed-off-by: Jeff Ortel --- task/rule.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/task/rule.go b/task/rule.go index a42568db1..f87545d53 100644 --- a/task/rule.go +++ b/task/rule.go @@ -77,9 +77,6 @@ type RulePreempted struct { // Postpone based on a duration after the last preempted event. func (r *RulePreempted) Match(ready, _ *Task) (matched bool, reason string) { preemption := Settings.Hub.Task.Preemption - if !preemption.Enabled { - return - } mark := time.Now() event, found := ready.LastEvent(Preempted) if found { From 92bde321d965f2335d7e56cccfe164b4d76952e0 Mon Sep 17 00:00:00 2001 From: David Zager Date: Mon, 5 Aug 2024 09:52:56 -0400 Subject: [PATCH 11/12] :seedling: oil the pr ci workflow (#709) Needs konveyor/ci#54 Signed-off-by: David Zager --- .github/workflows/main.yml | 67 ++++++++------------ .github/workflows/march-image-build-push.yml | 18 ++---- 2 files changed, 33 insertions(+), 52 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9f7f5b43c..9e99967c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,88 +12,75 @@ jobs: fmt: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v3 with: go-version: '1.19' - run: make fmt + vet: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v3 with: go-version: '1.19' - run: make vet + build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v3 with: go-version: '1.19' - run: make cmd - build-image: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: make podman-build test-unit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v3 with: go-version: '1.19' - run: make test test-api: + needs: + - fmt + - vet + - build + - test-unit runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v3 with: go-version: '1.19' - run: | - make vet DISCONNECTED=1 make run & sleep 15 # probably a dirty solution DISCONNECTED=1 HUB_BASE_URL=http://localhost:8080 make test-api DISCONNECTED=1 HUB_BASE_URL=http://localhost:8080 make test-api # Intentionaly run 2x to catch data left in Hub DB. - test-e2e: + build-image: + needs: + - fmt + - vet + - build + - test-unit + - test-api runs-on: ubuntu-latest + env: + IMG: ttl.sh/konveyor-hub-${{ github.sha }}:2h steps: - - uses: actions/checkout@v3 - - name: start-minikube - uses: konveyor/tackle2-operator/.github/actions/start-minikube@main - - name: Build image in minikube - run: | - export SHELL=/bin/bash - eval $(minikube -p minikube docker-env) - make docker-build - - name: install-tackle - uses: konveyor/tackle2-operator/.github/actions/install-tackle@main - with: - tackle-hub-image: tackle2-hub:latest - tackle-image-pull-policy: IfNotPresent - - - name: save image - run: | - IMG=quay.io/konveyor/tackle2-hub:latest make docker-build - docker save -o /tmp/tackle2-hub.tar quay.io/konveyor/tackle2-hub:latest - - - name: Upload image as artifact - uses: actions/upload-artifact@v3 - with: - name: tackle2-hub - path: /tmp/tackle2-hub.tar - retention-days: 1 + - uses: actions/checkout@v4 + - run: make docker-build + - run: docker push ${IMG} test-integration: - needs: test-e2e - uses: konveyor/ci/.github/workflows/global-ci.yml@main + needs: build-image + uses: konveyor/ci/.github/workflows/global-ci-bundle.yml@main with: - component_name: tackle2-hub + tackle_hub: ttl.sh/konveyor-hub-${{ github.sha }}:2h api_hub_tests_ref: ${{ github.ref }} diff --git a/.github/workflows/march-image-build-push.yml b/.github/workflows/march-image-build-push.yml index 8729d4cda..25bbcf065 100644 --- a/.github/workflows/march-image-build-push.yml +++ b/.github/workflows/march-image-build-push.yml @@ -19,15 +19,9 @@ jobs: runs-on: ubuntu-20.04 strategy: fail-fast: false - steps: - - name: Checkout Push to Registry action - uses: konveyor/release-tools/build-push-quay@main - with: - architectures: "amd64, arm64" - containerfile: "./Dockerfile" - image_name: "tackle2-hub" - image_namespace: "konveyor" - image_registry: "quay.io" - quay_publish_robot: ${{ secrets.QUAY_PUBLISH_ROBOT }} - quay_publish_token: ${{ secrets.QUAY_PUBLISH_TOKEN }} - ref: ${{ github.ref }} + uses: konveyor/release-tools/build-push-images.yaml@main + with: + registry: "quay.io/konveyor" + image_name: "tackle2-hub" + containerfile: "./Dockerfile" + architectures: '[ "amd64", "arm64" ]' From 74c54196d999d000156a7a59cafeabd8d298c3ee Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Mon, 12 Aug 2024 11:55:18 -0500 Subject: [PATCH 12/12] :bug: Add task.patch. (#741) Add missing scope. https://issues.redhat.com/browse/MTA-3195 Signed-off-by: Jeff Ortel --- auth/roles.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/auth/roles.yaml b/auth/roles.yaml index a46df37a2..aa65e7a77 100644 --- a/auth/roles.yaml +++ b/auth/roles.yaml @@ -130,6 +130,7 @@ - get - post - put + - patch - name: tasks.bucket verbs: - delete @@ -327,6 +328,7 @@ - get - post - put + - patch - name: tasks.bucket verbs: - delete @@ -468,6 +470,7 @@ - get - post - put + - patch - name: tasks.bucket verbs: - delete