Skip to content

Commit

Permalink
Bump go to 1.21.5 and update deps (#178)
Browse files Browse the repository at this point in the history
* gitignore: Ignore kubitect binary

* go: Bump to 1.21.5 and update deps

* pkg/cluster/provisioner: Update tf tests and remove ioutils

* pkg/utils/validation: Fix CIDRv4 validator

* github/workflows: Bump go version to 1.21
  • Loading branch information
MusicDin committed Mar 9, 2024
1 parent ad7ca28 commit 8bcc6b1
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 505 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
types:
- published

env:
go-version: 1.18

jobs:
releases-matrix:
name: Release Go Binaries
Expand All @@ -26,6 +23,8 @@ jobs:
exclude:
- goarch: "386"
goos: darwin
env:
go-version: 1.21
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- ubuntu-latest
- macos-latest
go:
- 1.18
- 1.21
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ versions.tf.save

## Generated by script (downloaded or created)
/.kubitect/
/kubitect
/ansible/collections/
/ansible/kubespray/
/venv/
Expand Down
52 changes: 26 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
module github.com/MusicDin/kubitect

go 1.18
go 1.21.5

require (
github.com/apenella/go-ansible v1.1.7
github.com/apenella/go-ansible v1.3.0
github.com/creasty/defaults v1.7.0
github.com/go-git/go-git/v5 v5.7.0
github.com/go-playground/validator/v10 v10.14.1
github.com/hashicorp/hc-install v0.5.2
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
golang.org/x/term v0.8.0
github.com/go-git/go-git/v5 v5.11.0
github.com/go-playground/validator/v10 v10.19.0
github.com/hashicorp/hc-install v0.6.3
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
golang.org/x/term v0.18.0
gopkg.in/yaml.v3 v3.0.1
)

require gopkg.in/yaml.v2 v2.4.0 // indirect

require (
github.com/cloudflare/circl v1.3.3 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.9.3 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230528122434-6f98819771a1 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.1-proton // indirect
github.com/apenella/go-common-utils/data v0.0.0-20221227202648-5452d804e940 // indirect
github.com/apenella/go-common-utils/error v0.0.0-20221227202648-5452d804e940 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.15.0
github.com/fatih/color v1.16.0
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/hashicorp/go-version v1.6.0
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.9.0
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/crypto v0.21.0
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
533 changes: 70 additions & 463 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/cluster/provisioner/terraform/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (t MainTemplate) Write() error {

// defaultHost returns default host from a given list of hosts.
func defaultHost(hosts []config.Host) (config.Host, error) {
if hosts == nil || len(hosts) == 0 {
if len(hosts) == 0 {
return config.Host{}, fmt.Errorf("defaultHost: hosts list is empty")
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/cluster/provisioner/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ func installTerraform(ver, binDir string) (string, error) {
return "", err
}

fmt.Printf("==> Installing Terraform %v\n", ver)
fmt.Printf("==> Installing Terraform %v\n", version.Must(version.NewVersion(ver)))

installer := &releases.ExactVersion{
Product: product.Terraform,
Version: version.Must(version.NewVersion(ver)),
Expand Down
19 changes: 9 additions & 10 deletions pkg/cluster/provisioner/terraform/terraform_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package terraform

import (
"io/ioutil"
"os"
"path"
"reflect"
Expand Down Expand Up @@ -29,7 +28,7 @@ func MockTerraform(t *testing.T) *terraform {
// Create sample terraform main.tf file
maintf := "output \"test\" { value = \"test\" }"
maintfPath := path.Join(projDir, "main.tf")
err := ioutil.WriteFile(maintfPath, []byte(maintf), 0777)
err := os.WriteFile(maintfPath, []byte(maintf), 0777)
require.NoError(t, err)

return &terraform{
Expand All @@ -41,7 +40,7 @@ func MockTerraform(t *testing.T) *terraform {

func MockMissingTerraform(t *testing.T) *terraform {
tf := MockTerraform(t)
tf.version = "1.0.0"
tf.version = env.ConstTerraformVersion
return tf
}

Expand Down Expand Up @@ -92,19 +91,19 @@ func TestTerraform_init(t *testing.T) {
tf := MockMissingTerraform(t)
tfPath := path.Join(tf.binDir, "terraform")

assert.NoError(t, tf.init())
assert.Equal(t, tfPath, tf.binPath)
assert.Equal(t, true, tf.initialized)
require.NoError(t, tf.init())
require.Equal(t, tfPath, tf.binPath)
require.Equal(t, true, tf.initialized)

// tf.init() should quit immediately if initialized == true
assert.NoError(t, tf.init())
require.NoError(t, tf.init())

// Set initialized to false to call findAndInstall again.
// Since tf is already installed, tf must be found locally
tf.initialized = false
assert.NoError(t, tf.init())
assert.Equal(t, tfPath, tf.binPath)
assert.Equal(t, true, tf.initialized)
require.NoError(t, tf.init())
require.Equal(t, tfPath, tf.binPath)
require.Equal(t, true, tf.initialized)
}

func TestTerraform_init_InvalidBinDir(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/utils/validation/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func initialize() {
validate.RegisterValidation("extra_vsemver", extra_VSemVer)
validate.RegisterValidation("extra_semverinrange", extra_SemVersionInRange)
validate.RegisterValidation("extra_ipinrange", extra_IPInRange)
validate.RegisterValidation("extra_cidrv4", extra_CIDRv4)
validate.RegisterValidation("extra_uniquefield", extra_UniqueField)
validate.RegisterValidation("extra_regexany", extra_RegexAny)
validate.RegisterValidation("extra_regexall", extra_RegexAll)
Expand Down Expand Up @@ -276,7 +277,7 @@ func CIDR() Validator {
// CIDRv4 checks whether the field value is a valid v4 CIDR address.
func CIDRv4() Validator {
return Validator{
Tags: "cidrv4",
Tags: "extra_cidrv4",
Err: "Field '{.Field}' must be a valid CIDRv4 address (actual: {.Value}).",
}
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/utils/validation/validators_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ func extra_IPInRange(fl validator.FieldLevel) bool {
return subnet.Contains(ip)
}

// extra_CIDRv4 returns true if struct filed is a valid v4 CIDR address.
// Note: Required since breaking change in go-playground/validation@10.15.5
func extra_CIDRv4(fl validator.FieldLevel) bool {
ip, _, err := net.ParseCIDR(fl.Field().String())
return err == nil && ip.To4() != nil
}

// extra_UniqueField returns true if struct field with a given name is unique for
// all slice elements.
func extra_UniqueField(fl validator.FieldLevel) bool {
Expand Down

0 comments on commit 8bcc6b1

Please sign in to comment.