Open SQxiaoxiaomeng opened 1 year ago
should add // +kubebuilder:pruning:PreserveUnknownFields
to github.com/openyurtio/yurt-app-manager/pkg/yurtappmanager/apis/apps/v1alpha1/yurtappset_types.go:Pool.Patch
// Pool defines the detail of a pool.
type Pool struct {
// Indicates pool name as a DNS_LABEL, which will be used to generate
// pool workload name prefix in the format '<deployment-name>-<pool-name>-'.
// Name should be unique between all of the pools under one YurtAppSet.
// Name is NodePool Name
Name string `json:"name"`
// Indicates the node selector to form the pool. Depending on the node selector,
// pods provisioned could be distributed across multiple groups of nodes.
// A pool's nodeSelectorTerm is not allowed to be updated.
// +optional
NodeSelectorTerm corev1.NodeSelectorTerm `json:"nodeSelectorTerm,omitempty"`
// Indicates the tolerations the pods under this pool have.
// A pool's tolerations is not allowed to be updated.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// Indicates the number of the pod to be created under this pool.
// +required
Replicas *int32 `json:"replicas,omitempty"`
// Indicates the patch for the templateSpec
// Now support strategic merge path :https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/#notes-on-the-strategic-merge-patch
// Patch takes precedence over Replicas fields
// If the Patch also modifies the Replicas, use the Replicas value in the Patch
// +kubebuilder:pruning:PreserveUnknownFields
// +optional
Patch *runtime.RawExtension `json:"patch,omitempty"`
}
copy from k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types.go preserveUnknownFields disables pruning of object fields which are not specified in the OpenAPI schema. apiVersion, kind, metadata and known fields inside metadata are always preserved. Defaults to true in v1beta and will default to false in v1.
in v0.6.0, crd apiVersion is apiextensions.k8s.io/v1, and in v0.5.0 crd version is apiextensions.k8s.io/v1beta1. So this bug not happened in v0.5.0
copy from k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types.go preserveUnknownFields disables pruning of object fields which are not specified in the OpenAPI schema. apiVersion, kind, metadata and known fields inside metadata are always preserved. Defaults to true in v1beta and will default to false in v1.
in v0.6.0, crd apiVersion is apiextensions.k8s.io/v1, and in v0.5.0 crd version is apiextensions.k8s.io/v1beta1. So this bug not happened in v0.5.0
你好,我按照你的方式修改两个文件,然后,执行 make generate ,但是报错误: /root/gopath/src/yurt-app-manager/bin/controller-gen "crd:crdVersions=v1" rbac:roleName=manager-role webhook paths="./..." paths="./pkg/yurtappmanager/..." output:crd:artifacts:config=config/yurt-app-manager/crd/bases output:rbac:artifacts:config=config/yurt-app-manager/rbac output:webhook:artifacts:config=config/yurt-app-manager/webhook /bin/sh: /root/gopath/src/yurt-app-manager/bin/controller-gen: No such file or directory
怎么解决呢?
@smallbearstar install controller-gen
in /root/gopath/src/yurt-app-manager/bin/controller-gen
,but run make generate
will install controller-gen
automatically.
@smallbearstar install
controller-gen
in/root/gopath/src/yurt-app-manager/bin/controller-gen
,but runmake generate
will installcontroller-gen
automatically.
那我修改文件后,需要做什么,才能使得openyurt 的crd 支持patch 字段呢?我现在需要patch这个功能,please help me!
@smallbearstar 你是用all_in_one.yaml部署吗,找到YurtAppSet这个CRD资源,在patch
字段下加上x-kubernetes-preserve-unknown-fields: true
,像下面这样,再重新apply
patch:
description: Indicates the patch for the templateSpec Now
support strategic merge path :https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/#notes-on-the-strategic-merge-patch
Patch takes precedence over Replicas fields If the Patch
also modifies the Replicas, use the Replicas value in
the Patch
type: object
x-kubernetes-preserve-unknown-fields: true
x-kubernetes-preserve-unknown-fields
we may update all_in_one.yaml file . @SQxiaoxiaomeng
What happened:
first step
second step
Execute
kubectl get yas ud-test -oyaml
,we get following yamlpatch in beijing nodePool has been pruned. And two deployments have same
sepc.template.spec.containers
as followingWhat you expected to happen:
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
Environment:
kubectl version
): client v1.22.15, server 1.22.15cat /etc/os-release
) NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/"CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
uname -a
): Linux kind-k8s 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux