File kubernetes.spec of Package kubernetes.4864

#
# spec file for package kubernetes
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#


%{!?tmpfiles_create:%global tmpfiles_create systemd-tmpfiles --create}
Name:           kubernetes
Version:        1.3.10
Release:        0
Summary:        Production-Grade Container Scheduling and Management
License:        Apache-2.0
Group:          System/Management
Url:            http://kubernetes.io
Source:         %{name}-%{version}.tar.xz
Source2:        genmanpages.sh
#systemd services
Source10:       kube-apiserver.service
Source11:       kube-controller-manager.service
Source12:       kubelet.service
Source13:       kube-proxy.service
Source14:       kube-scheduler.service
#config files
Source20:       apiserver
Source21:       config
Source22:       controller-manager
Source23:       kubelet
Source24:       proxy
Source25:       scheduler
Source26:       kubernetes.tmp.conf
# Patches so it also builds in ppc64le and arm64.
Patch1:         0002-Change-DUP2-to-DUP3-in-contrib-mesos-to-build-on-arm.patch
Patch2:         gcc-on-ppc64-and-arm.patch
Patch3:         add_pr_template.patch 
BuildRequires:  bash-completion
BuildRequires:  go-go-md2man
BuildRequires:  golang-packaging
BuildRequires:  rsync
BuildRequires:  systemd-rpm-macros
%{go_nostrip}
%{go_provides}

%description
Manage a cluster of Linux containers as a single system to accelerate Dev and simplify Ops.

%package common
Summary:        Kubernetes common files

%description common
Manage a cluster of Linux containers as a single system to accelerate Dev and simplify Ops.
Kubernetes common files

%package master
Summary:        Kubernetes services for master host
Requires:       kubernetes-common = %{version}-%{release}
%if 0%{?suse_version}
Recommends:     kubernetes-client = %{version}-%{release}
%endif
Requires(pre):  shadow
Requires(pre):  openssl
# if the master is installed with node, version and release must be the same
Conflicts:      kubernetes-node < %{version}-%{release}
Conflicts:      kubernetes-node > %{version}-%{release}
%{?systemd_requires}

%description master
Manage a cluster of Linux containers as a single system to accelerate Dev and simplify Ops.
Kubernetes services for master host

%package node
Summary:        Kubernetes services for node host
Requires:       kubernetes-common = %{version}-%{release}
Requires:       docker
Requires:       ethtool
Requires:       socat
Requires:       iptables
Requires(pre):  shadow
# if master is installed with node, version and release must be the same
Conflicts:      kubernetes-master < %{version}-%{release}
Conflicts:      kubernetes-master > %{version}-%{release}
%{?systemd_requires}

%description node
Manage a cluster of Linux containers as a single system to accelerate Dev and simplify Ops.
Kubernetes services for node host

%package client
Summary:        Kubernetes client tools
Requires:       bash-completion

%description client
Kubernetes client tools like kubectl

%package extra
Summary:        Kubernetes extra resources
Requires:       go

%description extra
Manage a cluster of Linux containers as a single system to accelerate Dev and simplify Ops.
Kubernetes extra resources: cluster providers, demos, testsuite...

%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1

%build
%{goprep} github.com/kubernetes/kubernetes
export KUBE_GIT_VERSION=v%{version}
./hack/build-go.sh --use_go_build

# The majority of the documentation has already been moved into
# http://kubernetes.io/docs/admin, and most of the files stored in the `docs`
# directory simply point there. That being said, some of the files are actual
# man pages, but they have to be generated with `hack/generate-docs.sh`. So,
# let's do that and run `genmanpages.sh`.
./hack/generate-docs.sh
pushd docs
pushd admin
cp kube-apiserver.md kube-controller-manager.md kube-proxy.md kube-scheduler.md kubelet.md ..
popd
cp %{SOURCE2} genmanpages.sh
bash genmanpages.sh
popd

cd hack && go build e2e.go

%install

%ifarch x86_64
host_arch=amd64
output_path="_output/local/bin/linux/amd64"
%else
    %ifarch %arm
    host_arch=arm
    %else
        %ifarch %ix86
        host_arch=386
        %else
            %ifarch s390x
            host_arch=s390x
            %else
                %ifarch ppc64
                host_arch=ppc64le
                %endif
            %endif
        %endif
    %endif
    output_path="_output/local/go/bin"
%endif

platform_path="platforms/linux/${host_arch}"

binaries=(kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet kubectl)
install -m 755 -d %{buildroot}%{_bindir}
for bin in "${binaries[@]}"; do
  echo "+++ INSTALLING ${bin}"
  install -p -m 755 -t %{buildroot}%{_bindir} ${output_path}/${bin}
done

# install extra things
kubernetes_src=%{buildroot}%{_usrsrc}/kubernetes

install -m 755 -d ${kubernetes_src}
cp -R cluster  ${kubernetes_src}/
cp -R examples ${kubernetes_src}/
cp -R hack     ${kubernetes_src}/
cp -R test     ${kubernetes_src}/

platforms_dir=${kubernetes_src}/platforms/linux/${host_arch}
extra_binaries=(ginkgo e2e_node.test e2e.test integration)
install -m 755 -d $platforms_dir
for bin in "${extra_binaries[@]}"; do
  echo "+++ INSTALLING ${bin}"
  install -p -m 755 -t ${platforms_dir} ${output_path}/${bin}
done

#
# systemd service
#
install -d -m 0755 %{buildroot}%{_unitdir}
install -m 0644 -t %{buildroot}%{_unitdir}/ %{SOURCE10}
install -m 0644 -t %{buildroot}%{_unitdir}/ %{SOURCE11}
install -m 0644 -t %{buildroot}%{_unitdir}/ %{SOURCE12}
install -m 0644 -t %{buildroot}%{_unitdir}/ %{SOURCE13}
install -m 0644 -t %{buildroot}%{_unitdir}/ %{SOURCE14}

# make symlinks to rc files
mkdir -p %{buildroot}%{_sbindir}
for rc in kube-proxy kubelet kube-apiserver kube-controller-manager kube-scheduler
do
  ln -sf service %{buildroot}%{_sbindir}/rc$rc
done

# install manpages
install -d %{buildroot}%{_mandir}/man1
install -p -m 644 docs/man/man1/* %{buildroot}%{_mandir}/man1

# install config files
install -d -m 0755 %{buildroot}%{_sysconfdir}/%{name}
install -m 0644 -t %{buildroot}%{_sysconfdir}/%{name} %{SOURCE20}
install -m 0644 -t %{buildroot}%{_sysconfdir}/%{name} %{SOURCE21}
install -m 0644 -t %{buildroot}%{_sysconfdir}/%{name} %{SOURCE22}
install -m 0644 -t %{buildroot}%{_sysconfdir}/%{name} %{SOURCE23}
install -m 0644 -t %{buildroot}%{_sysconfdir}/%{name} %{SOURCE24}
install -m 0644 -t %{buildroot}%{_sysconfdir}/%{name} %{SOURCE25}

# place kubernetes.tmp.conf to /usr/lib/tmpfiles.d/kubernetes.conf
install -d -m 0755 %{buildroot}%{_tmpfilesdir}
install -D -m 0644 %{SOURCE26} %{buildroot}/%{_tmpfilesdir}/kubernetes.conf

# install the place the kubelet defaults to put volumes
install -d %{buildroot}%{_localstatedir}/lib/kubelet

%fdupes -s %{buildroot}


%pre master
getent group kube >/dev/null || groupadd -r kube
getent passwd kube >/dev/null || useradd -r -g kube -d / -s /sbin/nologin \
        -c "Kubernetes user" kube
%service_add_pre kube-apiserver.service kube-scheduler.service kube-controller-manager.service

mkdir -p -m 755 /var/lib/kubernetes
chown -R kube /var/lib/kubernetes
chgrp -R kube /var/lib/kubernetes

# Generate ServiceAccount key if needed
service_account_key="/var/lib/kubernetes/serviceaccount.key"
if [ ! -f "${service_account_key}" ] ; then
  mkdir -p "$(dirname ${service_account_key})"
  openssl genrsa -out "${service_account_key}" 2048 2>/dev/null
  chmod 600 "${service_account_key}"
  chown kube:kube "${service_account_key}"
fi

%post master
%service_add_post kube-apiserver.service kube-scheduler.service kube-controller-manager.service
%tmpfiles_create %{_tmpfilesdir}/kubernetes.conf

%preun master
%service_del_preun kube-apiserver.service kube-scheduler.service kube-controller-manager.service

%postun master
%service_del_postun kube-apiserver.service kube-scheduler.service kube-controller-manager.service

%pre node
getent group kube >/dev/null || groupadd -r kube
getent passwd kube >/dev/null || useradd -r -g kube -d / -s /sbin/nologin \
        -c "Kubernetes user" kube
%service_add_pre kubelet.service kube-proxy.service

%post node
%service_add_post kubelet.service kube-proxy.service
%tmpfiles_create %{_tmpfilesdir}/kubernetes.conf

%preun node
%service_del_preun kubelet.service kube-proxy.service

%postun node
%service_del_postun kubelet.service kube-proxy.service

%files common
%defattr(-,root,root)
%config(noreplace) %{_sysconfdir}/%{name}/config

%files master
%defattr(-,root,root)
%doc README.md LICENSE CONTRIB.md CONTRIBUTING.md DESIGN.md
%{_mandir}/man1/kube-apiserver.1*
%{_mandir}/man1/kube-controller-manager.1*
%{_mandir}/man1/kube-scheduler.1*
%{_bindir}/kube-apiserver
%{_bindir}/kube-controller-manager
%{_bindir}/kube-scheduler
%{_unitdir}/kube-apiserver.service
%{_unitdir}/kube-controller-manager.service
%{_unitdir}/kube-scheduler.service
%{_sbindir}/rckube-apiserver
%{_sbindir}/rckube-controller-manager
%{_sbindir}/rckube-scheduler
%attr(0750,root,root) %dir %ghost %{_rundir}/%{name}

%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/apiserver
%config(noreplace) %{_sysconfdir}/%{name}/scheduler
%config(noreplace) %{_sysconfdir}/%{name}/controller-manager
%{_tmpfilesdir}/kubernetes.conf

%files node
%defattr(-,root,root)
%doc README.md LICENSE CONTRIB.md CONTRIBUTING.md DESIGN.md CHANGELOG.md
%{_mandir}/man1/kubelet.1*
%{_mandir}/man1/kube-proxy.1*
%{_bindir}/kubelet
%{_bindir}/kube-proxy
%{_unitdir}/kube-proxy.service
%{_unitdir}/kubelet.service
%{_sbindir}/rckube-proxy
%{_sbindir}/rckubelet
%dir %{_localstatedir}/lib/kubelet
%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/kubelet
%config(noreplace) %{_sysconfdir}/%{name}/proxy
%{_tmpfilesdir}/%{name}.conf
%attr(0750,root,root) %dir %ghost %{_rundir}/%{name}

%files client
%defattr(-,root,root)
%doc README.md LICENSE CONTRIB.md CONTRIBUTING.md DESIGN.md
%{_mandir}/man1/kubectl.1*
%{_mandir}/man1/kubectl-*
%{_bindir}/kubectl

%files extra
%defattr(-,root,root)
%dir %{_usrsrc}/kubernetes
%dir %{_usrsrc}/kubernetes/cluster
%dir %{_usrsrc}/kubernetes/examples
%dir %{_usrsrc}/kubernetes/hack
%dir %{_usrsrc}/kubernetes/test
%dir %{_usrsrc}/kubernetes/platforms
%{_usrsrc}/kubernetes/cluster/*
%{_usrsrc}/kubernetes/examples/*
%{_usrsrc}/kubernetes/test/*
%{_usrsrc}/kubernetes/hack/*
%{_usrsrc}/kubernetes/platforms/*

%changelog