#
# spec file for package node-feature-discovery
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name:           node-feature-discovery
Version:        0
Release:        0
Summary:        Advertises hardware features available on each Kubernetes node using node labels
License:        Apache-2.0
URL:            https://github.com/kubernetes-sigs/node-feature-discovery
Source:         %{name}-%{version}.tar
Source1:        vendor.tar.gz
BuildRequires:  glibc-static
BuildRequires:  golang(API) = 1.25
ExcludeArch:    s390
ExcludeArch:    %{ix86}

%description
Node-Feature-Discovery (NFD) software enables node feature discovery for Kubernetes. It detects hardware features available on each node in a
Kubernetes cluster, and advertises those features using node labels and optionally node extended resources, annotations and node taints.
Node Feature Discovery is compatible with any recent version of Kubernetes (v1.21+).

NFD consists of four software components:
- nfd-master:
    daemon responsible for communication towards the Kubernetes API. That is, it receives labeling requests from the worker and modifies node
    objects accordingly.
- nfd-worker:
    daemon responsible for feature detection. It then communicates the information to nfd-master which does the actual node labeling. One instance
    of nfd-worker is supposed to be running on each node of the cluster.
- nfd-topology-updater:
    daemon responsible for examining allocated resources on a worker node to account for resources available to be allocated to new pod on a per-zone
    basis (where a zone can be a NUMA node). It then creates or updates a NodeResourceTopology custom resource object specific to this node. One instance
    of nfd-topology-updater is supposed to be running on each node of the cluster.
- nfd-gc:
    daemon responsible for cleaning obsolete NodeFeature and NodeResourceTopology objects.
    One instance of nfd-gc is supposed to be running in the cluster.
- nfd:
    client able to export features or labels in a generic context (e.g., compute nodes that warrant assessment, but may not have Kubernetes running,
    or may not be able to or want to run a central daemon service for data).

%prep
%autosetup -a1 -n %{name}-%{version} -p1

%build
%define cgoenabled "1"
# Most of the following go-build settings, toghether the build requirement on glibc-static package (see above) come from the aim
# to get an statically linked binary (once CGO being enabled); they have been taken from upstream Makefile.
#
# Apart from that, the "host-" setting in "pathPrefix" variable in "sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath" package
# (below) is required for alignment with the several mount paths set in the nfd chart's "worker" daemonset (yaml) template, for
# all the hostPath volumes defined there.
%define buildgotags "osusergo,netgo"
%define buildldflags "-linkmode=external -extldflags '-static -Wl,--fatal-warnings' -X sigs.k8s.io/node-feature-discovery/pkg/version.version=v%{version} -X sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath.pathPrefix=/host- -s -w"
CGO_ENABLED=%{cgoenabled} go build -mod=vendor -trimpath -tags %{buildgotags} -ldflags %{buildldflags} -o kubectl-nfd ./cmd/kubectl-nfd
CGO_ENABLED=%{cgoenabled} go build -mod=vendor -trimpath -tags %{buildgotags} -ldflags %{buildldflags} -o nfd-gc      ./cmd/nfd-gc
CGO_ENABLED=%{cgoenabled} go build -mod=vendor -trimpath -tags %{buildgotags} -ldflags %{buildldflags} -o nfd-master  ./cmd/nfd-master
CGO_ENABLED=%{cgoenabled} go build -mod=vendor -trimpath -tags %{buildgotags} -ldflags %{buildldflags} -o nfd-worker  ./cmd/nfd-worker
CGO_ENABLED=%{cgoenabled} go build -mod=vendor -trimpath -tags %{buildgotags} -ldflags %{buildldflags} -o nfd-topology-updater ./cmd/nfd-topology-updater
CGO_ENABLED=%{cgoenabled} go build -mod=vendor -trimpath -tags %{buildgotags} -ldflags %{buildldflags} -o nfd ./cmd/nfd

%install
install -D -m0755 kubectl-nfd %{buildroot}%{_bindir}/kubectl-nfd
install -D -m0755 nfd-gc %{buildroot}%{_bindir}/nfd-gc
install -D -m0755 nfd-master %{buildroot}%{_bindir}/nfd-master
install -D -m0755 nfd-worker %{buildroot}%{_bindir}/nfd-worker
install -D -m0755 nfd-topology-updater %{buildroot}%{_bindir}/nfd-topology-updater
install -D -m0755 nfd %{buildroot}%{_bindir}/nfd
install -D -m0644 ./deployment/components/worker-config/nfd-worker.conf.example %{buildroot}%{_sysconfdir}/kubernetes/node-feature-discovery/nfd-worker.conf

%files
%license LICENSE
%doc README.md
%{_bindir}/kubectl-nfd
%{_bindir}/nfd-gc
%{_bindir}/nfd-master
%{_bindir}/nfd-worker
%{_bindir}/nfd-topology-updater
%{_bindir}/nfd
%dir %{_sysconfdir}/kubernetes
%dir %{_sysconfdir}/kubernetes/node-feature-discovery
%{_sysconfdir}/kubernetes/node-feature-discovery/nfd-worker.conf

%changelog
