Skip to main content
Knowledge Base

import statement metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" is throwing k8s.io/apimachinery/pkg/util/clock: module k8s.io/apimachinery@latest found (v0.25.4), but does not contain package k8s.io/apimachinery/pkg/util/clock error

Answer

Hi All, I created terratest go language script for validating kubernetees pods and services I am using below functions in script for fetching services and pods 1. func [ListPods](https://github.com/gruntwork-io/terratest/blob/v0.41.3/modules/k8s/pod.go#L19) - ListPods(t, options, metav1.ListOptions{}) 2. func [ListServices](https://github.com/gruntwork-io/terratest/blob/v0.41.3/modules/k8s/service.go#L23) - ListServices(t, options, metav1.ListOptions{}) I am using below import statement for utlizing/invoking ListPods and ListServices functions `metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"` When i run below command then _go.mod_ file is getting generated successfully without any error `go mod init <module-name>` But when i run ANY of below command then i am getting error as **_k8s.io/apimachinery/pkg/util/clock: module k8s.io/apimachinery@latest found (v0.25.4), but does not contain package k8s.io/apimachinery/pkg/util/clock_** `go mod tidy` Or `go mod tidy -compat=1.17` Below is my _go version_ `go version go1.17.8 linux/amd64` Link and screenshot mentioned here https://github.com/gruntwork-io/terratest/blob/6fb86056797e3e62ebdd9011ba26605e0976a6f8/modules/k8s/pod_test.go#L20 is throwing error import statement metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" is throwing k8s.io/apimachinery/pkg/util/clock: module k8s.io/apimachinery@latest found (v0.25.4), but does not contain package k8s.io/apimachinery/pkg/util/clock error ![image](https://user-images.githubusercontent.com/73541850/204798343-11e41edb-564b-4e77-a80c-bcdfbf95565f.png) **Please help me at earliset as it is blocked for my Hackfest project accomplishment** This was working earlier around couple of months back but NOT working now :( --- <ins datetime="2022-11-30T12:58:00Z"> <p><a href="https://support.gruntwork.io/hc/requests/109674">Tracked in ticket #109674</a></p> </ins>

hi, usually, I fix this by locking dependencies versions, apimachinery in this case(maybe k8s api and client-go too): * remove `go.sum` * in `go.mod` set the same versions as in terratest https://github.com/gruntwork-io/terratest/blob/master/go.mod#L47 * `go mod tidy -compat=1.17` * may appear different errors in the code which will require fixing because of version downgrade