gpt4 book ai didi

go - go mod导入K8s Taints Api时出错

转载 作者:行者123 更新时间:2023-12-01 22:20:45 27 4
gpt4 key购买 nike

我想使用 api 向(从)k8s 节点添加(删除)污点,代码如下:

import (
taints "k8s.io/kubernetes/pkg/util/taints"
)

newNode, updated, err := taints.AddOrUpdateTaint(node,taint)
newNode, removed, err := taints.RemoveTaint(node,taint)
但是当我通过 GoLand 同步依赖项时,发生了错误:

go: finding module for package k8s.io/kubernetes/pkg/util/taints
go: found k8s.io/kubernetes/pkg/util/taints in k8s.io/kubernetes v1.19.0
go: k8s.io/kubernetes@v1.19.0 requires
    k8s.io/api@v0.0.0: reading k8s.io/api/go.mod at revision v0.0.0: unknown revision v0.0.0

go.mod在我的项目中是这样的:
go 1.14

require (
github.com/gammazero/workerpool v1.0.0
github.com/glc v0.0.0-00010101000000-000000000000
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/mediocregopher/radix.v2 v0.0.0-20181115013041-b67df6e626f9
github.com/robfig/cron v1.2.0
github.com/spf13/pflag v1.0.5
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.19.0
k8s.io/apiextensions-apiserver v0.19.0
k8s.io/apimachinery v0.19.0
k8s.io/client-go v0.19.0
k8s.io/metrics v0.19.0
sigs.k8s.io/controller-runtime v0.6.2
)
我发现了一些关于这个错误的问题,但它似乎对我不起作用。( https://github.com/kubernetes/kubernetes/issues/79384)
希望有人能帮忙,谢谢~

最佳答案

您可以使用 script在您提到的问题中建议:

#!/bin/sh
set -euo pipefail

VERSION=${1#"v"}
if [ -z "$VERSION" ]; then
echo "Must specify version!"
exit 1
fi
MODS=($(
curl -sS https://raw.githubusercontent.com/kubernetes/kubernetes/v${VERSION}/go.mod |
sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p'
))
for MOD in "${MODS[@]}"; do
V=$(
go mod download -json "${MOD}@kubernetes-${VERSION}" |
sed -n 's|.*"Version": "\(.*\)".*|\1|p'
)
go mod edit "-replace=${MOD}=${MOD}@${V}"
done
go get "k8s.io/kubernetes@v${VERSION}"
将此另存为 upgrade-k8s.sh在与 go.mod 相同的目录中并按如下方式运行 sh upgrade-k8s.sh 1.19.0 .然后提交对 go.mod 所做的所有更改文件。现在您可以删除 upgrade-k8s.sh或保留以备将来升级 k8s.io/kubernetes模块。

关于go - go mod导入K8s Taints Api时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63682888/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com