Skip to content

KOPS use custom build

Fred Vogt edited this page Aug 17, 2020 · 31 revisions

KOPS only provides tagged releases. To test with the latest from master or a release branch you'll have to build and upload the client binary and cloud assets.

Example: release-1.18 branch

S3 Build Bucket

For a "private" bucket:

resource "aws_s3_bucket" "kops_builds" {
  bucket = "kops-builds-${replace(var.domain, ".", "-")}"

  cors_rule {
    allowed_headers = ["*"]
    allowed_methods = ["GET", "HEAD"]
    allowed_origins = ["*"]
  }
}

data "aws_iam_policy_document" "kops_builds_s3" {
  ...

  statement {
    principals {
      type = "AWS"

      identifiers = local.org_account_roots
    }

    actions = [
      "s3:List*",
      "s3:Get*",
    ]

    resources = [
      "arn:aws:s3:::${aws_s3_bucket.kops_builds.bucket}",
      "arn:aws:s3:::${aws_s3_bucket.kops_builds.bucket}/kops/*",
    ]

    condition {
      test     = "StringEquals"
      variable = "aws:sourceVpce"
      values   = var.vpc_endpoints
    }
  }

  statement {
    principals {
      type = "*"

      identifiers = ["*"]
    }

    actions = [
      "s3:List*",
      "s3:Get*",
    ]

    resources = [
      "arn:aws:s3:::${aws_s3_bucket.kops_builds.bucket}",
      "arn:aws:s3:::${aws_s3_bucket.kops_builds.bucket}/kops/*",
    ]

    condition {
      test     = "IpAddress"
      variable = "aws:SourceIp"
      values   = var.allowed_cidr_blocks
    }
  }
}

resource "aws_s3_bucket_policy" "kops_builds" {
  bucket = aws_s3_bucket.kops_builds.bucket
  policy = data.aws_iam_policy_document.kops_builds_s3.json
}

Build Setup

# aws cli - install with pyenv+venv
pyenv local 3.8.3
virtualenv .venv
. .venv/bin/activate
pip install awscli

# checkout
git clone --single-branch --branch "release-1.18" "https://github.com/kubernetes/kops.git"
cd kops
kops$

# golang tooling - gvm
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
# Kops pre 1.19
kops$ gvm install "go$(grep 'GOVERSION=' Makefile | cut -d= -f2)" -B
kops$ gvm use "go$(grep 'GOVERSION=' Makefile | cut -d= -f2)"
# kops 1.19+
kops$ gvm install "go$(grep -E 'go[ ]+[0-9]+\.[0-9]+' go.mod | cut -d' ' -f2)" -B
kops$ gvm use "go$(grep -E 'go[ ]+[0-9]+\.[0-9]+' go.mod | cut -d' ' -f2)"

# bazel - ubuntu
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" \
    | sudo tee /etc/apt/sources.list.d/bazel.list
kops$ sudo apt install "bazel-$(cat .bazelversion)"

# bazel - mac
brew install bazel
(cd "/usr/local/Cellar/bazel/3.3.1/libexec/bin" && curl -LO https://releases.bazel.build/2.2.0/release/bazel-2.2.0-darwin-x86_64 && chmod +x bazel-2.2.0-darwin-x86_64)

bazel clean --expunge 
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license
bazel clean --expunge 

Build

# Must enable STATIC_BUILD

# .build/local/kops
kops$ make STATIC_BUILD=yes

export S3_BUCKET_NAME="kops-builds-..."
kops$ AWS_PROFILE=admin-main make dev-upload  STATIC_BUILD=yes "S3_BUCKET=s3://${S3_BUCKET_NAME}/"

Release in Github Fork

For easy inclusion in container builds.

  • https://github.com/<user>/kops/releases/tag/v<ci-version>-<git-sha>
cp "$(pwd)/.build/local/kops" /tmp/kops-linux-amd64
sha256sum /tmp/kops-linux-amd64

# Create a release in github
v<ci-version>-<git-sha>
Comment: sha256
Attach /tmp/kops-linux-amd64

Run

export AWS_REGION="us-west-2"
export S3_BUCKET_NAME="kops-builds-..."

# 1.18.0-beta.2
# export KOPS_VERSION="$(bazel run //cmd/kops version -- --short)"
export KOPS_VERSION="$($(which kops) version --short)"
export KOPS_BASE_URL=https://s3-${AWS_REGION}.amazonaws.com/${S3_BUCKET_NAME}/kops/${KOPS_VERSION}/
kops create cluster ...

PRs

git fetch <main-remote> pull/<id>/head:<local-branch>

git fetch upstream pull/9500/head:aws-iam-authenticator-modes-9500
git checkout aws-iam-authenticator-modes-9500

export _KOPS_VERSION="$(grep 'KOPS_CI_VERSION\s*=' version.go | awk '{print $3}' | sed -e 's/"//g')-$(git rev-parse --short HEAD)"
export S3_BUCKET_NAME="kops-builds-..."

make STATIC_BUILD=yes VERSION=$_KOPS_VERSION
make STATIC_BUILD=yes VERSION=$_KOPS_VERSION "$(pwd)/.build/dist/linux/amd64/kops"
AWS_PROFILE=admin-main make dev-upload STATIC_BUILD=yes VERSION=$_KOPS_VERSION "S3_BUCKET=s3://${S3_BUCKET_NAME}/"

shasum -a 256 "$(pwd)/.build/dist/linux/amd64/kops"
cp "$(pwd)/.build/dist/linux/amd64/kops" ~/Downloads/kops-linux-amd64

Forks

git remote add <name> ...
git fetch <name>
git checkout --track <name>/<branch>

Links