From 4d50ce93aa0b20534e8a2e8456e89cfeb58bd422 Mon Sep 17 00:00:00 2001 From: Christian Kampka Date: Wed, 3 Jul 2019 13:00:27 +0200 Subject: [PATCH] kops: restructure package to maintain multiple versions in the future kops versions are bound to the version of the kubernetes cluster they are targeted to maintain (kops 1.12 -> k8s 1.12, kops 1.13 -> k8s 1.13, etc). Upgrading kops should therefore be done very deliberately as it may affect the cluster it is working with in drastic ways. This change introduces the ability to maintain multiple versions of kops in nixpkgs, giving the users the ability to pin it to their target cluster version when installing --- .../networking/cluster/kops/default.nix | 81 +++++++++++-------- pkgs/top-level/all-packages.nix | 6 +- 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/pkgs/applications/networking/cluster/kops/default.nix b/pkgs/applications/networking/cluster/kops/default.nix index 96f3354023c..cd6cd9ee22b 100644 --- a/pkgs/applications/networking/cluster/kops/default.nix +++ b/pkgs/applications/networking/cluster/kops/default.nix @@ -1,44 +1,57 @@ -{ stdenv, buildGoPackage, fetchFromGitHub, go-bindata }: - -buildGoPackage rec { - name = "kops-${version}"; - version = "1.12.1"; +{ stdenv, lib, buildGoPackage, fetchFromGitHub, go-bindata }: +let goPackagePath = "k8s.io/kops"; - src = fetchFromGitHub { - rev = version; - owner = "kubernetes"; - repo = "kops"; - sha256 = "09rmgazdrmnh1lqaayzfbn0ld7mbj9whihs9ijv5gf6si9p0ml9y"; - }; + generic = { version, sha256, ...}@attrs: + let attrs' = builtins.removeAttrs attrs ["version" "sha256"] ; in + buildGoPackage { + name = "kops-${version}"; - buildInputs = [go-bindata]; - subPackages = ["cmd/kops"]; + inherit goPackagePath; - buildFlagsArray = '' - -ldflags= - -X k8s.io/kops.Version=${version} - -X k8s.io/kops.GitVersion=${version} - ''; + src = fetchFromGitHub { + rev = version; + owner = "kubernetes"; + repo = "kops"; + inherit sha256; + }; - preBuild = '' - (cd go/src/k8s.io/kops - go-bindata -o upup/models/bindata.go -pkg models -prefix upup/models/ upup/models/...) - ''; + buildInputs = [go-bindata]; + subPackages = ["cmd/kops"]; - postInstall = '' - mkdir -p $bin/share/bash-completion/completions - mkdir -p $bin/share/zsh/site-functions - $bin/bin/kops completion bash > $bin/share/bash-completion/completions/kops - $bin/bin/kops completion zsh > $bin/share/zsh/site-functions/_kops - ''; + buildFlagsArray = '' + -ldflags= + -X k8s.io/kops.Version=${version} + -X k8s.io/kops.GitVersion=${version} + ''; - meta = with stdenv.lib; { - description = "Easiest way to get a production Kubernetes up and running"; - homepage = https://github.com/kubernetes/kops; - license = licenses.asl20; - maintainers = with maintainers; [offline zimbatm]; - platforms = platforms.unix; + preBuild = '' + (cd go/src/k8s.io/kops + go-bindata -o upup/models/bindata.go -pkg models -prefix upup/models/ upup/models/...) + ''; + + postInstall = '' + mkdir -p $bin/share/bash-completion/completions + mkdir -p $bin/share/zsh/site-functions + $bin/bin/kops completion bash > $bin/share/bash-completion/completions/kops + $bin/bin/kops completion zsh > $bin/share/zsh/site-functions/_kops + ''; + + meta = with stdenv.lib; { + description = "Easiest way to get a production Kubernetes up and running"; + homepage = https://github.com/kubernetes/kops; + license = licenses.asl20; + maintainers = with maintainers; [offline zimbatm]; + platforms = platforms.unix; + }; + } // attrs'; +in rec { + + mkKops = generic; + + kops_1_12 = mkKops { + version = "1.12.2"; + sha256 = "0937crwifnld7r5pf5gvab9ibmf8k44dafr9y3hld2p01ijrari1"; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 77563721c58..5c1b2017788 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -23635,7 +23635,11 @@ in kontemplate = callPackage ../applications/networking/cluster/kontemplate { }; - kops = callPackage ../applications/networking/cluster/kops { }; + inherit (callPackage ../applications/networking/cluster/kops {}) + mkKops + kops_1_12 + ; + kops = kops_1_12; lguf-brightness = callPackage ../misc/lguf-brightness { };