Unverified Commit 8970ef98 authored by FKouhai's avatar FKouhai
Browse files

argocd: automate kubectl version to use in ldflags

parent 52d36112
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
  buildGoModule,
  fetchFromGitHub,
  installShellFiles,
  nix-update-script,
  stdenv,
}:

@@ -26,25 +27,27 @@ buildGoModule rec {

  ldflags =
    let
      package_url = "github.com/argoproj/argo-cd/v2/common";
      packageUrl = "github.com/argoproj/argo-cd/v2/common";
    in
    [
      "-s"
      "-w"
      "-X ${package_url}.version=${version}"
      "-X ${package_url}.buildDate=unknown"
      "-X ${package_url}.gitCommit=${src.rev}"
      "-X ${package_url}.gitTag=${src.rev}"
      "-X ${package_url}.gitTreeState=clean"
      "-X ${package_url}.kubectlVersion=v0.31.2"
      # NOTE: Update kubectlVersion when upgrading this package with
      # https://github.com/search?q=repo%3Aargoproj%2Fargo-cd+%22k8s.io%2Fkubectl%22+path%3Ago.mod&type=code
      # Per https://github.com/search?q=repo%3Aargoproj%2Fargo-cd+%22KUBECTL_VERSION%3D%22+path%3AMakefile&type=code
      # Will need a way to automate it :P
      "-X ${packageUrl}.version=${version}"
      "-X ${packageUrl}.buildDate=unknown"
      "-X ${packageUrl}.gitCommit=${src.rev}"
      "-X ${packageUrl}.gitTag=${src.rev}"
      "-X ${packageUrl}.gitTreeState=clean"
    ];

  nativeBuildInputs = [ installShellFiles ];

  # set ldflag for kubectlVersion since it is needed for argo
  # Per https://github.com/search?q=repo%3Aargoproj%2Fargo-cd+%22KUBECTL_VERSION%3D%22+path%3AMakefile&type=code
  prePatch = ''
    export KUBECTL_VERSION=$(grep 'k8s.io/kubectl v' go.mod | cut -f 2 -d " " | cut -f 1 -d "=" )
    echo using $KUBECTL_VERSION
    ldflags="''${ldflags} -X github.com/argoproj/argo-cd/v2/common.kubectlVersion=''${KUBECTL_VERSION}"
  '';
  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin