Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsupported Kubernetes and Ruby versions from Krane and CI #905

Merged
merged 10 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 19 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,46 @@ jobs:
ruby-tests:
runs-on: ubuntu-latest

name: "Tests - Ruby ${{ matrix.ruby }} with k8s ${{ matrix.kubernetes_version }}"
name: "Tests - Ruby ${{ matrix.ruby }} with Kubernetes ${{ matrix.kubernetes_version }}"
strategy:
fail-fast: false
matrix:
ruby:
# Use unique Ruby versions, or GitHub gets confused when building the rest of the matrix
- '3.1.2' # With k8s 1.23
- '3.0.3' # With k8s 1.23
- '3.0.2' # With k8s 1.22
- '3.0.1' # With k8s 1.21
- '3.0' # With k8s 1.20
- '2.7' # With k8s 1.19
- "3.1.2"
- "3.0.4"
- "2.7.6"
kubernetes_version:
- "1.24.6"
- "1.23.12"
- "1.22.15"
include:
# Match kind images with chosen version https://github.com/kubernetes-sigs/kind/releases
- ruby: '3.1.2'
kind_version: 'v0.11.1'
kubernetes_version: '1.23.0'
kind_image: 'kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac'
- ruby: '3.0.3'
kind_version: 'v0.11.1'
kubernetes_version: '1.23.0'
kind_image: 'kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac'
- ruby: '3.0.2'
kind_version: 'v0.11.1'
kubernetes_version: '1.22.0'
kind_image: 'kindest/node:v1.22.0@sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047'
- ruby: '3.0.1'
kind_version: 'v0.11.1'
kubernetes_version: '1.21.1'
kind_image: 'kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6'
- ruby: '3.0'
kind_version: 'v0.11.1'
kubernetes_version: '1.20.7'
kind_image: 'kindest/node:v1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9'
- ruby: '2.7'
kind_version: 'v0.11.1'
kubernetes_version: '1.19.11'
kind_image: 'kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729'
- kubernetes_version: "1.24.6"
kind_image: "kindest/node:v1.24.6@sha256:97e8d00bc37a7598a0b32d1fabd155a96355c49fa0d4d4790aab0f161bf31be1"
- kubernetes_version: "1.23.12"
kind_image: "kindest/node:v1.23.12@sha256:9402cf1330bbd3a0d097d2033fa489b2abe40d479cc5ef47d0b6a6960613148a"
- kubernetes_version: "1.22.15"
kind_image: "kindest/node:v1.22.15@sha256:bfd5eaae36849bfb3c1e3b9442f3da17d730718248939d9d547e86bbac5da586"

steps:
- uses: actions/checkout@v2

- name: Set up Ruby ${{ matrix.ruby }}
- name: Setup Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Setup kubectl
- name: Setup kubectl ${{ matrix.kubernetes_version }}
run: |
mkdir -p "${GITHUB_WORKSPACE}/bin"
curl -o "${GITHUB_WORKSPACE}/bin/kubectl" -LO "https://dl.k8s.io/release/v${{ matrix.kubernetes_version }}/bin/linux/amd64/kubectl"
chmod +x "${GITHUB_WORKSPACE}/bin/kubectl"
echo "PATH=$GITHUB_WORKSPACE/bin:${PATH}" >> $GITHUB_ENV

- uses: engineerd/setup-kind@v0.5.0
- name: Setup Kind v0.16.0
uses: engineerd/setup-kind@v0.5.0
with:
version: "${{ matrix.kind_version }}"
version: v0.16.0
image: "${{ matrix.kind_image }}"

- name: Run tests
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## next

*Enhancements*

- CI test matrix now test all Krane supported Ruby and Kubernetes versions.
Ruby: 3.1.2 , 3.0.4 , 2.7.6, Kubernetes: - 1.24.6, 1.23.12, 1.22.15.

*Breaking Changes*
- Remove unsupported Kubernetes and Ruby versions from Krane and CI [#905](https://github.com/Shopify/krane/pull/905)

## 2.4.9

- Fixed a Ruby 3.1 regression that caused an exception when using a `--bindings=@<file>` argument to `krane render` [#900](https://github.com/Shopify/krane/pull/900)
Expand Down
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ behavior to [krane@shopify.com](mailto:krane@shopify.com).
## Maintainers

This project is currently under the stewardship of the Production Platform group at Shopify.
The two primary maintainers are @knverey and @dturn. Approval from at least one primary maintainer is
required for all significant feature proposals and code architecture changes. In general,
two people must approve all non-trivial PRs.
In general, two people must approve all non-trivial PRs.

## What should I know before I get started?

Expand Down Expand Up @@ -113,7 +111,7 @@ This gem uses subclasses of `KubernetesResource` to implement custom success/fai

If you work for Shopify, just run `dev up`, but otherwise:

1. [Install kubectl version 1.10.0 or higher](https://kubernetes.io/docs/user-guide/prereqs/) and make sure it is in your path
1. [Install kubectl version 1.22.0 or higher](https://kubernetes.io/docs/user-guide/prereqs/) and make sure it is in your path
2. [Install minikube](https://kubernetes.io/docs/getting-started-guides/minikube/#installation) (required to run the test suite)
3. [Install any required minikube drivers](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md) (on OS X, you may need the [hyperkit driver](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#hyperkit-driver)
4. Check out the repo
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,28 @@ If you need the ability to render dynamic values in templates before deploying,
## Prerequisites

* Ruby 2.7+
* Your cluster must be running Kubernetes v1.19.0 or higher<sup>1</sup>
* Your cluster must be running Kubernetes v1.22.0 or higher<sup>1</sup>

<sup>1</sup> We run integration tests against these Kubernetes versions. You can find our
official compatibility chart below.
## Compatibility

<sup>1</sup> We run integration tests against these Kubernetes versions. You can find our official compatibility chart below.

Krane provides support for official upstream supported versions [Kubernetes](https://endoflife.date/kubernetes), [Ruby](https://endoflife.date/ruby) that are part of the compatibility matrix; Nevertheless, older releases are still likely to work.

| Kubernetes version | Currently Tested? | Last officially supported in gem version |
|:------------------:|-------------------|:----------------------------------------:|
| 1.18 | No | 2.3.7 |
| 1.19 | Yes | -- |
| 1.20 | Yes | -- |
| 1.21 | Yes | -- |
| 1.19 | No | 2.4.9 |
| 1.20 | No | 2.4.9 |
| 1.21 | No | 2.4.9 |
| 1.22 | Yes | -- |
| 1.23 | Yes | -- |
| 1.24 | Yes | -- |
| 1.25 | No | -- |

## Installation

1. [Install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl) (requires v1.19.0 or higher) and make sure it is available in your $PATH
1. [Install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl) (requires v1.22.0 or higher) and make sure it is available in your $PATH
2. Set up your [kubeconfig file](https://kubernetes.io/docs/tasks/access-application-cluster/authenticate-across-clusters-kubeconfig/) for access to your cluster(s).
3. `gem install krane`

Expand Down Expand Up @@ -497,7 +502,7 @@ resource to restart.

## Prerequisites

* You've already deployed a [`PodTemplate`](https://v1-15.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/#podtemplate-v1-core) object with field `template` containing a `Pod` specification that does not include the `apiVersion` or `kind` parameters. An example is provided in this repo in `test/fixtures/hello-cloud/template-runner.yml`.
* You've already deployed a [`PodTemplate`](https://v1-22.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#podtemplate-v1-core) object with field `template` containing a `Pod` specification that does not include the `apiVersion` or `kind` parameters. An example is provided in this repo in `test/fixtures/hello-cloud/template-runner.yml`.
* The `Pod` specification in that template has a container named `task-runner`.

Based on this specification `krane run` will create a new pod with the entrypoint of the `task-runner ` container overridden with the supplied arguments.
Expand Down
2 changes: 1 addition & 1 deletion bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ docker run --rm \
-e VERBOSE=1 \
-e PARALLELISM=$PARALLELISM \
-w /usr/src/app \
ruby:"${RUBY_VERSION:-2.6.6}" \
ruby:"${RUBY_VERSION:-2.7.6}" \
bin/test
4 changes: 2 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if [ ! -x "$(which minikube)" ]; then
fi

if [ ! -x "$(which kubectl)" ]; then
echo -e "\n\033[0;33mPlease install kubectl version 1.15.0 or higher:\nhttps://kubernetes.io/docs/user-guide/prereqs/\033[0m"
echo -e "\n\033[0;33mPlease install kubectl version 1.22.0 or higher:\nhttps://kubernetes.io/docs/user-guide/prereqs/\033[0m"
else
KUBECTL_VERSION=$(kubectl version --short --client | grep -oe "v[[:digit:]\.]\+")
echo -e "\n\033[0;32mKubectl version $KUBECTL_VERSION is already installed. This gem requires version v1.15.0 or greater.\033[0m"
echo -e "\n\033[0;32mKubectl version $KUBECTL_VERSION is already installed. This gem requires version v1.22.0 or greater.\033[0m"
fi
4 changes: 2 additions & 2 deletions dev.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
name: krane
up:
- ruby: '3.0.3' # Matches gemspec
- ruby: '3.1.2' # Matches gemspec
- bundler
- podman
- kind:
name: krane
image: kindest/node:v1.22.0@sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047
image: kindest/node:v1.24.6@sha256:97e8d00bc37a7598a0b32d1fabd155a96355c49fa0d4d4790aab0f161bf31be1
commands:
test:
run: bin/test
Expand Down
2 changes: 1 addition & 1 deletion krane.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|

spec.metadata['allowed_push_host'] = "https://rubygems.org"

spec.required_ruby_version = '>= 2.6.0'
spec.required_ruby_version = '>= 2.7.6'
spec.add_dependency("activesupport", ">= 5.0")
spec.add_dependency("kubeclient", "~> 4.9")
spec.add_dependency("googleauth", "~> 1.2")
Expand Down
13 changes: 0 additions & 13 deletions lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ def fetch_resources(namespaced: false)
end.compact.uniq { |r| "#{r['apigroup']}/#{r['kind']}" }
end

def fetch_mutating_webhook_configurations
command = %w(get mutatingwebhookconfigurations)
raw_json, err, st = kubectl.run(*command, output: "json", attempts: 5, use_namespace: false)
if st.success?
JSON.parse(raw_json)["items"].map do |definition|
Krane::MutatingWebhookConfiguration.new(namespace: namespace, context: context, logger: logger,
definition: definition, statsd_tags: @namespace_tags)
end
else
raise FatalKubeAPIError, "Error retrieving mutatingwebhookconfigurations: #{err}"
end
end

private

# During discovery, the api paths may not actually be at the root, so we must programatically find it.
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
require 'krane/task_config_validator'

module Krane
MIN_KUBE_VERSION = '1.15.0'
MIN_KUBE_VERSION = '1.22.0'
end
25 changes: 8 additions & 17 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
custom_resource_definition
horizontal_pod_autoscaler
secret
mutating_webhook_configuration
).each do |subresource|
require "krane/kubernetes_resource/#{subresource}"
end
Expand Down Expand Up @@ -285,26 +284,18 @@ def validate_configuration(prune:)
end
measure_method(:validate_configuration)

def partition_dry_run_resources(resources)
individuals = []
mutating_webhook_configurations = cluster_resource_discoverer.fetch_mutating_webhook_configurations
mutating_webhook_configurations.each do |mutating_webhook_configuration|
mutating_webhook_configuration.webhooks.each do |webhook|
individuals = (individuals + resources.select { |resource| webhook.matches_resource?(resource) }).uniq
resources -= individuals
end
end
[resources, individuals]
end

def validate_resources(resources)
validate_globals(resources)
batchable_resources, individuals = partition_dry_run_resources(resources.dup)
batch_dry_run_success = kubectl.server_dry_run_enabled? && validate_dry_run(batchable_resources)
individuals += batchable_resources unless batch_dry_run_success
batch_dry_run_success = validate_dry_run(resources)
resources.select! { |r| r.selected?(@selector) } if @selector_as_filter

Krane::Concurrency.split_across_threads(resources) do |r|
r.validate_definition(kubectl: kubectl, selector: @selector, dry_run: individuals.include?(r))
# No need to pass in kubectl (and do per-resource dry run apply) if batch dry run succeeded
if batch_dry_run_success
r.validate_definition(kubectl: nil, selector: @selector, dry_run: false)
else
r.validate_definition(kubectl: kubectl, selector: @selector, dry_run: true)
end
end
failed_resources = resources.select(&:validation_failed?)
if failed_resources.present?
Expand Down
6 changes: 1 addition & 5 deletions lib/krane/kubectl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ def server_dry_run_enabled?
end

def dry_run_flag
if client_version >= Gem::Version.new("1.18")
"--dry-run=server"
else
"--server-dry-run"
end
"--dry-run=server"
end

private
Expand Down
17 changes: 2 additions & 15 deletions lib/krane/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ def group
version ? grouping : "core"
end

def version
prefix, version = @definition.dig("apiVersion").split("/")
version || prefix
end

def kubectl_resource_type
type
end
Expand Down Expand Up @@ -569,11 +564,7 @@ def validate_spec_with_kubectl(kubectl)

# Server side dry run is only supported on apply
def validate_with_server_side_dry_run(kubectl)
command = if kubectl.client_version >= Gem::Version.new('1.18')
["apply", "-f", file_path, "--dry-run=server", "--output=name"]
else
["apply", "-f", file_path, "--server-dry-run", "--output=name"]
end
command = ["apply", "-f", file_path, "--dry-run=server", "--output=name"]

kubectl.run(*command, log_failure: false, output_is_sensitive: sensitive_template_content?,
retry_whitelist: [:client_timeout, :empty, :context_deadline], attempts: 3)
Expand All @@ -584,11 +575,7 @@ def validate_with_server_side_dry_run(kubectl)
# If the resource template uses generateName, validating with apply will fail
def validate_with_local_dry_run(kubectl)
verb = deploy_method == :apply ? "apply" : "create"
command = if kubectl.client_version >= Gem::Version.new('1.18')
[verb, "-f", file_path, "--dry-run=client", "--output=name"]
else
[verb, "-f", file_path, "--dry-run", "--output=name"]
end
command = [verb, "-f", file_path, "--dry-run=client", "--output=name"]

kubectl.run(*command, log_failure: false, output_is_sensitive: sensitive_template_content?,
retry_whitelist: [:client_timeout, :empty, :context_deadline], attempts: 3, use_namespace: !global?)
Expand Down
Loading