-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use rancher/k3s images for k3s preset
* Use upstream docker.io/rancher/k3s images for k3s preset * JSON encode kubeconfig-httpd manifest in init and panic on error * Add WithPort back and new WithDynamicPort * Complete backwards compatibility with support and test against k3s v1.16.x-v1.26.x * only formal support for Kubernetes actively maintained versions
- Loading branch information
Showing
9 changed files
with
338 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,60 @@ | ||
package k3s | ||
|
||
import ( | ||
"strings" | ||
|
||
"golang.org/x/mod/semver" | ||
) | ||
|
||
// Option is an optional configuration of this Gnomock preset. Use available | ||
// Options to configure the container. | ||
type Option func(*P) | ||
|
||
// WithVersion sets image version. | ||
func WithVersion(version string) Option { | ||
return func(o *P) { | ||
// support original orlangure/k3s versions with rancher/k3s by | ||
// appending '-k3s1' to them. | ||
if version != "latest" { | ||
if !strings.Contains(version, "k3s") { | ||
version += "-k3s1" | ||
} | ||
|
||
if semver.Compare(version, "v1.17.0") > 0 { | ||
// --disable flag only exists in k3s versions above v1.17.0. | ||
o.K3sServerFlags = append(o.K3sServerFlags, "--disable=traefik") | ||
} | ||
} | ||
|
||
o.Version = version | ||
} | ||
} | ||
|
||
// WithPort allows to use a custom port for k3s API access instead of the | ||
// default one. If no custom port is provided, port 48443 is used instead. | ||
// Deprecated: WithPort allows to use a custom port for k3s API access instead | ||
// of the default one. If no custom port is provided, port 48443 is used | ||
// instead. | ||
// | ||
// Please make sure that whichever port you choose to use (including the | ||
// default) is available on the host system. Otherwise this container won't | ||
// start. | ||
// | ||
// This option and its affects has been kept as is for backward compatibility. | ||
// We recommend using `WithDynamicPort()` instead as it does not require a | ||
// static port to be available on the host. | ||
func WithPort(port int) Option { | ||
return func(o *P) { | ||
o.Port = port | ||
} | ||
} | ||
|
||
// WithDynamicPort configures the preset to find and use a dynamic (free) port | ||
// for k3s API access from the host. The kubeconfig is replaced with the | ||
// container host port so local Kubernetes clients will still work. | ||
// | ||
// This is preferred to `WithPort` as it does not require a specific host port | ||
// to be available. | ||
func WithDynamicPort() Option { | ||
return func(o *P) { | ||
o.UseDynamicPort = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package k3s_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/orlangure/gnomock/preset/k3s" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestWithVersion(t *testing.T) { | ||
tests := []struct { | ||
inVersion string | ||
expectedSetVersion string | ||
}{ | ||
{"v1.17.11", "v1.17.11-k3s1"}, | ||
{"v1.17.12", "v1.17.12-k3s1"}, | ||
{"v1.17.13", "v1.17.13-k3s1"}, | ||
{"v1.17.2", "v1.17.2-k3s1"}, | ||
{"v1.17.3", "v1.17.3-k3s1"}, | ||
{"v1.17.4", "v1.17.4-k3s1"}, | ||
{"v1.17.5", "v1.17.5-k3s1"}, | ||
{"v1.17.6", "v1.17.6-k3s1"}, | ||
{"v1.17.7", "v1.17.7-k3s1"}, | ||
{"v1.17.9", "v1.17.9-k3s1"}, | ||
{"v1.18.10", "v1.18.10-k3s1"}, | ||
{"v1.18.2", "v1.18.2-k3s1"}, | ||
{"v1.18.3", "v1.18.3-k3s1"}, | ||
{"v1.18.4", "v1.18.4-k3s1"}, | ||
{"v1.18.6", "v1.18.6-k3s1"}, | ||
{"v1.18.8", "v1.18.8-k3s1"}, | ||
{"v1.18.9", "v1.18.9-k3s1"}, | ||
{"v1.19.1", "v1.19.1-k3s1"}, | ||
{"v1.19.10", "v1.19.10-k3s1"}, | ||
{"v1.19.11", "v1.19.11-k3s1"}, | ||
{"v1.19.12", "v1.19.12-k3s1"}, | ||
{"v1.19.2", "v1.19.2-k3s1"}, | ||
{"v1.19.3", "v1.19.3-k3s1"}, | ||
{"v1.19.4", "v1.19.4-k3s1"}, | ||
{"v1.19.5", "v1.19.5-k3s1"}, | ||
{"v1.19.7", "v1.19.7-k3s1"}, | ||
{"v1.19.8", "v1.19.8-k3s1"}, | ||
{"v1.19.9", "v1.19.9-k3s1"}, | ||
{"v1.20.2", "v1.20.2-k3s1"}, | ||
{"v1.20.4", "v1.20.4-k3s1"}, | ||
{"v1.20.5", "v1.20.5-k3s1"}, | ||
{"v1.20.6", "v1.20.6-k3s1"}, | ||
{"v1.20.7", "v1.20.7-k3s1"}, | ||
{"v1.20.8", "v1.20.8-k3s1"}, | ||
{"v1.21.0", "v1.21.0-k3s1"}, | ||
{"v1.21.1", "v1.21.1-k3s1"}, | ||
{"v1.21.2", "v1.21.2-k3s1"}, | ||
{"latest", "latest"}, | ||
{"v1.25.8-k3s1-amd64", "v1.25.8-k3s1-amd64"}, | ||
{"v1.26.3-k3s1-arm64", "v1.26.3-k3s1-arm64"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.inVersion, func(t *testing.T) { | ||
p := k3s.Preset(k3s.WithVersion(tt.inVersion)) | ||
|
||
assert.IsType(t, &k3s.P{}, p) | ||
if k3sp, ok := p.(*k3s.P); ok { | ||
assert.Equal(t, tt.expectedSetVersion, k3sp.Version) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.