File kubectl-sniff.spec of Package kubectl-sniff

#
# spec file for package kubectl-sniff
#
# Copyright (c) 2023 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/
#


%define __arch_install_post export NO_BRP_STRIP_DEBUG=true

%define tcpdump_version 4.9.2

Name:           kubectl-sniff
Version:        1.6.2
Release:        0
Summary:        Kubectl plugin for Sniffing on pods using tcpdump and wireshark
License:        Apache-2.0
URL:            https://github.com/eldadru/ksniff
Source:         ksniff-%{version}.tar.gz
Source1:        vendor.tar.gz
#Source2:        tcpdump-%{tcpdump_version}.tar.gz
Source2:        https://www.tcpdump.org/release/tcpdump-%{tcpdump_version}.tar.gz
Source3:        https://www.tcpdump.org/release/tcpdump-%{tcpdump_version}.tar.gz.sig
Source4:        https://www.tcpdump.org/tcpdump-workers.asc#/tcpdump.keyring
BuildRequires:  go >= 1.19

# BuildRequires for static-tpcdump
BuildRequires:  gcc13
BuildRequires:  binutils
BuildRequires:  autoconf
BuildRequires:  make
BuildRequires:  glibc-devel-static
BuildRequires:  libpcap
BuildRequires:  libpcap-devel-static

#
Requires:       wireshark

#
Provides:       ksniff = %{version}

%description
A kubectl plugin that utilize tcpdump and Wireshark to start a remote capture on any pod in your Kubernetes cluster.
You get the full power of Wireshark with minimal impact on your running pods.

When working with micro-services, many times it's very helpful to get a capture of the network activity between your micro-service and it's dependencies.
ksniff use kubectl to upload a statically compiled tcpdump binary to your pod and redirecting it's output to your local Wireshark for smooth network debugging experience.

%prep
%autosetup -p1 -a 1 -n ksniff-%{version}
tar xvzf %{SOURCE2}

%build
go build \
   -mod=vendor \
   -buildmode=pie \
   -ldflags="-X main.Version=%{version}" \
   -o kubectl-sniff cmd/kubectl-sniff.go

# build statically-linked tcpdump
cd tcpdump-%{tcpdump_version}

### expand macro configure
CONFIG_SHELL="${CONFIG_SHELL:-/usr/bin/bash}" ; export CONFIG_SHELL ; 
CFLAGS="${CFLAGS:--O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables}" ; export CFLAGS ; 
CXXFLAGS="${CXXFLAGS:--O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables}" ; export CXXFLAGS ; 
FFLAGS="${FFLAGS:--O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables }" ; export FFLAGS ; 
FCFLAGS="${FCFLAGS:--O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables }" ; export FCFLAGS ; 
LDFLAGS="${LDFLAGS:-}" ; export LDFLAGS; 

CFLAGS="%{optflags} -DGUESS_TSO -static"
export CFLAGS

./configure --without-crypto
%make_build


%install
# Install the binary.
install -D -m 0755 %{name} "%{buildroot}/%{_bindir}/%{name}"
ln -s %{name} "%{buildroot}/%{_bindir}/ksniff"

%files
%doc README.md
%license LICENSE
%{_bindir}/%{name}
%{_bindir}/ksniff

%changelog
openSUSE Build Service is sponsored by