# Disable debug information package creation
%define debug_package %{nil}

# Define the Go Import Path
%global goipath github.com/flightctl/flightctl

Name:           flightctl
Version:        0.3.0
Release:        1.20250116093409338177.pr789.308.g811255d%{?dist}
Summary:        Flightctl is a manager of the edge device fleets.

%gometa

License:        Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND MIT
URL:            %{gourl}

Source0:        flightctl-0.3.0.tar.gz

BuildRequires:  golang
BuildRequires:  make
BuildRequires:  git
BuildRequires:  openssl-devel

Requires: openssl

# Skip description for the main package since it won't be created
%description
# Main package is empty and not created.

# cli sub-package
%package cli
Summary: Flightctl CLI
%description cli
Flightctl is a command line interface for managing edge device fleets.

# agent sub-package
%package agent
Summary: Flightctl Agent

Requires: bootc

%description agent
Flightctl Agent is a component of the flightctl tool.

%prep
%goprep -A
%setup -q %{forgesetupargs} -n flightctl-0.3.0

%build
    # if this is a buggy version of go we need to set GOPROXY as workaround
    # see https://github.com/golang/go/issues/61928
    GOENVFILE=$(go env GOROOT)/go.env
    if [[ ! -f "${GOENVFILE}" ]]; then
        export GOPROXY='https://proxy.golang.org,direct'
    fi
    SOURCE_GIT_TAG=%{release} SOURCE_GIT_TREE_STATE=clean SOURCE_GIT_COMMIT=%{release} SOURCE_GIT_TAG_NO_V=%{version} make build-cli build-agent

%install
    mkdir -p %{buildroot}/usr/bin
    cp bin/flightctl %{buildroot}/usr/bin
    mkdir -p %{buildroot}/usr/lib/systemd/system
    mkdir -p %{buildroot}/%{_sharedstatedir}/flightctl
    mkdir -p %{buildroot}/usr/lib/flightctl/hooks.d/{afterupdating,beforeupdating,afterrebooting,beforerebooting}
    mkdir -p %{buildroot}/usr/lib/greenboot/check/required.d
    install -m 0755 packaging/greenboot/flightctl-agent-running-check.sh %{buildroot}/usr/lib/greenboot/check/required.d/20_check_flightctl_agent.sh
    cp bin/flightctl-agent %{buildroot}/usr/bin
    cp packaging/must-gather/flightctl-must-gather %{buildroot}/usr/bin
    cp packaging/hooks.d/afterupdating/00-default.yaml %{buildroot}/usr/lib/flightctl/hooks.d/afterupdating
    cp packaging/systemd/flightctl-agent.service %{buildroot}/usr/lib/systemd/system
    bin/flightctl completion bash > flightctl-completion.bash
    install -Dpm 0644 flightctl-completion.bash -t %{buildroot}/%{_datadir}/bash-completion/completions
    bin/flightctl completion fish > flightctl-completion.fish
    install -Dpm 0644 flightctl-completion.fish -t %{buildroot}/%{_datadir}/fish/vendor_completions.d/
    bin/flightctl completion zsh > _flightctl-completion
    install -Dpm 0644 _flightctl-completion -t %{buildroot}/%{_datadir}/zsh/site-functions/

    rm -f licenses.list

    find -type f -name LICENSE -or -name License | while read LICENSE_FILE; do
        echo "%{_datadir}/licenses/%{NAME}/${LICENSE_FILE}" >> licenses.list
    done
    mkdir -vp "%{buildroot}%{_datadir}/licenses/%{NAME}"
    cp LICENSE "%{buildroot}%{_datadir}/licenses/%{NAME}"

    mkdir -vp "%{buildroot}%{_docdir}/%{NAME}"

    for DOC in docs examples .markdownlint-cli2.yaml README.md; do
        cp -vr "${DOC}" "%{buildroot}%{_docdir}/%{NAME}/${DOC}"
    done

%check
    %{buildroot}%{_bindir}/flightctl-agent version

# File listings
# No %files section for the main package, so it won't be built

%files cli -f licenses.list
    %{_bindir}/flightctl
    %license LICENSE
    %{_datadir}/bash-completion/completions/flightctl-completion.bash
    %{_datadir}/fish/vendor_completions.d/flightctl-completion.fish
    %{_datadir}/zsh/site-functions/_flightctl-completion

%files agent -f licenses.list
    %license LICENSE
    %{_bindir}/flightctl-agent
    %{_bindir}/flightctl-must-gather
    /usr/lib/flightctl/hooks.d/afterupdating/00-default.yaml
    /usr/lib/systemd/system/flightctl-agent.service
    %{_sharedstatedir}/flightctl
    /usr/lib/greenboot/check/required.d/20_check_flightctl_agent.sh
    %{_docdir}/%{NAME}/*
    %{_docdir}/%{NAME}/.markdownlint-cli2.yaml


%changelog
* Thu Jan 16 2025 Packit <hello@packit.dev> - 0.3.0-1.20250116093409338177.pr789.308.g811255d
- EDM-885: make build-cli-multiarch target (Gregory Shilin)
- EDM-714: Remove rabbit refs in deploy scripts (Dakota Crowder)
- EDM-714: Fix file removal (Dakota Crowder)
- Revert "EDM-714: Rename rabbitmq to mq to be more inline with db and kv, fix file removal" (Dakota Crowder)
- EDM-714: Rename rabbitmq to mq to be more inline with db and kv, fix file removal (Dakota Crowder)
- EDM-714: Specify periodic and worker as systemd deps of the api container (Dakota Crowder)
- EDM-714: Better handling around setting PRIMARY_IP from our friend coderabbit (Dakota Crowder)
- EDM-714: Remove -it from not interactive exec cmds (Dakota Crowder)
- EDM-714: Fix standalone mq commands (Dakota Crowder)
- EDM-714: Add shared file for deploying individual services, share some config, cleanup the existing scripts (Dakota Crowder)
- EDM-714: Move deploy quadlets logic to a script file (Dakota Crowder)
- EDM-714: Move clean quadlets logic to a script file w/ some better logging (Dakota Crowder)
- EDM-714: Use more specific matching when copying files to /etc/containers/systemd/ (Dakota Crowder)
- EDM-714: Use more specific matching for stopping standalone services (Dakota Crowder)
- EDM-714: Use absolute paths for volume mount refs (Dakota Crowder)
- EDM-714: Add back creation of admin db to dpeloy-db make command (Dakota Crowder)
- EDM-714: Remove podman-compose code, move quadlets code into the deploy/podman directory (Dakota Crowder)
- EDM-714: Change deploy and kill kv commands to use quadlets (Dakota Crowder)
- EDM-714: Change deploy and kill mq commands to use quadlets (Dakota Crowder)
- EDM-714: Remove standalone network (Dakota Crowder)
- EDM-714: Use separate standalone config to spin up db rather than templating (Dakota Crowder)
- EDM-714: Spin up standalone postgres db (Dakota Crowder)
- EDM-714: Remove redis volume when we clean quadlets deployment (Dakota Crowder)
- EDM-714: Create separate file for the redis.conf volume instead of using ExecStartPre (Dakota Crowder)
- EDM-714: Wait for postgres db and add superuser permission when starting up quadlets (Dakota Crowder)
- EDM-846: Deploy default fctl roles in ACM env (#708) (Rastislav Wagner)
- EDM-1018: Add helm values for ACM deployment (#791) (Avishay Traeger)
- EDM-1036: Dispatch tasks via Redis (Avishay Traeger)
- EDM-773: Update charts to support deployment via ACM operator (#780) (Miguel Angel Ajo Pelayo)
- EDM-885: move CLI build to a separate PR (Gregory Shilin)
- EDM-885: RPM versioning (Gregory Shilin)
- EDM-967: Add identity information for K8S (#785) (Ori Amizur)
- EDM-768: Run linter on OpenAPI specs (Frank A. Zdarsky)
- EDM-768: Only set pdeathsig on Linux (Frank A. Zdarsky)
- EDM-768: Simplify enrollment config (Frank A. Zdarsky)
- EDM-768: Align CSR API with K8s (Frank A. Zdarsky)
- EDM-1021: applications: add controller sync test (Sam Batschelet)
- EDM-1021: applications: ensure id is deterministic (Sam Batschelet)
- EDM-1015: Add note in docs about go template syntax (Avishay Traeger)
- EDM-989: Flightctl should fail with explicit message if login was not done (rawagner)
- EDM-992: Validate URL for login cmd (#777) (Rastislav Wagner)
- EDM-983: Testing for Filtering (Eldar101)
- EDM-710: Validate Repository Spec Selectors Using GenericRepoSpec (#769) (Assaf Albo)
- EDM-1017: Replace variables in git config mountPath (Avishay Traeger)
- EDM-390: Update device lifecycle status based on Condition (Lily Sturmann)
- EDM-391: add lifecycle manager (Sam Batschelet)
- NO-ISSUE: Add shortcut 'k' for 'insecure-skip-tls-verify' flag (#778) (Rastislav Wagner)
- EDM-869: TC75506 Resources lifecycle (#687) (amalykhi)
- NO-ISSUE: Small fix in template variables doc (sserafin)
- EDM-821: Support pure k8s authN (rawagner)
- Revert "EDM-773: Update charts to support deployment via ACM operator" (#772) (Rastislav Wagner)
- EDM-969: applications: ensure unique ID (Sam Batschelet)
- EDM-969: applications: add internal support for tracking by ID (Sam Batschelet)
- EDM-390: Add decommission spec to rendered device config (Lily Sturmann)
- EDM-943: Add document describing k8s RBAC authorization (Ori Amizur)
- EDM-390: Set decommission request in device spec (Lily Sturmann)
- EDM-390: Add decommission request to device spec (Lily Sturmann)
- EDM-1008: Add permissions check for device console (#763) (Rastislav Wagner)
- EDM-1005: Fix selector behavior for NULL columns in the database (#762) (Assaf Albo)
- EDM-1011: CLI to request device count when listing fleets (Avishay Traeger)
- EDM-1010: Fix template variable for inline config path (Avishay Traeger)
- EDM-526: policy: ensure DST is properly covered (Sam Batschelet)
- EDM-970: Fix K8S_RBAC_NS value for ACM deployment (#759) (Rastislav Wagner)
- EDM-773: Update charts to support deployment via ACM operator (#760) (Rastislav Wagner)
- EDM-526: policy: improve logging (Sam Batschelet)
- EDM-526: device: ensure policy has an escape hatch (Sam Batschelet)
- EDM-526: policy: add schedule tests and improve logic (Sam Batschelet)
- EDM-526: api: install tzdata for time zone validation (Sam Batschelet)
- EDM-526: spec/queue: refactor (Sam Batschelet)
- EDM-526: device: update status to align with policy checks and docs (Sam Batschelet)
- EDM-526: spec/queue: improve docs (Sam Batschelet)
- EDM-526: plumb update policy (Sam Batschelet)
- EDM-526: agent: add update policy (Sam Batschelet)
- Integrate Labels and Annotations Filtering into Selector Framework (#751) (Assaf Albo)
- EDM-768: Align createOrUpdate (Frank A. Zdarsky)
- EDM-768: Fix properties next to ref linting issue (Frank A. Zdarsky)
- EDM-768: Fix PascalCase linting issue (Frank A. Zdarsky)
- EDM-768: Fix linting issues (Frank A. Zdarsky)
- EDM-822: Container port (Eldar101)
- EDM-781: Field selectors tests (Eldar Weiss)
- EDM-390: Set enrolled devices to 'Enrolled' lifecycle status (Lily Sturmann)
- EDM-954: Use approved RabbitMQ (Avishay Traeger)
- EDM-819: Remove any unnecessary helm for the gRPC endpoint (Miguel Angel Ajo)
- EDM-818: gRPC and agent HTTPS under the same endpoint (Miguel Angel Ajo)
- EDM-955: Use approved Redis (Avishay Traeger)
- NO-ISSUE: Collect logs in smoke/e2e github workflows (Avishay Traeger)
- EDM-922: Fine-tune HTTP server settings (Avishay Traeger)
- EDM-953: Use approved Postgres (Avishay Traeger)
- NO-ISSUE: omit grpc from make generate (Sam Batschelet)
- EDM-649: Update CSR error codes to be more expressive and accurate (Lily Sturmann)
- NO-ISSUE: reduce scope of bootc API (Sam Batschelet)
- Revert "NO-ISSUE: helm: unblock CI pin rabbitmq" (Sam Batschelet)
- EDM-390: Add decommission CLI command (Lily Sturmann)
- EDM-390: Small fix for decommission target type (Lily Sturmann)
- NO-ISSUE: troubleshooting: add basic agent debug (Sam Batschelet)
- EDM-948: Allow specifying Namespace for k8s RBAC checks (#736) (Rastislav Wagner)
- EDM-870: flightctl console cli on web socket (#731) (Miguel Angel Ajo Pelayo)
- MGMT-18492: Add logical support for reboot hooks (Sam Batschelet)
- EDM-390: Add lifecyclestatus to devicestatus (Lily Sturmann)
- NO-ISSUE: libvirt-dev should always be installed (Miguel Angel Ajo)
- NO-ISSUE: Implement Go tools pattern (Frank A. Zdarsky)
- NO-ISSUE: Update GH runner (Frank A. Zdarsky)
- EDM-390: Add decommissioning field to rendered device spec (Lily Sturmann)
- NO-ISSUE: packaging: add flightctl agent version to must-gather (Sam Batschelet)
- NO-ISSUE: metrics: register flightctl_api_errors_client_total (Sam Batschelet)
- EDM-391: Add 'decommissioning' Condition and Reasons for device (Lily Sturmann)
- NO-ISSUE: Use a password for accessing Valkey (Avishay Traeger)
- NO-ISSUE: Move key-value code out of tasks package (Avishay Traeger)
- EDM-854: Use go-templates for fleet template parameters (Avishay Traeger)
- NO-ISSUE: helm: unblock CI pin rabbitmq (Sam Batschelet)
- EDM-879: improve service generated app status (Sam Batschelet)
- EDM-886: correctly fmt service side app status (Sam Batschelet)
- EDM-526: ensure errors reported by os.exec are properly handeled (Sam Batschelet)
- EDM-870: ws console wiring (Miguel Angel Ajo)
- EDM-870: Move console request/connection to websocket (Miguel Angel Ajo)
- EDN-860: Add permission checks for all API endpoints (Ori Amizur)
- NO-ISSUE: Fix OpenAPI descriptions (Frank A. Zdarsky)
- EDM-848: revert tzdata host mount (#690) (Sam Batschelet)
- EDM-876: Fix helm template error (Celia Amador)
- EDM-788: Add init script for PostgreSQL to set master user as superuser (#679) (Assaf Albo)
- EDM-838: Update ACM registration doc (Frank A. Zdarsky)
- NO-ISSUE: redeploy kind pods for development (Miguel Angel Ajo)
- NO-ISSUE: move ownership od status exporters to managers (Sam Batschelet)
- EDM-853: spec/queue: ensure item requeue backoff only if tried  (#696) (Sam Batschelet)
- EDM-642: Remove sorting mechanism for TP phase (#701) (Assaf Albo)
- MGMT-17672: Document device statuses (Frank A. Zdarsky)
- EDM-417: Get renderedVersion from DB (Frank A. Zdarsky)
- EDM-417: Update unit-tests for server-side status (Frank A. Zdarsky)
- EDM-417: Do not report retries, fail faster (Frank A. Zdarsky)
- EDM-417: Compute service-side status (Frank A. Zdarsky)
- EDM-649: Add specific error message when CSR approval fails (Lily Sturmann)
- EDM-649: Remove extraneous CN len check (Lily Sturmann)
- EDM-842: transient networking error should not mark agent degraded (Sam Batschelet)
- EDM-772: Move UI chart to main repo (#673) (Rastislav Wagner)
- NO-ISSUE: agent: ensure bootstrap status (Sam Batschelet)
- EDM-761: Document lifecycle hooks (Frank A. Zdarsky)
- EDM-764: Update Hooks API implementation (Frank A. Zdarsky)
- EDM-764: Update Hooks API (Frank A. Zdarsky)
- EDM-659: agent/fileio: ensure ignition gid, uid and mode (Sam Batschelet)
- NO-ISSUE: Pass internalOpenShiftApiUrl from values to api-config CM (#680) (Rastislav Wagner)
- EDM-424: add update policy api and validation (Sam Batschelet)
- EDM-420: Increase DB parameters (#669) (Gregory Shilin)
- NO-ISSUE: Append UI port to valid redirect URIs (rawagner)
- EDM-390: Add decommissioning route to device API (Lily Sturmann)
- EDM-417: Centralize API consts (Frank A. Zdarsky)
- NO-ISSUE: add command to prepare e2e test (sserafin)
- EDM-621: Fix microshift registration docs (Avishay Traeger)
- EDM-767: Actually update ignition mount path (Avishay Traeger)
- EDM-708: Reduce git access (Avishay Traeger)
- NO-ISSUE: Remove duplicated code in git helpers (Avishay Traeger)
- MGMT-17672: device: align update status phases (Sam Batschelet)
- Add developer documentation for field-selector (#658) (Assaf Albo)
- EDM-681: Allow field selector when 'summaryOnly' is enabled (#656) (Assaf Albo)
- EDM-704: Automate test 75991 (sserafin)
- EDM-695: typo fix (Gregory Shilin)
- EDM-695: typo fix (Gregory Shilin)
- EDM-695: typo fix (Gregory Shilin)
- EDM-695: typo fix (Gregory Shilin)
- EDM-695: created a document with instructions to run devicesimulator (Gregory Shilin)
- EDM-695: Logger verbosity flag was added (-v) (#651) (Gregory Shilin)
- EDM-423: Fix lexer state for nested exists/notexists selectors (#655) (Assaf Albo)
- EDM-423: Adapt K8s lexer to support RHS equality symbol (asafbss)
- EDM-423: Modify k8s containment operator; remove support for 'in' and 'notin' on JSON fields (asafbss)
- EDM-423: Remove selector casting; implement a whitelist of selectors per resource for stricter filtering (asafbss)
- EDM-423: Move alias back to label in API while keeping it as a field in device model (asafbss)
- EDM-423: Add documentation for Field Selectors (asafbss)
- EDM-666: Updated selector names to match the documented API (asafbss)
- EDM-664: Added selector support for Spec field in field-selector (asafbss)
- EDM-423: Introduce Alias Field for Device Metadata (asafbss)
- EDM-423: Add more Kubernetes operators to enhance selectors for fields (asafbss)
- EDM-423: Kubernetes vanilla label selector (asafbss)
- NO-ISSUE: Fix linter and spellchecker issues (Frank A. Zdarsky)
- NO-ISSUE: Fix path-filter (Frank A. Zdarsky)
- EDM-694: Add Valkey key value store service (Ricardo Noriega)
- EDM-694: Use primary IP and nip.io domains (Ricardo Noriega)
- EDM-694: Add FlightCtl Network to slice (Ricardo Noriega)
- EDM-694: Add Makefile Quadlet targets for deploy and clean (Ricardo Noriega)
- EDM-694: Initial FlightCtl deployment with Quadlets (Ricardo Noriega)
- NO-ISSUE: Update config storage API (Avishay Traeger)
- EDM-578: Remove templateversion populate task (Avishay Traeger)
- EDM-582: Freeze HTTP configurations (Avishay Traeger)
- EDM-583: Freeze k8s secret configurations (Avishay Traeger)
- EDM-581: Freeze git configurations (Avishay Traeger)
- NO-ISSUE: Remove device's TV annotation if removed from fleet (Avishay Traeger)
- EDM-580: Deploy Valkey for frozen configurations (Avishay Traeger)
- EDM-578: Separate fleet validate and device render logic (Avishay Traeger)
- EDM-420: Enable to run devicesimulator on multiple hosts (#650) (Gregory Shilin)
- NO-ISSUE: Improve UpdateDeviceWithRetries to handle all errors (Miguel Angel Ajo)
- EDM-446: device/fileio: ensure readable paths in PathExists (Sam Batschelet)
- EDM-656: agent: clarify completed status (Sam Batschelet)
- EDM-656: agent: ensure Shutdown is threadsafe (Sam Batschelet)
- EDM-656: agent/device improve systemd status reporting (Sam Batschelet)
- NO-ISSUE: console: simplify exec test case (Sam Batschelet)
- EDM-673: Enable exposing APIs via Gateway (rawagner)
- EDM-650: Load k8s ca.crt when deployed on k8s (rawagner)
- EDM-482: node-exporter conatainer failed to start due the Failed to open directory, disabling udev device properties (Ori Amizur)

* Mon Nov 4 2024 Miguel Angel Ajo <majopela@redhat.com> - 0.3.0-1
- Move the Release field to -1 so we avoid auto generating packages
  with -5 all the time.
* Wed Aug 21 2024 Sam Batschelet <sbatsche@redhat.com> - 0.0.1-5
- Add must-gather script to provide a simple mechanism to collect agent debug
* Wed Aug 7 2024 Sam Batschelet <sbatsche@redhat.com> - 0.0.1-4
- Add basic greenboot support for failed flightctl-agent service
* Wed Mar 13 2024 Ricardo Noriega <rnoriega@redhat.com> - 0.0.1-3
- New specfile for both CLI and agent packages