mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-21 08:20:21 +02:00
Fix Integration tests (#2425)
* fix(ci): Bump golangci-lint to 1.51.1 * chore(lint): fix gofmt and goimport issues * chore(lint): fix linter issues - Adapted error comparison according to linter recommendation - Disabled noctx linting for http request where canceling makes no sense - Disabled nilerror linting where nil error is returned on purpose - Disabled makezero linter where slice is explicitly deepcopied * chore(ci): Update go version in tests workflows * fix(ci): Allow boilerplate years from 2000-2099 Previously the regex only allowed the copyright notice to contain the years 2018,2019,2020,2021, or 2022. This commit widens to regex to 20\d\d allowing any year in the range [2000-2099] * feat(ci): Replace minikube with k3s for intregration tests The existing setup for minikube is very complicated, replicating most of the setup steps for a full kubernetes cluster in an only partially supported minikube configuration (driver=none). Furthermore the existing setup has been broken for sometime, likely, at least in part due to the changes to CNI and CRI in recent kubernetes versions. Since what we actually need is only a running Kubernetes cluster on the node and access to a registry on localhost:5000, we can switch the extremely complicated minikube setup for a lightweight cluster using k3s. Minikube came with a default addon for running a registry on every node, but the same is not the case for k3s, instead we make use of the package helm controller and its HelmChart CR to deploy twuni/docker-registry.helm and expose it on localhost using the integrated LoadBalancer controller. * fix(test-684): pin base container version The dockerfile for the regression test connected to issue 684 used a rolling tag as base image, making it flaky and fail since it was introduced. This commit pins the base image to the digest of bionic-20200219, which, based on the date of the commit that introduced to the dockerfile would be the most newest ubuntu build and likely what the "rolling" tag resolved to back then. Since this also an image from the pre-oci days of ubuntu, this circumvents a bug in container-diff as well (https://github.com/GoogleContainerTools/container-diff/issues/389)
This commit is contained in:
@@ -49,7 +49,7 @@ func (h *HTTPSTar) UnpackTarFromBuildContext() (directory string, err error) {
|
||||
|
||||
// Download tar file from remote https server
|
||||
// and save it into the target tar file
|
||||
resp, err := http.Get(h.context)
|
||||
resp, err := http.Get(h.context) //nolint:noctx
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Vendored
+10
-20
@@ -16,15 +16,13 @@ limitations under the License.
|
||||
|
||||
package cache
|
||||
|
||||
import "errors"
|
||||
|
||||
// IsAlreadyCached returns true if the supplied error is of the type AlreadyCachedErr
|
||||
// otherwise it returns false.
|
||||
func IsAlreadyCached(err error) bool {
|
||||
switch err.(type) {
|
||||
case AlreadyCachedErr:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
var e AlreadyCachedErr
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// AlreadyCachedErr is returned when the Docker image requested for caching is already
|
||||
@@ -39,13 +37,9 @@ func (a AlreadyCachedErr) Error() string {
|
||||
|
||||
// IsNotFound returns true if the supplied error is of the type NotFoundErr
|
||||
// otherwise it returns false.
|
||||
func IsNotFound(e error) bool {
|
||||
switch e.(type) {
|
||||
case NotFoundErr:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
func IsNotFound(err error) bool {
|
||||
var e NotFoundErr
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotFoundErr is returned when the requested Docker image is not present in the cache.
|
||||
@@ -59,13 +53,9 @@ func (e NotFoundErr) Error() string {
|
||||
|
||||
// IsExpired returns true if the supplied error is of the type ExpiredErr
|
||||
// otherwise it returns false.
|
||||
func IsExpired(e error) bool {
|
||||
switch e.(type) {
|
||||
case ExpiredErr:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
func IsExpired(err error) bool {
|
||||
var e ExpiredErr
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// ExpiredErr is returned when the requested Docker image is present in the cache, but is
|
||||
|
||||
+6
-6
@@ -38,12 +38,12 @@ type AddCommand struct {
|
||||
|
||||
// ExecuteCommand executes the ADD command
|
||||
// Special stuff about ADD:
|
||||
// 1. If <src> is a remote file URL:
|
||||
// - destination will have permissions of 0600
|
||||
// - If remote file has HTTP Last-Modified header, we set the mtime of the file to that timestamp
|
||||
// - If dest doesn't end with a slash, the filepath is inferred to be <dest>/<filename>
|
||||
// 2. If <src> is a local tar archive:
|
||||
// - it is unpacked at the dest, as 'tar -x' would
|
||||
// 1. If <src> is a remote file URL:
|
||||
// - destination will have permissions of 0600
|
||||
// - If remote file has HTTP Last-Modified header, we set the mtime of the file to that timestamp
|
||||
// - If dest doesn't end with a slash, the filepath is inferred to be <dest>/<filename>
|
||||
// 2. If <src> is a local tar archive:
|
||||
// - it is unpacked at the dest, as 'tar -x' would
|
||||
func (a *AddCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.BuildArgs) error {
|
||||
replacementEnvs := buildArgs.ReplacementEnvs(config.Env)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
@@ -374,7 +375,7 @@ func Test_resolveIfSymlink(t *testing.T) {
|
||||
for i, c := range cases {
|
||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||
res, e := resolveIfSymlink(c.destPath)
|
||||
if e != c.err {
|
||||
if !errors.Is(e, c.err) {
|
||||
t.Errorf("%s: expected %v but got %v", c.destPath, c.err, e)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -28,7 +28,7 @@ type OnBuildCommand struct {
|
||||
cmd *instructions.OnbuildCommand
|
||||
}
|
||||
|
||||
//ExecuteCommand adds the specified expression in Onbuild to the config
|
||||
// ExecuteCommand adds the specified expression in Onbuild to the config
|
||||
func (o *OnBuildCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.BuildArgs) error {
|
||||
logrus.Info("Cmd: ONBUILD")
|
||||
logrus.Infof("Args: %s", o.cmd.Expression)
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -54,7 +54,7 @@ func (v *VolumeCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.
|
||||
if _, err := os.Stat(volume); os.IsNotExist(err) {
|
||||
logrus.Infof("Creating directory %s", volume)
|
||||
if err := os.MkdirAll(volume, 0755); err != nil {
|
||||
return fmt.Errorf("could not create directory for volume %s: %s", volume, err)
|
||||
return fmt.Errorf("could not create directory for volume %s: %w", volume, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
|
||||
@@ -55,7 +55,8 @@ func (b *BuildArgs) ReplacementEnvs(envs []string) []string {
|
||||
resultEnv := make([]string, len(envs))
|
||||
copy(resultEnv, envs)
|
||||
filtered := b.FilterAllowed(envs)
|
||||
return append(resultEnv, filtered...)
|
||||
// Disable makezero linter, since the previous make is paired with a same sized copy
|
||||
return append(resultEnv, filtered...) //nolint:makezero
|
||||
}
|
||||
|
||||
// AddMetaArgs adds the supplied args map to b's allowedMetaArgs
|
||||
|
||||
@@ -40,7 +40,7 @@ func ParseStages(opts *config.KanikoOptions) ([]instructions.Stage, []instructio
|
||||
var d []uint8
|
||||
match, _ := regexp.MatchString("^https?://", opts.DockerfilePath)
|
||||
if match {
|
||||
response, e := http.Get(opts.DockerfilePath)
|
||||
response, e := http.Get(opts.DockerfilePath) //nolint:noctx
|
||||
if e != nil {
|
||||
return nil, nil, e
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package executor
|
||||
|
||||
import (
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestHeaderAdded(t *testing.T) {
|
||||
os.Setenv("UPSTREAM_CLIENT_TYPE", test.upstream)
|
||||
defer func() { os.Unsetenv("UPSTREAM_CLIENT_TYPE") }()
|
||||
}
|
||||
req, err := http.NewRequest("GET", "dummy", nil)
|
||||
req, err := http.NewRequest("GET", "dummy", nil) //nolint:noctx
|
||||
if err != nil {
|
||||
t.Fatalf("culd not create a req due to %s", err)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package snapshot
|
||||
|
||||
import (
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package snapshot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -262,7 +263,7 @@ func addParentDirectories(t util.Tar, addedPaths map[string]bool, path string) e
|
||||
// filesWithLinks returns the symlink and the target path if its exists.
|
||||
func filesWithLinks(path string) ([]string, error) {
|
||||
link, err := util.GetSymLink(path)
|
||||
if err == util.ErrNotSymLink {
|
||||
if errors.Is(err, util.ErrNotSymLink) {
|
||||
return []string{path}, nil
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
@@ -272,7 +273,7 @@ func filesWithLinks(path string) ([]string, error) {
|
||||
link = filepath.Join(filepath.Dir(path), link)
|
||||
}
|
||||
if _, err := os.Stat(link); err != nil {
|
||||
return []string{path}, nil
|
||||
return []string{path}, nil //nolint:nilerr
|
||||
}
|
||||
return []string{path, link}, nil
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package snapshot
|
||||
|
||||
import (
|
||||
@@ -75,7 +76,7 @@ func TestSnapshotFSFileChange(t *testing.T) {
|
||||
actualFiles := []string{}
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ func TestSnapshotFSChangePermissions(t *testing.T) {
|
||||
foundFiles := []string{}
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
foundFiles = append(foundFiles, hdr.Name)
|
||||
@@ -248,7 +249,7 @@ func TestEmptySnapshotFS(t *testing.T) {
|
||||
}
|
||||
tr := tar.NewReader(f)
|
||||
|
||||
if _, err := tr.Next(); err != io.EOF {
|
||||
if _, err := tr.Next(); !errors.Is(err, io.EOF) {
|
||||
t.Fatal("no files expected in tar, found files.")
|
||||
}
|
||||
}
|
||||
@@ -559,7 +560,7 @@ func TestSnapshotOmitsUnameGname(t *testing.T) {
|
||||
tr := tar.NewReader(f)
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
@@ -636,7 +637,7 @@ func listFilesInTar(path string) ([]string, error) {
|
||||
var files []string
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.
|
||||
*/
|
||||
|
||||
package timing
|
||||
|
||||
import (
|
||||
|
||||
@@ -173,10 +173,14 @@ func IsDestDir(path string) bool {
|
||||
|
||||
// DestinationFilepath returns the destination filepath from the build context to the image filesystem
|
||||
// If source is a file:
|
||||
//
|
||||
// If dest is a dir, copy it to /dest/relpath
|
||||
// If dest is a file, copy directly to dest
|
||||
// If dest is a file, copy directly to dest
|
||||
//
|
||||
// If source is a dir:
|
||||
//
|
||||
// Assume dest is also a dir, and copy to dest/
|
||||
//
|
||||
// If dest is not an absolute filepath, add /cwd to the beginning
|
||||
func DestinationFilepath(src, dest, cwd string) (string, error) {
|
||||
_, srcFileName := filepath.Split(src)
|
||||
@@ -287,7 +291,7 @@ func IsSrcRemoteFileURL(rawurl string) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
_, err = http.Get(rawurl)
|
||||
_, err = http.Get(rawurl) //nolint:noctx
|
||||
return err == nil
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -167,7 +167,7 @@ func GetFSFromLayers(root string, layers []v1.Layer, opts ...FSOpt) ([]string, e
|
||||
tr := tar.NewReader(r)
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func DeleteFilesystem() error {
|
||||
return filepath.Walk(config.RootDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
// ignore errors when deleting.
|
||||
return nil
|
||||
return nil //nolint:nilerr
|
||||
}
|
||||
|
||||
if CheckIgnoreList(path) {
|
||||
@@ -270,7 +270,7 @@ func UnTar(r io.Reader, dest string) ([]string, error) {
|
||||
tr := tar.NewReader(r)
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
@@ -450,7 +450,7 @@ func DetectFilesystemIgnoreList(path string) error {
|
||||
for {
|
||||
line, err := reader.ReadString('\n')
|
||||
logrus.Tracef("Read the following line from %s: %s", path, line)
|
||||
if err != nil && err != io.EOF {
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return err
|
||||
}
|
||||
lineArr := strings.Split(line, " ")
|
||||
@@ -600,11 +600,11 @@ func AddVolumePathToIgnoreList(path string) {
|
||||
|
||||
// DownloadFileToDest downloads the file at rawurl to the given dest for the ADD command
|
||||
// From add command docs:
|
||||
// 1. If <src> is a remote file URL:
|
||||
// - destination will have permissions of 0600
|
||||
// - If remote file has HTTP Last-Modified header, we set the mtime of the file to that timestamp
|
||||
// 1. If <src> is a remote file URL:
|
||||
// - destination will have permissions of 0600
|
||||
// - If remote file has HTTP Last-Modified header, we set the mtime of the file to that timestamp
|
||||
func DownloadFileToDest(rawurl, dest string, uid, gid int64) error {
|
||||
resp, err := http.Get(rawurl)
|
||||
resp, err := http.Get(rawurl) //nolint:noctx
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func (t *Tar) Close() {
|
||||
func (t *Tar) AddFileToTar(p string) error {
|
||||
i, err := os.Lstat(p)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to get file info for %s: %s", p, err)
|
||||
return fmt.Errorf("Failed to get file info for %s: %w", p, err)
|
||||
}
|
||||
linkDst := ""
|
||||
if i.Mode()&os.ModeSymlink != 0 {
|
||||
@@ -156,7 +156,7 @@ func writeSecurityXattrToToFile(path string, hdr *tar.Header) error {
|
||||
}
|
||||
if capability, ok := hdr.Xattrs[securityCapabilityXattr]; ok {
|
||||
err := system.Lsetxattr(path, securityCapabilityXattr, []byte(capability), 0)
|
||||
if err != nil && !errors.Is(err, syscall.EOPNOTSUPP) && err != system.ErrNotSupportedPlatform {
|
||||
if err != nil && !errors.Is(err, syscall.EOPNOTSUPP) && !errors.Is(err, system.ErrNotSupportedPlatform) {
|
||||
return errors.Wrapf(err, "failed to write %q attribute to %q", securityCapabilityXattr, path)
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func readSecurityXattrToTarHeader(path string, hdr *tar.Header) error {
|
||||
hdr.Xattrs = make(map[string]string)
|
||||
}
|
||||
capability, err := system.Lgetxattr(path, securityCapabilityXattr)
|
||||
if err != nil && !errors.Is(err, syscall.EOPNOTSUPP) && err != system.ErrNotSupportedPlatform {
|
||||
if err != nil && !errors.Is(err, syscall.EOPNOTSUPP) && !errors.Is(err, system.ErrNotSupportedPlatform) {
|
||||
return errors.Wrapf(err, "failed to read %q attribute from %q", securityCapabilityXattr, path)
|
||||
}
|
||||
if capability != nil {
|
||||
|
||||
+3
-2
@@ -30,6 +30,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/minio/highwayhash"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -195,7 +196,7 @@ func Lgetxattr(path string, attr string) ([]byte, error) {
|
||||
dest := make([]byte, 128)
|
||||
sz, errno := unix.Lgetxattr(path, attr, dest)
|
||||
|
||||
for errno == unix.ERANGE {
|
||||
for errors.Is(errno, unix.ERANGE) {
|
||||
// Buffer too small, use zero-sized buffer to get the actual size
|
||||
sz, errno = unix.Lgetxattr(path, attr, []byte{})
|
||||
if errno != nil {
|
||||
@@ -206,7 +207,7 @@ func Lgetxattr(path string, attr string) ([]byte, error) {
|
||||
}
|
||||
|
||||
switch {
|
||||
case errno == unix.ENODATA:
|
||||
case errors.Is(errno, unix.ENODATA):
|
||||
return nil, nil
|
||||
case errno != nil:
|
||||
return nil, errno
|
||||
|
||||
Reference in New Issue
Block a user