diff --git a/.idea/kubernetes-stack-cookbook.iml b/.idea/kubernetes-stack-cookbook.iml
new file mode 100644
index 0000000..f8b023f
--- /dev/null
+++ b/.idea/kubernetes-stack-cookbook.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..de6e841
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..01001c1
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..9db6edb
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,304 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1522256949771
+
+
+ 1522256949771
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.kitchen.dokken.yml b/.kitchen.dokken.yml
index 2e9be27..653d63e 100644
--- a/.kitchen.dokken.yml
+++ b/.kitchen.dokken.yml
@@ -1,13 +1,15 @@
---
driver:
name: dokken
- chef_version: latest
+ chef_version: <%= ENV['CHEF_VERSION'] || 'current' %>
+ privileged: true # because Docker and SystemD/Upstart
transport:
name: dokken
provisioner:
name: dokken
+ deprecations_as_errors: true
verifier:
name: inspec
@@ -15,15 +17,12 @@ verifier:
platforms:
- name: ubuntu-16.04
driver:
- image: ubuntu:16.04
- # pid_one_command: /bin/systemd
+ image: dokken/ubuntu-16.04
+ pid_one_command: /bin/systemd
intermediate_instructions:
- RUN /usr/bin/apt-get update
- - RUN /usr/bin/apt-get -y install curl lsb-release bash-completion
-- name: centos-7
- driver:
- image: centos:7
- privileged: true
- # pid_one_command: /usr/lib/systemd/systemd
- intermediate_instructions:
- - RUN yum -y install lsof which net-tools curl bash-completion
+
+# - name: centos-7
+# driver:
+# image: dokken/centos-7
+# pid_one_command: /usr/lib/systemd/systemd
diff --git a/.kitchen.yml b/.kitchen.yml
index 7566a3b..00b3db2 100644
--- a/.kitchen.yml
+++ b/.kitchen.yml
@@ -14,18 +14,20 @@ verifier:
platforms:
- name: ubuntu-16.04
- - name: centos-7.3
+ # - name: centos-7
suites:
- - name: smoke-install-default
+ - name: smoke-install
run_list:
+ - recipe[kubernetes-stack-test::default]
- recipe[kubernetes-stack-test::install]
verifier:
inspec_tests:
- test/smoke/default/default_test.rb
- - test/smoke/gcloud/gcloud_install_default_test.rb
- - test/smoke/kubectl/kubectl_install_default_test.rb
- - test/smoke/helm/helm_install_default_test.rb
+ - test/smoke/kubectl/kubectl_install_test.rb
+ - test/smoke/gcloud/gcloud_install_test.rb
+ - test/smoke/helm/helm_install_test.rb
+ - test/smoke/minikube/minikube_install_test.rb
attributes:
kubernetes-stack:
kubectl:
@@ -37,36 +39,25 @@ suites:
helm:
enabled: true,
version: ""
-
- - name: smoke-install-specific-version
- run_list:
- - recipe[kubernetes-stack-test::install]
- verifier:
- inspec_tests:
- - test/smoke/default/default_test.rb
- - test/smoke/gcloud/gcloud_install_specific_version_test.rb
- - test/smoke/kubectl/kubectl_install_specific_version_test.rb
- - test/smoke/helm/helm_install_specific_version_test.rb
- attributes:
- kubernetes-stack:
- kubectl:
+ minikube:
enabled: true,
- version: "v1.7.0"
- gcloud:
- enabled: true,
- version: "158.0.0"
- helm:
- enabled: true,
- version: "v2.4.2"
+ version: "v0.25.2"
+ k8s_version: ""
+ network_plugin: "cni"
+ bootstrapper: "kubeadm"
+ vm_driver: "none"
- name: smoke-uninstall
run_list:
+ - recipe[kubernetes-stack-test::default]
- recipe[kubernetes-stack-test::uninstall]
verifier:
inspec_tests:
+ - test/smoke/default/default_test.rb
- test/smoke/gcloud/gcloud_uninstall_test.rb
- - test/smoke/kubectl/kubectl_uninstall_test.rb
- test/smoke/helm/helm_uninstall_test.rb
+ - test/smoke/kubectl/kubectl_uninstall_test.rb
+ - test/smoke/minikube/minikube_uninstall_test.rb
attributes:
kubernetes-stack:
kubectl:
@@ -78,3 +69,10 @@ suites:
helm:
enabled: true,
version: ""
+ minikube:
+ enabled: true,
+ version: "v0.25.2"
+ k8s_version: ""
+ network_plugin: "cni"
+ bootstrapper: "kubeadm"
+ vm_driver: "none"
diff --git a/.rubocop.yml b/.rubocop.yml
index bf2e916..265606c 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,4 +1,5 @@
AllCops:
+ TargetRubyVersion: 2.4
Exclude:
- vendor/**/*
- Guardfile
diff --git a/.travis.yml b/.travis.yml
index 21e58c5..b9d9259 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,31 +9,29 @@ addons:
packages:
- chefdk
+# Don't `bundle install` which takes about 1.5 mins
install: echo "skip bundle install"
services: docker
env:
matrix:
- - INSTANCE=smoke-install-default-ubuntu-1604
- - INSTANCE=smoke-install-default-centos-7
- - INSTANCE=smoke-install-specific-version-ubuntu-1604
- - INSTANCE=smoke-install-specific-version-centos-7
+ - INSTANCE=smoke-install-ubuntu-1604
+ # - INSTANCE=smoke-install-default-centos-7
- INSTANCE=smoke-uninstall-ubuntu-1604
- - INSTANCE=smoke-uninstall-centos-7
+ # - INSTANCE=smoke-uninstall-centos-7
-# Ensure we make ChefDK's Ruby the default
before_script:
- sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
- eval "$(/opt/chefdk/bin/chef shell-init bash)"
- chef gem install kitchen-dokken
+ - chef gem install docker-api
+ - eval "$(/opt/chefdk/bin/chef shell-init bash)"
script: KITCHEN_LOCAL_YAML=.kitchen.dokken.yml /opt/chefdk/embedded/bin/kitchen verify ${INSTANCE}
matrix:
include:
- - before_script:
- - eval "$(/opt/chefdk/bin/chef shell-init bash)"
- script:
- /opt/chefdk/embedded/bin/chef --version
- /opt/chefdk/embedded/bin/cookstyle --version
diff --git a/Berksfile b/Berksfile
index 7965508..ad2a6cb 100644
--- a/Berksfile
+++ b/Berksfile
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
source 'https://supermarket.chef.io'
metadata
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..b99c1ce
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1 @@
+Please refer to https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 93201d8..743e65a 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -7,4 +7,4 @@
see:
-- https://github.com/teracyhq-incubator/kubernetes-stack-cookbook/graphs/contributors
+- https://github.com/teracyhq-incubator/kubernetes-stack-cookbook/graphs/contributors
\ No newline at end of file
diff --git a/README.md b/README.md
index 5817561..8cdde6d 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,24 @@ Kubernetes stack cookbook to work with Kubernetes: https://supermarket.chef.io/c
- `kubectl`: support all centos-7 and ubuntu-16.04 versions.
- `helm`: support all centos-7 and ubuntu-16.04 versions.
-- `gcloud`: support all centos-7 and ubuntu-16.04 versions. Should use version avaiable in https://packages.cloud.google.com/apt/ (with ubuntu platform) for faster autocomplete.
+- `gcloud`: support all centos-7 and ubuntu-16.04 versions.
+- `minikube`: support all centos-7 and ubuntu-16.04 versions.
+
+## Cookbook
+
+- kubernetes-stack
+- docker
+
+## Requirement
+
+- docker must be installed in machine
+- `minikube` should be run with special user. You can change by override attributes in recipe:
+
+ ```ruby
+ node.override['kubernetes-stack']['user'] = `user`
+ ```
+
+- or edit attributes in `default.rb` file
## How to use
@@ -26,19 +43,29 @@ Kubernetes stack cookbook to work with Kubernetes: https://supermarket.chef.io/c
kubectl 'install kubectl' do
action [:install, :remove]
version '' #application version (if empty, default: latest)
- binary_path '' #application path (if empty, default: /usr/local/bin/kubectl)
+ path '' #application path (if empty, default: /usr/local/bin)
end
gcloud 'install gcloud' do
action [:install, :remove]
version '' #application version (if empty, default: latest)
- binary_path '' #application path (if empty, default: /usr/local/bin/gcloud)
+ path '' #application path (if empty, default: /usr/local/bin)
end
helm 'install helm' do
action [:install, :remove]
version '' #application version (if empty, default: latest)
- binary_path '' #application path (if empty, default: /usr/local/bin/helm)
+ path '' #application path (if empty, default: /usr/local/bin)
+end
+
+minikube 'install minikube' do
+ action [:install, :run, :remove]
+ version '' #application version (if empty, default: latest)
+ path '' #application path (if empty, default: /usr/local/bin)
+ k8s_version '' #kubernetes_version (if empty, default: latest)
+ network_plugin '' #network plugin use in minikube
+ bootstrapper '' #bootstrapper use in minikube
+ vm_driver '' #vm driver use in minikube (if empty, default: none)
end
```
@@ -85,6 +112,7 @@ end
- [gcloud](#gcloud): install or remove `google-cloud-sdk`.
- [kubectl](#kubectl): install or remove `kubectl`.
- [helm](#helm): install or remove `helm`.
+- [minikube](#minikube): install and run or remove `minikube`.
## Resources detail
## gcloud
@@ -99,7 +127,7 @@ Install `gcloud` with default version:
gcloud 'install default gcloud' do
action :install
version ''
- binary_path ''
+ path ''
end
```
@@ -109,7 +137,7 @@ Install `gcloud` with specific version:
gcloud 'install specific gcloud version' do
action :install
version '164.0.0'
- binary_path ''
+ path ''
end
```
@@ -125,7 +153,7 @@ end
- `action` - `:install` to install `gcloud`, `:remove` to uninstall `gcloud`.
- `version` - The desired version of `gcloud`.
-- `binary_path` - Application path (if empty, default:/usr/local/bin/gcloud)
+- `path` - Application path (if empty, default:/usr/local/bin).
## kubectl
@@ -139,7 +167,7 @@ Install `kubectl` with default version:
kubectl 'install default kubectl' do
action :install
version ''
- binary_path ''
+ path ''
end
```
@@ -149,7 +177,7 @@ Install `kubectl` with specific version:
kubectl 'install specific kubectl version' do
action :install
version 'v1.7.0'
- binary_path ''
+ path ''
end
```
@@ -164,7 +192,7 @@ end
### Properties
- `action` - `:install` to install `kubectl`, `:remove` to uninstall `kubectl`.
- `version` - The desired version of `kubectl`.
-- `binary_path` - Application path (if empty, default:/usr/local/bin/kubectl)
+- `path` - Application path (if empty, default:/usr/local/bin).
## helm
@@ -178,7 +206,7 @@ Install `helm` with default version:
helm 'install default helm' do
action :install
version ''
- binary_path ''
+ path ''
end
```
@@ -188,7 +216,7 @@ Install `helm` with specific version:
helm 'install specific helm version' do
action :install
version 'v2.4.2'
- binary_path ''
+ path ''
end
```
@@ -203,7 +231,44 @@ end
### Properties
- `action` - `:install` to install `helm`, `:remove` to uninstall `helm`.
- `version` - The desired version of `helm`.
-- `binary_path` - Application path (if empty, default:/usr/local/bin/helm)
+- `path` - Application path (if empty, default:/usr/local/bin).
+
+## minikube
+
+The `minikube` resource auto-install and run or auto-remove `minikube` with the provider resolution system.
+
+### Example
+
+Install and run `minikube`:
+
+```ruby
+minikube 'install minikube' do
+ action [:install, :run]
+ version 'v0.25.2' #application version (if empty, default: latest)
+ path '' #application path (if empty, default: /usr/local/bin)
+ k8s_version '' #kubernetes_version (if empty, default: latest)
+ network_plugin 'cni' #network plugin use in minikube
+ bootstrapper 'kubeadm' #bootstrapper use in minikube
+ vm_driver 'none' #vm driver use in minikube (if empty, default: none)
+end
+```
+
+Remove `minikube`:
+
+```ruby
+minikube 'remove minikube' do
+ action :remove
+end
+```
+
+### Properties
+- `action` - `:install` to install `minikube`, `:remove` to uninstall `minikube`.
+- `version` - The desired version of `minikube`.
+- `k8s_version` - The desired version of `kubernetes resource`.
+- `path` - Application path (if empty, default:/usr/local/bin).
+- `network_plugin` - Network plugin.
+- `bootstrapper` - Bootstrapper.
+- `vm_driver` - Vm driver (if empty, default:none).
## See more:
diff --git a/TESTING.md b/TESTING.md
new file mode 100644
index 0000000..66d780f
--- /dev/null
+++ b/TESTING.md
@@ -0,0 +1 @@
+Please refer to https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD
diff --git a/attributes/default.rb b/attributes/default.rb
index 76e708b..24dcb23 100644
--- a/attributes/default.rb
+++ b/attributes/default.rb
@@ -1,21 +1,27 @@
+# frozen_string_literal: true
# The MIT License (MIT)
#
-# Copyright:: 2017, Teracy Corporation
+# Cookbook:: kubernetes-stack
+# Attribute:: default
#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
+# Copyright:: 2008-2018, Chef Software, Inc.
#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+default['kubernetes-stack']['arch'] = 'amd64'
+default['kubernetes-stack']['sys'] = 'linux'
+default['kubernetes-stack']['user'] = node['kubernetes-stack']['user'] || 'vagrant'
+default['kubernetes-stack']['home'] = "/home/#{node['kubernetes-stack']['user']}"
+
+default['docker_machine']['version'] = 'v0.14.0'
+default['docker_machine']['command_path'] = '/usr/local/bin/docker-machine'
diff --git a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/metadata.rb b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/metadata.rb
index 7bf3b26..35b8d88 100644
--- a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/metadata.rb
+++ b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/metadata.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
name 'kubernetes-stack-cookbook'
maintainer 'The Authors'
maintainer_email 'you@example.com'
@@ -20,3 +21,4 @@
# source_url 'https://github.com//kubernetes-stack-cookbook'
depends 'chef-dk'
+depends 'docker'
diff --git a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/recipes/chefdk.rb b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/recipes/chefdk.rb
index f6821fa..94d9584 100644
--- a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/recipes/chefdk.rb
+++ b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/recipes/chefdk.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
chef_dk 'latest chefdk' do
global_shell_init true
action :install
diff --git a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/recipes/default.rb b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/recipes/default.rb
index 29ad8bc..0d5dbc0 100644
--- a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/recipes/default.rb
+++ b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/recipes/default.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack-cookbook
# Recipe:: default
diff --git a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/spec/unit/recipes/default_spec.rb b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/spec/unit/recipes/default_spec.rb
index c06c8f5..348d67d 100644
--- a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/spec/unit/recipes/default_spec.rb
+++ b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/spec/unit/recipes/default_spec.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack-cookbook
# Spec:: default
diff --git a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/test/smoke/default/default_test.rb b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/test/smoke/default/default_test.rb
index ffc95d8..55800c1 100644
--- a/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/test/smoke/default/default_test.rb
+++ b/dev-setup/chef/main-cookbooks/kubernetes-stack-cookbook/test/smoke/default/default_test.rb
@@ -1,4 +1,5 @@
-# # encoding: utf-8
+# frozen_string_literal: true
+# encoding: utf-8
# Inspec test for recipe kubernetes-stack-cookbook::default
diff --git a/dev-setup/vagrant_config_default.json b/dev-setup/vagrant_config_default.json
index 6507293..e195594 100644
--- a/dev-setup/vagrant_config_default.json
+++ b/dev-setup/vagrant_config_default.json
@@ -14,8 +14,7 @@
"_id": "kubernetes-stack-cookbook-0",
"key": "KITCHEN_LOCAL_YAML",
"value": ".kitchen.dokken.yml",
- "action": "add" // one of add, remove. Default: add.
- // See more: https://github.com/customink-webops/magic_shell/blob/master/resources/environment.rb
+ "action": "add"
}]
}
}
diff --git a/libraries/helpers.rb b/libraries/helpers.rb
new file mode 100644
index 0000000..add0c5c
--- /dev/null
+++ b/libraries/helpers.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+module KubernetesStackCookbook
+ module Helpers
+ include Chef::Mixin::ShellOut
+
+ # Determines if sudo is installed on a system.
+ #
+ # @return [Boolean]
+ def sudo_installed?
+ !which('sudo').nil?
+ end
+
+ # Determines if docker is installed on a system.
+ #
+ # @return [Boolean]
+ def docker_installed?
+ !which('docker').nil?
+ end
+
+ # Determines if user has in system.
+ #
+ # @return [Boolean]
+ def user_exist?(user_name)
+ cmd = shell_out!("getent passwd #{user_name}", returns: [0, 2])
+ cmd.stderr.empty? && (cmd.stdout =~ /^#{user_name}/)
+ end
+
+ # Determines if bash-completion is installed on a system.
+ #
+ # @return [Boolean]
+ def bash_completion_installed?
+ !which('bash-completion').nil?
+ end
+
+ # Finds a command in $PATH
+ #
+ # @return [String, nil]
+ def which(cmd)
+ paths = (ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin))
+
+ paths.each do |path|
+ possible = File.join(path, cmd)
+ return possible if File.executable?(possible)
+ end
+
+ nil
+ end
+ end
+end
+
+Chef::Recipe.send(:include, ::KubernetesStackCookbook::Helpers)
diff --git a/libraries/matcher.rb b/libraries/matcher.rb
index 4c4dfd9..d1e3f45 100644
--- a/libraries/matcher.rb
+++ b/libraries/matcher.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
if defined?(ChefSpec)
def install_kubectl(message)
ChefSpec::Matchers::ResourceMatcher.new(:kubectl, :install, message)
@@ -10,4 +11,8 @@ def install_helm(message)
def install_gcloud(message)
ChefSpec::Matchers::ResourceMatcher.new(:gcloud, :install, message)
end
+
+ def install_minikube(message)
+ ChefSpec::Matchers::ResourceMatcher.new(:minikube, :install, message)
+ end
end
diff --git a/metadata.rb b/metadata.rb
index a3693bc..d781c7e 100644
--- a/metadata.rb
+++ b/metadata.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
name 'kubernetes-stack'
maintainer 'Teracy Corporation'
maintainer_email 'hq@teracy.com'
@@ -22,3 +23,6 @@
supports 'ubuntu'
supports 'centos'
+
+depends 'docker'
+gem 'docker-api', '= 1.34.0'
diff --git a/recipes/default.rb b/recipes/default.rb
index cb756b9..a286520 100644
--- a/recipes/default.rb
+++ b/recipes/default.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack
# Recipe:: default
diff --git a/resources/gcloud.rb b/resources/gcloud.rb
index 6208f39..bb0f257 100644
--- a/resources/gcloud.rb
+++ b/resources/gcloud.rb
@@ -1,7 +1,8 @@
+# frozen_string_literal: true
resource_name :gcloud
property :version, String, default: ''
-property :binary_path, String, default: '/usr/local/bin/gcloud'
+property :path, String, default: '/usr/local/bin'
default_action :install
@@ -9,206 +10,277 @@
end
action :install do
- version = latest_version()
- version = new_resource.version unless new_resource.version.empty?
- existing_version = existing_version()
+ version = new_resource.version
+ version = latest_ver if new_resource.version.empty?
- if existing_version != version
- # Deleting previous version if mismatched
- delete_gcloud(binary_path) unless existing_version.empty?
+ Chef::Log.info("gcloud install version = '#{version}'")
- arch_cmd = Mixlib::ShellOut.new('uname -m')
- arch_cmd.run_command
- arch_cmd.error!
- arch = arch_cmd.stdout.strip
+ current = current_ver
- install_requirement
+ Chef::Log.info("gcloud current version = '#{current}'")
+
+ if current != version
+ # Deleting previous version if mismatched
+ delete_gcloud unless current.nil?
+
+ directory new_resource.path do
+ action :create
+ not_if { Dir.exist?(new_resource.path) }
+ mode 0755
+ notifies :write, "log[create #{new_resource.path} directory]", :immediately
+ end
- install_path = '/usr/lib'
+ log "create #{new_resource.path} directory" do
+ level :info
+ action :nothing
+ end
- install_root_dir = "#{install_path}/google-cloud-sdk"
+ install_requirement
if platform?('ubuntu')
version_avaiable = version_avaiable_in_apt_package(version)
- end
- # Gcloud version will be installed via apt-get
- if version_avaiable
- if platform?('ubuntu')
- execute 'import google-cloud-sdk public key' do
- command 'curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -'
- end
+ version = latest_ver unless version_avaiable
- apt_repository 'google-cloud-sdk' do
- uri 'http://packages.cloud.google.com/apt'
- distribution "cloud-sdk-#{node['lsb']['codename']}"
- components ['main']
- # key 'A7317B0F'
- # keyserver 'packages.cloud.google.com/apt/doc/apt-key.gpg'
- end
+ execute 'import google-cloud-sdk public key' do
+ command 'curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -'
+ end
- package 'google-cloud-sdk' do
- version "#{version}-0"
- end
+ apt_repository 'google-cloud-sdk' do
+ uri 'http://packages.cloud.google.com/apt'
+ distribution "cloud-sdk-#{node['lsb']['codename']}"
+ components ['main']
+ # key 'A7317B0F'
+ # keyserver 'packages.cloud.google.com/apt/doc/apt-key.gpg'
end
- # Link to binary_path
- link_to_path(binary_path, install_root_dir)
- # Disable update notification when run command 'gcloud version'
- disable_update_check(install_root_dir)
+ apt_package 'google-cloud-sdk' do
+ version "#{version}-0"
+ action :install
+ end
+ elsif platform?('centos')
+ version_avaiable = version_avaiable_in_yum_package(version)
+
+ version = latest_ver unless version_avaiable
+
+ yum_repository 'google-cloud-sdk' do
+ description 'google-cloud-sdk'
+ baseurl 'https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64'
+ enabled true
+ gpgcheck true
+ repo_gpgcheck true
+ gpgkey [
+ 'https://packages.cloud.google.com/yum/doc/yum-key.gpg',
+ 'https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg',
+ ]
+ end
- # Gcloud version will be installed via file downloaded
+ yum_package 'google-cloud-sdk' do
+ version version
+ action :install
+ end
else
- download_url = "https://storage.googleapis.com/cloud-sdk-release/google-cloud-sdk-#{version}-linux-#{arch} -m`.tar.gz"
+ raise 'platform not support'
+ end
- execute "curl #{download_url} | tar xvz" do
- cwd install_path
- action :run
- not_if 'which gcloud'
- end
+ gcloud_dir = gcloud_installation_dir
- execute './google-cloud-sdk/install.sh --quiet' do
- cwd install_path
- action :run
- only_if "test -d #{install_root_dir}"
+ log "installation root dir : #{gcloud_dir}" do
+ level :info
+ not_if { gcloud_dir.empty? }
+ end
+
+ %w(gcloud gsutil bq).each do |gc|
+ link "#{new_resource.path}/#{gc}" do
+ to "#{gcloud_dir}/bin/#{gc}"
end
+ end
- # Link to binary_path
- link_to_path(binary_path, install_root_dir)
- # Disable update notification when run command 'gcloud version'
- disable_update_check(install_root_dir)
- # Install autocomplete
- install_autocomplete(install_root_dir)
+ # Disable update notification when run command 'gcloud version'
+ execute 'disable update check' do
+ command 'gcloud config set --installation component_manager/disable_update_check true'
+ end
+
+ # Update file config.json
+ execute 'update gcloud file config' do
+ command "sed -i -- 's/\"disable_updater\": false/\"disable_updater\": true/g' #{gcloud_dir}/lib/googlecloudsdk/core/config.json"
+ end
+
+ package 'bash-completion' do
+ action :install
+ notifies :write, 'log[install bash-completion]', :immediately
+ not_if { Dir.exist?('/etc/bash_completion.d') }
+ end
+
+ log 'install bash-completion' do
+ level :info
+ action :nothing
+ end
+
+ remote_file 'install autocomplete' do
+ path '/etc/bash_completion.d/gcloud'
+ source "file://#{gcloud_dir}/completion.bash.inc"
+ mode '0755'
+ end
+
+ link gcloud_completion_path do
+ to "#{gcloud_dir}/completion.bash.inc"
+ mode '0755'
+ end
+
+ ruby_block 'check gcloud autocompletion' do
+ block do
+ if ::File.exist?(gcloud_completion_path)
+ log 'gcloud autocomplete has installed' do
+ level :info
+ end
+ else
+ log 'gcloud autocomplete has not installed' do
+ level :error
+ end
+ end
+ end
+ action :run
+ end
+ else
+ log 'no need to install new gcloud version' do
+ level :info
end
end
end
action :remove do
- delete_gcloud(binary_path)
+ delete_gcloud
end
action_class do
- def latest_version
- latest_version_url = "curl -s https://cloud.google.com/sdk/docs/release-notes | grep 'h2' | head -1 | cut -d '>' -f2 | sed 's/[[:space:]].*//'"
- latest_version_cmd = Mixlib::ShellOut.new(latest_version_url)
- latest_version_cmd.run_command
-
- latest_version = ''
- latest_version = latest_version_cmd.stdout.strip if latest_version_cmd.stderr.empty? && !latest_version_cmd.stdout.empty?
- latest_version
+ def sys
+ node['kubernetes-stack']['sys']
end
- def existing_version
- existing_version_cmd = Mixlib::ShellOut.new("gcloud version | head -1 | grep -o -E '[0-9].*'")
- existing_version_cmd.run_command
+ def binary_path
+ "#{new_resource.path}/gcloud"
+ end
- existing_version = ''
- existing_version = existing_version_cmd.stdout.strip if existing_version_cmd.stderr.empty? && !existing_version_cmd.stdout.empty?
- existing_version
+ def gcloud_installation_dir
+ return '/usr/lib64/google-cloud-sdk' if node['platform'] == 'centos'
+ '/usr/lib/google-cloud-sdk'
end
- def version_avaiable_in_apt_package(version)
- version_avaiable_cmd = Mixlib::ShellOut.new("curl -s https://packages.cloud.google.com/apt/dists/cloud-sdk-$(lsb_release -c -s)/main/binary-amd64/Packages | grep 'google-cloud-sdk_#{version}'")
- version_avaiable_cmd.run_command
+ def gcloud_completion_path
+ '/etc/bash_completion.d/gcloud'
+ end
- version_avaiable = false
- version_avaiable = true if version_avaiable_cmd.stderr.empty? && !version_avaiable_cmd.stdout.empty?
- version_avaiable
+ def latest_ver
+ cmd = Mixlib::ShellOut.new("curl -s https://cloud.google.com/sdk/docs/release-notes | grep 'h2' | head -1 | cut -d '>' -f2 | sed 's/[[:space:]].*//'")
+ cmd.run_command
+
+ ver = cmd.stderr.empty? && !cmd.stdout.empty? ? cmd.stdout.strip : nil
+ ver
end
- def link_to_path(binary_path, install_root_dir)
- link binary_path do
- to "#{install_root_dir}/bin/gcloud"
- only_if "test -f #{install_root_dir}/bin/gcloud"
- end
+ def current_ver
+ cmd = Mixlib::ShellOut.new("gcloud version | head -1 | grep -o -E '[0-9].*'")
+ cmd.run_command
- # Add gsutil to ENV_PATH
- link '/usr/local/bin/gsutil' do
- to "#{install_root_dir}/bin/gsutil"
- only_if "test -f #{install_root_dir}/bin/gsutil"
- end
+ ver = cmd.stderr.empty? && !cmd.stdout.empty? ? cmd.stdout.strip : nil
+ ver
+ end
- # Add bq command to ENV_PATH
- link '/usr/local/bin/bq' do
- to "#{install_root_dir}/bin/bq"
- only_if "test -f #{install_root_dir}/bin/bq"
- end
+ def version_avaiable_in_apt_package(version)
+ cmd = Mixlib::ShellOut.new("curl -s https://packages.cloud.google.com/apt/dists/cloud-sdk-$(lsb_release -c -s)/main/binary-amd64/Packages | grep 'google-cloud-sdk_#{version}'")
+ cmd.run_command
+
+ version_avaiable = cmd.stderr.empty? && !cmd.stdout.empty? ? true : false
+ version_avaiable
end
- def disable_update_check(install_root_dir)
- # Disable update notification when run command 'gcloud version'
- execute 'disable update check' do
- command 'gcloud config set --installation component_manager/disable_update_check true'
- end
+ def version_avaiable_in_yum_package(version)
+ cmd = Mixlib::ShellOut.new("curl -s https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64/repodata/other.xml | grep 'google-cloud-sdk_#{version}'")
+ cmd.run_command
- # Update file config.json
- execute 'update gcloud file config' do
- command "sed -i -- 's/\"disable_updater\": false/\"disable_updater\": true/g' #{install_root_dir}/lib/googlecloudsdk/core/config.json"
- end
+ version_avaiable = cmd.stderr.empty? && !cmd.stdout.empty? ? true : false
+ version_avaiable
end
def install_requirement
- case node[:platform]
- when 'ubuntu'
- package %w(bash-completion python python-pip apt-transport-https)
- when 'centos'
- package %w(bash-completion python)
- execute 'download pip' do
- command "curl 'https://bootstrap.pypa.io/get-pip.py' -o 'get-pip.py'"
+ if platform?('ubuntu')
+ package %w(gcc python-dev python-setuptools python-pip lsb-release apt-transport-https openssh-client)
+ end
+
+ if platform?('centos')
+ package %w(gcc python python-setuptools)
+
+ remote_file 'get python pip' do
+ path "#{Chef::Config[:file_cache_path]}/get-pip.py"
+ source 'https://bootstrap.pypa.io/get-pip.py'
+ mode '0755'
+ action :create
end
execute 'install pip' do
+ cwd Chef::Config[:file_cache_path]
command 'python get-pip.py'
+ action :run
end
end
execute 'install crc-mod' do
+ cwd '/tmp'
command 'pip install -U crcmod'
+ action :run
end
end
- def install_autocomplete(install_root_dir)
- remote_file 'install autocomplete' do
- path '/etc/bash_completion.d/gcloud'
- source "file://#{install_root_dir}/completion.bash.inc"
- mode '0755'
- end
-
- link '/etc/bash_completion.d/gcloud' do
- to "#{install_root_dir}/completion.bash.inc"
- mode '0755'
+ def delete_gcloud
+ bash 'remove config directory' do
+ user 'root'
+ code <<-EOH
+ config_dir=$(gcloud info --format='value(config.paths.global_config_dir)');
+ rm -rf $config_dir
+ EOH
+ notifies :write, 'log[config directory has deleted successfull]', :immediately
+ only_if 'which gcloud'
end
- end
- def delete_gcloud(binary_path)
- if platform?('ubuntu')
- execute 'to complete remove gcloud' do
- command 'apt-get purge --auto-remove -y google-cloud-sdk'
- action :run
- end
+ log 'config directory has deleted successfull' do
+ level :info
+ action :nothing
end
- file 'cleanup_binany_path' do
- path binary_path
- action :delete
+ bash 'remove installation directory' do
+ user 'root'
+ code <<-EOH
+ installation_dir=$(gcloud info --format='value(installation.sdk_root)');
+ rm -rf $installation_dir
+ EOH
+ notifies :write, 'log[installation directory has deleted successfull]', :immediately
only_if 'which gcloud'
end
- directory 'cleanup_config_path' do
- path '~/.config/gcloud'
- recursive true
- action :delete
- only_if 'test -d ~/.config/gcloud'
+ log 'installation directory has deleted successfull' do
+ level :info
+ action :nothing
end
- directory 'cleanup_install_root_dir' do
- path '/usr/lib/google-cloud-sdk'
- recursive true
- action :delete
- only_if 'test -d /usr/lib/google-cloud-sdk'
+ %w(gcloud gsutil bq).each do |gc|
+ bash "remove #{gc} binary path" do
+ user 'root'
+ code <<-EOH
+ #{gc}_binary=$(which #{gc});
+ rm -rf $#{gc}_binary
+ EOH
+ notifies :write, "log[#{gc} has deleted successfull]", :immediately
+ only_if { ::File.exist?("#{new_resource.path}/#{gc}") }
+ end
+
+ log "#{gc} has deleted successfull" do
+ level :info
+ action :nothing
+ end
end
- file 'cleanup_completion_path' do
+ file gcloud_completion_path do
path '/etc/bash_completion.d/gcloud'
action :delete
only_if 'test -f /etc/bash_completion.d/gcloud'
diff --git a/resources/helm.rb b/resources/helm.rb
index 5fe6145..e92c07b 100644
--- a/resources/helm.rb
+++ b/resources/helm.rb
@@ -1,7 +1,8 @@
+# frozen_string_literal: true
resource_name :helm
property :version, String, default: ''
-property :binary_path, String, default: '/usr/local/bin/helm'
+property :path, String, default: '/usr/local/bin'
default_action :install
@@ -10,84 +11,192 @@
action :install do
version = new_resource.version
+ version = latest_ver if new_resource.version.empty?
- arch_cmd = Mixlib::ShellOut.new('uname -m')
- arch_cmd.run_command
- arch_cmd.error!
- arch = arch_cmd.stdout.strip
-
- case arch
- when 'x86', 'i686', 'i386'
- arch = '386'
- when 'x86_64', 'aarch64'
- arch = 'amd64'
- when 'armv5*'
- arch = 'armv5'
- when 'armv6*'
- arch = 'armv6'
- when 'armv7*'
- arch = 'armv7'
- else
- arch = 'default'
+ log "helm install version = '#{version}'" do
+ level :info
end
- if version.empty?
- latest_version_url = "curl -s https://api.github.com/repos/kubernetes/helm/releases/latest | grep 'tag_name' | cut -d\\\" -f4"
- latest_version_cmd = Mixlib::ShellOut.new(latest_version_url)
- latest_version_cmd.run_command
- latest_version_cmd.error!
- version = latest_version_cmd.stdout.strip
+ current = current_ver
+
+ log "helm current version = '#{current}'" do
+ level :info
end
- # Command to check if we should be installing helm or not.
- existing_version_cmd = Mixlib::ShellOut.new("helm version --short --client | cut -d ':' -f2 | sed 's/[[:space:]]//g' | sed 's/+.*//'")
- existing_version_cmd.run_command
+ if current != version
- if existing_version_cmd.stderr.empty? && !existing_version_cmd.stdout.empty?
- existing_version = existing_version_cmd.stdout.strip
- end
+ remove_helm unless current.nil?
- if existing_version.to_s != version.to_s
- bash 'clean up the mismatched helm version' do
- code <<-EOF
- helm_binary=$(which helm);
- rm -rf $helm_binary
- EOF
- only_if 'which helm'
+ get_helm_url = "https://storage.googleapis.com/kubernetes-helm/helm-#{version}-#{sys}-#{arch}.tar.gz"
+
+ log "helm chart will be downloaded at #{get_helm_url}" do
+ level :info
end
- download_url = "https://storage.googleapis.com/kubernetes-helm/helm-#{version}-linux-#{arch}.tar.gz"
+ execute 'get helm' do
+ user 'root'
+ cwd '/tmp'
+ command "curl #{get_helm_url} | tar -zxv"
+ action :run
+ end
- bash 'install helm' do
- code <<-EOH
- curl #{download_url} | tar -xvz
- mv linux-#{arch}/helm #{binary_path}
- EOH
+ file_extract_path = "/tmp/linux-#{arch}/helm"
+
+ ruby_block "check helm exist in #{file_extract_path}" do
+ block do
+ if ::File.exist?(file_extract_path)
+ log 'helm has downloaded' do
+ level :info
+ end
+ else
+ log "Could not find helm at #{file_extract_path}!" do
+ level :error
+ end
+ raise
+ end
+ end
+ action :run
end
- package 'bash-completion'
+ directory new_resource.path do
+ mode 0755
+ action :create
+ notifies :write, "log[create #{new_resource.path} directory]", :immediately
+ not_if { Dir.exist?(new_resource.path) }
+ end
- # Delete helm autocomplete if existing
- execute 'delete helm autocomplete' do
+ log "create #{new_resource.path} directory" do
+ level :info
+ action :nothing
+ end
+
+ remote_file "move file to #{new_resource.path}" do
+ path binary_path
+ source "file://#{file_extract_path}"
+ mode '0755'
+ end
+
+ ruby_block "check helm exist in #{new_resource.path}" do
+ block do
+ if ::File.exist?(binary_path)
+ log "helm has installed at #{new_resource.path}!" do
+ level :info
+ end
+
+ file file_extract_path do
+ action :delete
+ only_if { ::File.exist?(file_extract_path) }
+ end
+ else
+ log "Could not find helm at #{new_resource.path}!" do
+ level :error
+ end
+ raise
+ end
+ end
action :run
- command 'rm -rf /etc/bash_completion.d/helm'
- user 'root'
- only_if 'test -f /etc/bash_completion.d/helm'
+ end
+
+ package 'bash-completion' do
+ action :install
+ notifies :write, 'log[install bash-completion]', :immediately
+ not_if { Dir.exist?('/etc/bash_completion.d') }
+ end
+
+ log 'install bash-completion' do
+ level :info
+ action :nothing
end
# Install helm autocomplete
- execute 'install helm autocomplete' do
- action :run
- command 'helm completion bash > /etc/bash_completion.d/helm'
- creates '/etc/bash_completion.d/helm'
+ execute 'install helm bash completion' do
user 'root'
+ command "helm completion bash > #{helm_completion_path}"
+ creates helm_completion_path
+ action :run
+ only_if { ::File.exist?(binary_path) }
+ end
+
+ ruby_block 'check helm autocompletion' do
+ block do
+ if ::File.exist?(helm_completion_path)
+ log 'helm autocomplete has installed' do
+ level :info
+ end
+ else
+ log 'helm autocomplete has not installed' do
+ level :error
+ end
+ end
+ end
+ action :run
+ end
+ else
+ log 'no need to install new helm version' do
+ level :info
end
end
end
action :remove do
- execute 'remove helm' do
- command "rm -rf #{binary_path}"
- only_if 'which helm'
+ remove_helm
+end
+
+action_class do
+ def arch
+ node['kubernetes-stack']['arch']
+ end
+
+ def sys
+ node['kubernetes-stack']['sys']
+ end
+
+ def binary_path
+ "#{new_resource.path}/helm"
+ end
+
+ def latest_ver
+ cmd = Mixlib::ShellOut.new("curl -s https://api.github.com/repos/kubernetes/helm/releases/latest | grep 'tag_name' | cut -d\\\" -f4")
+ cmd.run_command
+ cmd.error!
+
+ ver = cmd.stdout.strip
+ ver
+ end
+
+ def current_ver
+ cmd = Mixlib::ShellOut.new("helm version --short --client | cut -d ':' -f2 | sed 's/[[:space:]]//g' | sed 's/+.*//'")
+ cmd.run_command
+
+ ver = cmd.stderr.empty? && !cmd.stdout.empty? ? cmd.stdout.strip : nil
+ ver
+ end
+
+ def helm_completion_path
+ '/etc/bash_completion.d/helm'
+ end
+
+ def remove_helm
+ bash 'remove helm' do
+ user 'root'
+ code <<-EOH
+ helm_binary=$(which helm);
+ rm -rf $helm_binary
+ rm -rf #{helm_completion_path}
+ EOH
+ notifies :write, 'log[helm has deleted successfull]', :immediately
+ notifies :write, 'log[helm-autocompletion has deleted successfull]', :immediately
+ only_if 'which helm'
+ end
+
+ log 'helm has deleted successfull' do
+ level :info
+ action :nothing
+ end
+
+ log 'helm-autocompletion has deleted successfull' do
+ level :info
+ action :nothing
+ end
end
end
diff --git a/resources/kubectl.rb b/resources/kubectl.rb
index e6ae8a3..1e895f7 100644
--- a/resources/kubectl.rb
+++ b/resources/kubectl.rb
@@ -1,7 +1,8 @@
+# frozen_string_literal: true
resource_name :kubectl
property :version, String, default: ''
-property :binary_path, String, default: '/usr/local/bin/kubectl'
+property :path, String, default: '/usr/local/bin'
default_action :install
@@ -10,83 +11,164 @@
action :install do
version = new_resource.version
+ version = latest_ver if new_resource.version.empty?
- arch_cmd = Mixlib::ShellOut.new('uname -m')
- arch_cmd.run_command
- arch_cmd.error!
- arch = arch_cmd.stdout.strip
-
- case arch
- when 'x86', 'i686', 'i386'
- arch = '386'
- when 'x86_64', 'aarch64'
- arch = 'amd64'
- when 'armv5*'
- arch = 'armv5'
- when 'armv6*'
- arch = 'armv6'
- when 'armv7*'
- arch = 'armv7'
- else
- arch = 'default'
+ log "kubectl install version = '#{version}'" do
+ level :info
end
- if version.empty?
- latest_version_url = 'curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt'
- version_cmd = Mixlib::ShellOut.new(latest_version_url)
- version_cmd.run_command
- version_cmd.error!
- version = version_cmd.stdout.strip
+ current = current_ver
+
+ log "kubectl current version = '#{current}'" do
+ level :info
end
- # Command to check if we should be installing kubectl or not.
- existing_version_cmd = Mixlib::ShellOut.new("kubectl version --short --client | cut -d ':' -f2")
- existing_version_cmd.run_command
+ if current != version
- if existing_version_cmd.stderr.empty? && !existing_version_cmd.stdout.empty?
- existing_version = existing_version_cmd.stdout.strip
- end
+ remove_kubectl unless current.nil?
- if existing_version.to_s != version.to_s
- bash 'clean up the mismatched kubectl version' do
- code <<-EOH
- kubectl_binary=$(which kubectl);
- rm -rf $kubectl_binary
- EOH
- only_if 'which kubectl'
+ get_kubectl_url = "https://storage.googleapis.com/kubernetes-release/release/#{version}/bin/#{sys}/#{arch}/kubectl"
+
+ log "kubectl will be downloaded at #{get_kubectl_url}" do
+ level :info
end
- download_url = "https://storage.googleapis.com/kubernetes-release/release/#{version}/bin/linux/#{arch}/kubectl"
+ directory new_resource.path do
+ mode 0755
+ action :create
+ notifies :write, "log[create #{new_resource.path} directory]", :immediately
+ not_if { Dir.exist?(new_resource.path) }
+ end
- remote_file binary_path do
- source download_url
- mode '0755'
- not_if { ::File.exist?(binary_path) }
+ log "create #{new_resource.path} directory" do
+ level :info
+ action :nothing
end
- package 'bash-completion'
+ execute 'download kubectl' do
+ user 'root'
+ cwd new_resource.path
+ command "curl -Lo kubectl #{get_kubectl_url} && chmod +x kubectl"
+ action :run
+ not_if 'which kubectl'
+ end
- # Delete kubect autocomplete if existing
- execute 'delete kubectl autocomplete' do
+ ruby_block 'check kubectl' do
+ block do
+ if ::File.exist?(binary_path)
+ log "kubectl has installed at #{binary_path}!" do
+ level :info
+ end
+ else
+ log "Could not find kubectl at #{binary_path}!" do
+ level :error
+ end
+ raise
+ end
+ end
action :run
- command 'rm -rf /etc/bash_completion.d/kubectl'
- user 'root'
- only_if 'test -f /etc/bash_completion.d/kubectl'
+ end
+
+ package 'bash-completion' do
+ action :install
+ notifies :write, 'log[install bash-completion]', :immediately
+ not_if { Dir.exist?('/etc/bash_completion.d') }
+ end
+
+ log 'install bash-completion' do
+ level :info
+ action :nothing
end
# Install kubectl autocomplete
- execute 'install kubectl autocomplete' do
- action :run
- command 'kubectl completion bash > /etc/bash_completion.d/kubectl'
- creates '/etc/bash_completion.d/kubect'
+ execute 'install kubectl bash completion' do
+ command "kubectl completion bash > #{kubectl_completion_path}"
+ creates kubectl_completion_path
user 'root'
+ action :run
+ only_if 'which kubectl'
+ end
+
+ ruby_block 'check kubectl autocompletion' do
+ block do
+ if ::File.exist?(kubectl_completion_path)
+ log 'kubectl autocomplete has installed' do
+ level :info
+ end
+ else
+ log 'kubectl autocomplete has not installed' do
+ level :error
+ end
+ end
+ end
+ action :run
+ end
+ else
+ log 'no need to install new kubectl version' do
+ level :info
end
end
end
action :remove do
- execute 'remove kubectl' do
- command "rm -rf #{binary_path}"
- only_if 'which kubectl'
+ remove_kubectl
+end
+
+action_class do
+ def arch
+ node['kubernetes-stack']['arch']
+ end
+
+ def sys
+ node['kubernetes-stack']['sys']
+ end
+
+ def binary_path
+ "#{new_resource.path}/kubectl"
+ end
+
+ def kubectl_completion_path
+ '/etc/bash_completion.d/kubectl'
+ end
+
+ def latest_ver
+ cmd = Mixlib::ShellOut.new('curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt')
+ cmd.run_command
+ cmd.error!
+
+ ver = cmd.stdout.strip
+ ver
+ end
+
+ def current_ver
+ cmd = Mixlib::ShellOut.new("kubectl version --short --client | cut -d ':' -f2")
+ cmd.run_command
+
+ ver = cmd.stderr.empty? && !cmd.stdout.empty? ? cmd.stdout.strip : nil
+ ver
+ end
+
+ def remove_kubectl
+ bash 'remove kubectl' do
+ user 'root'
+ code <<-EOH
+ kubectl_binary=$(which kubectl);
+ rm -rf $kubectl_binary
+ rm -rf #{kubectl_completion_path}
+ EOH
+ notifies :write, 'log[kubectl has deleted successfull]', :immediately
+ notifies :write, 'log[kubectl-autocompletion has deleted successfull]', :immediately
+ only_if 'which kubectl'
+ end
+
+ log 'kubectl has deleted successfull' do
+ level :info
+ action :nothing
+ end
+
+ log 'kubectl-autocompletion has deleted successfull' do
+ level :info
+ action :nothing
+ end
end
end
diff --git a/resources/minikube.rb b/resources/minikube.rb
new file mode 100644
index 0000000..ef5e24b
--- /dev/null
+++ b/resources/minikube.rb
@@ -0,0 +1,266 @@
+# frozen_string_literal: true
+resource_name :minikube
+
+property :version, String, default: ''
+property :path, String, default: '/usr/local/bin'
+property :k8s_version, String, default: ''
+property :network_plugin, String, default: ''
+property :bootstrapper, String, default: ''
+property :vm_driver, String, default: 'none'
+
+default_action :install
+
+load_current_value do
+end
+
+action :install do
+ version = new_resource.version
+ version = latest_ver if new_resource.version.empty?
+
+ log "minikube install version = '#{version}'" do
+ level :info
+ end
+
+ current = current_ver
+
+ log "minikube current version : '#{current}'" do
+ level :info
+ end
+
+ if current != version
+
+ remove_minikube unless current.nil?
+
+ get_minikube_url = "https://storage.googleapis.com/minikube/releases/#{version}/minikube-#{sys}-#{arch}"
+
+ log "minikube will be downloaded at #{get_minikube_url}" do
+ level :info
+ end
+
+ directory new_resource.path do
+ mode 0755
+ action :create
+ notifies :write, "log[create #{new_resource.path} directory]", :immediately
+ not_if { Dir.exist?(new_resource.path) }
+ end
+
+ log "create #{new_resource.path} directory" do
+ level :info
+ action :nothing
+ end
+
+ execute 'get minikube' do
+ cwd new_resource.path
+ command "curl -Lo minikube #{get_minikube_url} && chmod +x minikube"
+ action :run
+ not_if 'which minikube'
+ end
+
+ ruby_block 'check minikube' do
+ block do
+ if ::File.exist?(binary_path)
+ log "minikube has installed at #{binary_path}!" do
+ level :info
+ end
+ else
+ log "Could not find minikube at #{binary_path}!" do
+ level :error
+ end
+ raise
+ end
+ end
+ action :run
+ end
+ else
+ log 'no need to install new minikube version' do
+ level :info
+ end
+ end
+end
+
+action :run do
+ user = node['kubernetes-stack']['user']
+
+ log "user : #{user}" do
+ level :info
+ end
+
+ user_home = node['kubernetes-stack']['home']
+
+ log "home dir : #{user_home}" do
+ level :info
+ end
+
+ user user do
+ comment 'create kubernetes-stack-cookbook user'
+ uid '1000'
+ home user_home
+ manage_home true
+ system true
+ not_if { user_exist?(user) }
+ end
+
+ ruby_block "check #{user} exist" do
+ block do
+ if user_exist?(user)
+ log "user_name: #{user} exist" do
+ level :info
+ end
+ else
+ log "user_name: #{user} has not exist" do
+ level :error
+ end
+ raise 'user not found'
+ end
+ end
+ action :run
+ end
+
+ unless sudo_installed?
+ package 'sudo' do
+ action :install
+ notifies :write, 'log[package sudo has been installed]', :immediately
+ end
+
+ log 'package sudo has been installed' do
+ level :info
+ action :nothing
+ end
+ end
+
+ execute 'set sudo command without passwd' do
+ user 'root'
+ command "echo '#{user} ALL=(ALL) NOPASSWD:SETENV:ALL' >> /etc/sudoers.d/#{user}_cmd"
+ only_if 'which sudo'
+ end
+
+ if docker_installed?
+ log 'docker has exist' do
+ level :info
+ end
+
+ group 'docker' do
+ action :modify
+ members user
+ append true
+ end
+ else
+ log 'docker has not exist' do
+ level :error
+ end
+ end
+
+ package 'ebtables'
+ package 'ethtool'
+
+ log "minikube start command: #{start_command}" do
+ level :info
+ end
+
+ bash 'run minikube' do
+ user user
+ environment(
+ 'USER' => user,
+ 'HOME' => user_home
+ )
+ code <<-EOF
+ export MINIKUBE_WANTUPDATENOTIFICATION=false
+ export MINIKUBE_WANTREPORTERRORPROMPT=fasle
+ export CHANGE_MINIKUBE_NONE_USER=true
+ export MINIKUBE_HOME=$HOME
+
+ mkdir -p $HOME/.kube || true
+ touch $HOME/.kube/config
+
+ export KUBECONFIG=$HOME/.kube/config
+
+ #{start_command}
+ EOF
+ end
+end
+
+action :remove do
+ remove_minikube
+end
+
+action_class do
+ include KubernetesStackCookbook::Helpers
+
+ def arch
+ node['kubernetes-stack']['arch']
+ end
+
+ def sys
+ node['kubernetes-stack']['sys']
+ end
+
+ def binary_path
+ "#{new_resource.path}/minikube"
+ end
+
+ def latest_ver
+ cmd = Mixlib::ShellOut.new("curl -s https://api.github.com/repos/kubernetes/minikube/releases/latest | grep 'tag_name' | cut -d\\\" -f4")
+ cmd.run_command
+ cmd.error!
+
+ ver = cmd.stdout.strip
+ ver
+ end
+
+ def current_ver
+ cmd = Mixlib::ShellOut.new("minikube version | cut -d ' ' -f3")
+ cmd.run_command
+
+ ver = cmd.stderr.empty? && !cmd.stdout.empty? ? cmd.stdout.strip : nil
+ ver
+ end
+
+ def start_command
+ cmd = "sudo -E #{binary_path} start"
+ cmd += " --vm-driver=#{new_resource.vm_driver}" unless new_resource.vm_driver.empty?
+ cmd += " --bootstrapper=#{new_resource.bootstrapper}" unless new_resource.bootstrapper.empty?
+ cmd += " --network-plugin=#{new_resource.network_plugin}" unless new_resource.network_plugin.empty?
+ cmd += " --kubernetes-version=#{new_resource.k8s_version}" unless new_resource.k8s_version.empty?
+ cmd
+ end
+
+ def remove_minikube
+ bash 'remove minikube' do
+ code <<-EOH
+ minikube delete
+ minikube_binary=$(which minikube);
+ rm -rf $minikube_binary
+ rm -rf $HOME/.minikube
+ EOH
+ notifies :write, 'log[minikube has deleted successfull]', :immediately
+ only_if 'which minikube'
+ end
+
+ log 'minikube has deleted successfull' do
+ level :info
+ action :nothing
+ end
+
+ service '*kubelet*.mount' do
+ notifies :write, 'log[kubelet has stopped]', :immediately
+ action :stop
+ end
+
+ log 'kubelet has stopped' do
+ level :info
+ action :nothing
+ end
+
+ execute 'remove k8s docker images' do
+ command 'docker rm -f $(docker ps -aq --filter name=k8s)'
+ notifies :write, 'log[k8s image has removed]', :immediately
+ action :run
+ only_if 'which docker'
+ end
+
+ log 'k8s image has removed' do
+ level :info
+ action :nothing
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e12bbd3..a7112cd 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require 'chefspec'
ChefSpec::Coverage.start!
diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb
index ef78bf8..055c2ba 100644
--- a/spec/unit/recipes/default_spec.rb
+++ b/spec/unit/recipes/default_spec.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack
# Spec:: default
diff --git a/spec/unit/resources/install_gcloud_spec.rb b/spec/unit/resources/install_gcloud_spec.rb
index 4b9dbf4..ab02308 100644
--- a/spec/unit/resources/install_gcloud_spec.rb
+++ b/spec/unit/resources/install_gcloud_spec.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack
# Spec:: kubectl
@@ -29,7 +30,7 @@
describe 'kubernetes-stack-test::install_gcloud_for_chefspec' do
context 'install on ubuntu 16.04' do
cached(:chef_run) do
- ChefSpec::ServerRunner.new(
+ ChefSpec::SoloRunner.new(
step_into: 'gcloud',
platform: 'ubuntu',
version: '16.04'
@@ -51,18 +52,14 @@
expect { chef_run }.to_not raise_error
end
- it 'install latest gcloud' do
- expect(chef_run).to install_gcloud('install latest gcloud')
- end
-
- it 'install specific gcloud version' do
- expect(chef_run).to install_gcloud('install specific gcloud version').with(version: '158.0.0')
+ it 'install gcloud' do
+ expect(chef_run).to install_gcloud('install gcloud').with(version: '197.0.0')
end
end
context 'Install on centos 7.3' do
cached(:chef_run) do
- ChefSpec::ServerRunner.new(
+ ChefSpec::SoloRunner.new(
step_into: 'gcloud',
platform: 'centos',
version: '7.3.1611'
@@ -84,12 +81,8 @@
expect { chef_run }.to_not raise_error
end
- it 'install latest gcloud' do
- expect(chef_run).to install_gcloud('install latest gcloud')
- end
-
- it 'install specific gcloud version' do
- expect(chef_run).to install_gcloud('install specific gcloud version').with(version: '158.0.0')
+ it 'install gcloud' do
+ expect(chef_run).to install_gcloud('install gcloud').with(version: '197.0.0')
end
end
end
diff --git a/spec/unit/resources/install_helm_spec.rb b/spec/unit/resources/install_helm_spec.rb
index ca4c8c1..23fb69f 100644
--- a/spec/unit/resources/install_helm_spec.rb
+++ b/spec/unit/resources/install_helm_spec.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack
# Spec:: helm
@@ -29,7 +30,7 @@
describe 'kubernetes-stack-test::install_helm_for_chefspec' do
context 'Install on ubuntu 16.04' do
cached(:chef_run) do
- ChefSpec::ServerRunner.new(
+ ChefSpec::SoloRunner.new(
step_into: 'helm',
platform: 'ubuntu',
version: '16.04'
@@ -45,18 +46,14 @@
expect { chef_run }.to_not raise_error
end
- it 'install latest helm' do
- expect(chef_run).to install_helm('install latest helm')
- end
-
- it 'install specific helm version' do
- expect(chef_run).to install_helm('install specific helm version').with(version: 'v2.4.2')
+ it 'install helm' do
+ expect(chef_run).to install_helm('install helm').with(version: 'v2.4.2')
end
end
context 'Install on centos 7.3' do
cached(:chef_run) do
- ChefSpec::ServerRunner.new(
+ ChefSpec::SoloRunner.new(
step_into: 'helm',
platform: 'centos',
version: '7.3.1611'
@@ -72,12 +69,8 @@
expect { chef_run }.to_not raise_error
end
- it 'install latest helm' do
- expect(chef_run).to install_helm('install latest helm')
- end
-
- it 'install specific helm version' do
- expect(chef_run).to install_helm('install specific helm version').with(version: 'v2.4.2')
+ it 'install helm' do
+ expect(chef_run).to install_helm('install helm').with(version: 'v2.4.2')
end
end
end
diff --git a/spec/unit/resources/install_kubectl_spec.rb b/spec/unit/resources/install_kubectl_spec.rb
index 04921d4..0ffea5f 100644
--- a/spec/unit/resources/install_kubectl_spec.rb
+++ b/spec/unit/resources/install_kubectl_spec.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack
# Spec:: kubectl
@@ -29,7 +30,7 @@
describe 'kubernetes-stack-test::install_kubectl_for_chefspec' do
context 'Install on ubuntu 16.04' do
cached(:chef_run) do
- ChefSpec::ServerRunner.new(
+ ChefSpec::SoloRunner.new(
step_into: 'kubectl',
platform: 'ubuntu',
version: '16.04'
@@ -45,18 +46,14 @@
expect { chef_run }.to_not raise_error
end
- it 'install latest kubectl' do
- expect(chef_run).to install_kubectl('install latest kubectl')
- end
-
- it 'install specific kubectl version' do
- expect(chef_run).to install_kubectl('install specific kubectl version').with(version: 'v1.7.0')
+ it 'install kubectl' do
+ expect(chef_run).to install_kubectl('install kubectl').with(version: 'v1.9.1')
end
end
context 'Install on centos 7.3' do
cached(:chef_run) do
- ChefSpec::ServerRunner.new(
+ ChefSpec::SoloRunner.new(
step_into: 'kubectl',
platform: 'centos',
version: '7.3.1611'
@@ -72,12 +69,8 @@
expect { chef_run }.to_not raise_error
end
- it 'install latest kubectl' do
- expect(chef_run).to install_kubectl('install latest kubectl')
- end
-
- it 'install specific kubectl version' do
- expect(chef_run).to install_kubectl('install specific kubectl version').with(version: 'v1.7.0')
+ it 'install kubectl' do
+ expect(chef_run).to install_kubectl('install kubectl').with(version: 'v1.9.1')
end
end
end
diff --git a/spec/unit/resources/install_minikube_spec.rb b/spec/unit/resources/install_minikube_spec.rb
new file mode 100644
index 0000000..e090782
--- /dev/null
+++ b/spec/unit/resources/install_minikube_spec.rb
@@ -0,0 +1,82 @@
+# frozen_string_literal: true
+#
+# Cookbook:: kubernetes-stack
+# Spec:: minikube
+#
+# The MIT License (MIT)
+#
+# Copyright:: 2017, Teracy Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+require 'spec_helper'
+
+describe 'kubernetes-stack-test::install_minikube_for_chefspec' do
+ context 'Install on ubuntu 16.04' do
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(
+ step_into: 'minikube',
+ platform: 'ubuntu',
+ version: '16.04'
+ ).converge(described_recipe)
+ end
+
+ before do
+ stub_command('which kubectl').and_return('/usr/local/bin/kubectl')
+ stub_command('which minikube').and_return('/usr/local/bin/minikube')
+ stub_command('which docker').and_return('/usr/bin/docker')
+ stub_command('which sudo').and_return('/usr/bin/sudo')
+ stub_command('grep vagrant /etc/passwd').and_return(true)
+ end
+
+ it 'converges successfully' do
+ expect { chef_run }.to_not raise_error
+ end
+
+ it 'install minikube' do
+ expect(chef_run).to install_minikube('install minikube')
+ end
+ end
+
+ context 'Install on centos 7' do
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(
+ step_into: 'minikube',
+ platform: 'centos',
+ version: '7.3.1611'
+ ).converge(described_recipe)
+ end
+
+ before do
+ stub_command('which kubectl').and_return('/usr/local/bin/kubectl')
+ stub_command('which minikube').and_return('/usr/local/bin/minikube')
+ stub_command('which docker').and_return('/usr/bin/docker')
+ stub_command('which sudo').and_return('/usr/bin/sudo')
+ stub_command('grep vagrant /etc/passwd').and_return(true)
+ end
+
+ it 'converges successfully' do
+ expect { chef_run }.to_not raise_error
+ end
+
+ it 'install minikube' do
+ expect(chef_run).to install_minikube('install minikube')
+ end
+ end
+end
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/metadata.rb b/test/fixtures/cookbooks/kubernetes-stack-test/metadata.rb
index 2027b0d..085c7ee 100644
--- a/test/fixtures/cookbooks/kubernetes-stack-test/metadata.rb
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/metadata.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
name 'kubernetes-stack-test'
maintainer 'The Authors'
maintainer_email 'you@example.com'
@@ -20,3 +21,4 @@
# source_url 'https://github.com//kubernetes-stack-test'
depends 'kubernetes-stack'
+depends 'docker'
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/default.rb b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/default.rb
index c2708c4..a1cfab3 100644
--- a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/default.rb
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/default.rb
@@ -1,5 +1,8 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack-test
# Recipe:: default
#
# Copyright:: 2017, The Authors, All Rights Reserved.
+
+include_recipe 'kubernetes-stack-test::docker'
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/docker.rb b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/docker.rb
new file mode 100644
index 0000000..64107fd
--- /dev/null
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/docker.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+#
+# Cookbook:: kubernetes-stack-test
+# Recipe:: docker
+#
+# Copyright:: 2017, The Authors, All Rights Reserved.
+
+unless docker_installed?
+ docker_service 'default' do
+ action [:create, :start]
+ end
+
+ def install_url
+ release = node['docker_machine']['release']
+ kernel_name = node['kernel']['name']
+ machine_hw_name = node['kernel']['machine']
+ "https://github.com/docker/machine/releases/download/#{release}/docker-machine-#{kernel_name}-#{machine_hw_name}"
+ end
+
+ command_path = node['docker_machine']['command_path']
+ url = install_url
+
+ execute 'install docker-machine' do
+ action :run
+ command "curl -sSL #{url} > #{command_path} && chmod +x #{command_path}"
+ creates command_path
+ user 'root'
+ group 'docker'
+ umask '0027'
+ end
+end
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install.rb b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install.rb
index b481b35..fdfa9e5 100644
--- a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install.rb
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack-test
# Recipe:: install
@@ -6,6 +7,8 @@
kubectl_opt = node['kubernetes-stack']['kubectl']
+minikube_opt = node['kubernetes-stack']['minikube']
+
gcloud_opt = node['kubernetes-stack']['gcloud']
helm_opt = node['kubernetes-stack']['helm']
@@ -30,3 +33,14 @@
action :install
end
end
+
+if minikube_opt['enabled']
+ minikube "install minikube #{minikube_opt['version']}" do
+ version minikube_opt['version']
+ k8s_version minikube_opt['k8s_version']
+ network_plugin minikube_opt['network_plugin']
+ bootstrapper minikube_opt['bootstrapper']
+ vm_driver minikube_opt['vm_driver']
+ action [:install, :run]
+ end
+end
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_gcloud_for_chefspec.rb b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_gcloud_for_chefspec.rb
index 06e56f3..e5104c1 100644
--- a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_gcloud_for_chefspec.rb
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_gcloud_for_chefspec.rb
@@ -1,8 +1,7 @@
+# frozen_string_literal: true
# This recipe is used for running the `install_gcloud_for_chefspec` tests, it should
# not be used in the other recipes.
-gcloud 'install latest gcloud'
-
-gcloud 'install specific gcloud version' do
- version '158.0.0'
+gcloud 'install gcloud' do
+ version '197.0.0'
end
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_helm_for_chefspec.rb b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_helm_for_chefspec.rb
index 5d947f8..ff167e5 100644
--- a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_helm_for_chefspec.rb
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_helm_for_chefspec.rb
@@ -1,8 +1,7 @@
+# frozen_string_literal: true
# This recipe is used for running the `install_helm_for_chefspec` tests, it should
# not be used in the other recipes.
-helm 'install latest helm'
-
-helm 'install specific helm version' do
+helm 'install helm' do
version 'v2.4.2'
end
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_kubectl_for_chefspec.rb b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_kubectl_for_chefspec.rb
index f2739a6..a972f94 100644
--- a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_kubectl_for_chefspec.rb
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_kubectl_for_chefspec.rb
@@ -1,8 +1,7 @@
+# frozen_string_literal: true
# This recipe is used for running the `install_kubectl_for_chefspec` tests, it should
# not be used in the other recipes.
-kubectl 'install latest kubectl'
-
-kubectl 'install specific kubectl version' do
- version 'v1.7.0'
+kubectl 'install kubectl' do
+ version 'v1.9.1'
end
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_minikube_for_chefspec.rb b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_minikube_for_chefspec.rb
new file mode 100644
index 0000000..3adb2c1
--- /dev/null
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/install_minikube_for_chefspec.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+# This recipe is used for running the `install_kubernetes_for_chefspec` tests, it should
+# not be used in the other recipes.
+
+minikube 'install minikube' do
+ version 'v0.25.2'
+end
diff --git a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/uninstall.rb b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/uninstall.rb
index db30814..e1dcaf6 100644
--- a/test/fixtures/cookbooks/kubernetes-stack-test/recipes/uninstall.rb
+++ b/test/fixtures/cookbooks/kubernetes-stack-test/recipes/uninstall.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# Cookbook:: kubernetes-stack-test
# Recipe:: uninstall
@@ -6,14 +7,18 @@
include_recipe 'kubernetes-stack-test::install'
-gcloud 'uninstall gcloud' do
+kubectl 'uninstall kubectl' do
action :remove
end
-kubectl 'uninstall kubectl' do
+gcloud 'uninstall gcloud' do
action :remove
end
helm 'uninstall helm' do
action :remove
end
+
+minikube 'uninstall minikube' do
+ action :remove
+end
diff --git a/test/smoke/default/default_test.rb b/test/smoke/default/default_test.rb
index cde023f..48721e9 100644
--- a/test/smoke/default/default_test.rb
+++ b/test/smoke/default/default_test.rb
@@ -1,4 +1,5 @@
-# # encoding: utf-8
+# frozen_string_literal: true
+# encoding: utf-8
# Inspec test for recipe kubernetes-stack::default
diff --git a/test/smoke/gcloud/gcloud_install_specific_version_test.rb b/test/smoke/gcloud/gcloud_install_specific_version_test.rb
deleted file mode 100644
index 8272d7c..0000000
--- a/test/smoke/gcloud/gcloud_install_specific_version_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# # encoding: utf-8
-
-# Inspec test for recipe kubernetes-stack::gcloud
-
-# The Inspec reference, with examples and extensive document
-
-describe command("gcloud version | head -1 | grep -o -E '[0-9].*'") do
- its(:exit_status) { should eq 0 }
- its(:stdout) { should match('158.0.0') }
-end
diff --git a/test/smoke/gcloud/gcloud_install_default_test.rb b/test/smoke/gcloud/gcloud_install_test.rb
similarity index 93%
rename from test/smoke/gcloud/gcloud_install_default_test.rb
rename to test/smoke/gcloud/gcloud_install_test.rb
index a670dbf..afd7e14 100644
--- a/test/smoke/gcloud/gcloud_install_default_test.rb
+++ b/test/smoke/gcloud/gcloud_install_test.rb
@@ -1,4 +1,5 @@
-# # encoding: utf-8
+# frozen_string_literal: true
+# encoding: utf-8
# Inspec test for recipe kubernetes-stack::gcloud
diff --git a/test/smoke/gcloud/gcloud_uninstall_test.rb b/test/smoke/gcloud/gcloud_uninstall_test.rb
index b9f6e7e..e57e4f1 100644
--- a/test/smoke/gcloud/gcloud_uninstall_test.rb
+++ b/test/smoke/gcloud/gcloud_uninstall_test.rb
@@ -1,4 +1,5 @@
-# # encoding: utf-8
+# frozen_string_literal: true
+# encoding: utf-8
# Inspec test for recipe kubernetes-stack::gcloud
diff --git a/test/smoke/helm/helm_install_specific_version_test.rb b/test/smoke/helm/helm_install_specific_version_test.rb
deleted file mode 100644
index daa790f..0000000
--- a/test/smoke/helm/helm_install_specific_version_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# # encoding: utf-8
-
-# Inspec test for recipe kubernetes-stack::helm
-
-# The Inspec reference, with examples and extensive document
-
-describe command("helm version --short --client | cut -d ':' -f2 | sed 's/[[:space:]]//g' | sed 's/+.*//'") do
- its(:exit_status) { should eq 0 }
- its(:stdout) { should match('v2.4.2') }
-end
diff --git a/test/smoke/helm/helm_install_default_test.rb b/test/smoke/helm/helm_install_test.rb
similarity index 93%
rename from test/smoke/helm/helm_install_default_test.rb
rename to test/smoke/helm/helm_install_test.rb
index 2d17d94..4a900ca 100644
--- a/test/smoke/helm/helm_install_default_test.rb
+++ b/test/smoke/helm/helm_install_test.rb
@@ -1,4 +1,5 @@
-# # encoding: utf-8
+# frozen_string_literal: true
+# encoding: utf-8
# Inspec test for recipe kubernetes-stack::helm
diff --git a/test/smoke/helm/helm_uninstall_test.rb b/test/smoke/helm/helm_uninstall_test.rb
index 9959219..b67618f 100644
--- a/test/smoke/helm/helm_uninstall_test.rb
+++ b/test/smoke/helm/helm_uninstall_test.rb
@@ -1,4 +1,5 @@
-# # encoding: utf-8
+# frozen_string_literal: true
+# encoding: utf-8
# Inspec test for recipe kubernetes-stack::helm
diff --git a/test/smoke/kubectl/kubectl_install_specific_version_test.rb b/test/smoke/kubectl/kubectl_install_specific_version_test.rb
deleted file mode 100644
index 7f4d510..0000000
--- a/test/smoke/kubectl/kubectl_install_specific_version_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# # encoding: utf-8
-
-# Inspec test for recipe kubernetes-stack::kubectl
-
-# The Inspec reference, with examples and extensive document
-
-describe command("kubectl version --short --client | cut -d ':' -f2") do
- its(:exit_status) { should eq 0 }
- its(:stdout) { should match('v1.7.0') }
-end
diff --git a/test/smoke/kubectl/kubectl_install_default_test.rb b/test/smoke/kubectl/kubectl_install_test.rb
similarity index 92%
rename from test/smoke/kubectl/kubectl_install_default_test.rb
rename to test/smoke/kubectl/kubectl_install_test.rb
index 36eb3e1..f01a515 100644
--- a/test/smoke/kubectl/kubectl_install_default_test.rb
+++ b/test/smoke/kubectl/kubectl_install_test.rb
@@ -1,4 +1,5 @@
-# # encoding: utf-8
+# frozen_string_literal: true
+# encoding: utf-8
# Inspec test for recipe kubernetes-stack::kubectl
diff --git a/test/smoke/kubectl/kubectl_uninstall_test.rb b/test/smoke/kubectl/kubectl_uninstall_test.rb
index d1a282c..f58533c 100644
--- a/test/smoke/kubectl/kubectl_uninstall_test.rb
+++ b/test/smoke/kubectl/kubectl_uninstall_test.rb
@@ -1,4 +1,5 @@
-# # encoding: utf-8
+# frozen_string_literal: true
+# encoding: utf-8
# Inspec test for recipe kubernetes-stack::kubectl
diff --git a/test/smoke/minikube/minikube_install_test.rb b/test/smoke/minikube/minikube_install_test.rb
new file mode 100644
index 0000000..933e05e
--- /dev/null
+++ b/test/smoke/minikube/minikube_install_test.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+# encoding: utf-8
+
+# Inspec test for recipe kubernetes-stack::minikube
+
+# The Inspec reference, with examples and extensive document
+
+describe command('curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt') do
+ its(:exit_status) { should eq 0 }
+ its('stdout') { should match /^\s*v[0-9]+.[0-9]+.[0-9]+?$/ }
+end
+
+describe command('which minikube') do
+ its(:exit_status) { should eq 0 }
+ its(:stdout) { should match('/usr/local/bin/minikube') }
+end
+
+describe command("minikube version | cut -d ' ' -f3") do
+ its(:exit_status) { should eq 0 }
+end
+
+describe command('minikube').exist? do
+ it { should eq true }
+end
+
+describe command("kubectl version --short --client | cut -d ':' -f2") do
+ its(:exit_status) { should eq 0 }
+ its('stdout') { should match /^\s*v[0-9]+.[0-9]+.[0-9]+?$/ }
+end
+
+describe command('kubectl').exist? do
+ it { should eq true }
+end
+
+describe command('which docker') do
+ its(:exit_status) { should eq 0 }
+ its(:stdout) { should match('/usr/bin/docker') }
+end
+
+describe command('grep vagrant /etc/passwd') do
+ its(:exit_status) { should eq 0 }
+end
+
+describe file('/home/vagrant/.kube/config') do
+ it { should exist }
+end
+
+describe command('which kubeadm') do
+ its(:exit_status) { should eq 0 }
+ its(:stdout) { should match('/usr/bin/kubeadm') }
+end
+
+describe command('which kubelet') do
+ its(:exit_status) { should eq 0 }
+ its(:stdout) { should match('/usr/bin/kubelet') }
+end
diff --git a/test/smoke/minikube/minikube_uninstall_test.rb b/test/smoke/minikube/minikube_uninstall_test.rb
new file mode 100644
index 0000000..f0d6ec6
--- /dev/null
+++ b/test/smoke/minikube/minikube_uninstall_test.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+# encoding: utf-8
+
+# Inspec test for recipe kubernetes-stack::minikube
+
+# The Inspec reference, with examples and extensive document
+
+describe command('which minikube') do
+ its(:exit_status) { should eq 1 }
+end