Skip to content

Commit 343c68d

Browse files
committed
Merge remote-tracking branch 'origin/main' into tg/support-provider-id-format-of-upstream-ccm
2 parents 3268799 + e55c90a commit 343c68d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

hack/update-operator-dev-deployment.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ tag="$(echo -n "$tag" | tr -c 'a-zA-Z0-9_.-' '-')"
8383

8484
image="$image_path/caph-staging:$tag"
8585

86+
# Fail if cluster-api-operator is running
87+
if kubectl get pods -A | grep -q cluster-api-operator; then
88+
echo "Error: cluster-api-operator is running!"
89+
echo "Changes to caph deployment and its CRDs would be reverted."
90+
echo "Hint: Scale down replicas of the cluster-api-operator deployment."
91+
exit 1
92+
fi
93+
8694
# run in background
8795
{
8896
make generate-manifests

main.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"time"
2929

3030
"github.com/spf13/pflag"
31+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
"k8s.io/apimachinery/pkg/runtime"
3233
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3334
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -37,6 +38,7 @@ import (
3738
"sigs.k8s.io/cluster-api/util/record"
3839
ctrl "sigs.k8s.io/controller-runtime"
3940
"sigs.k8s.io/controller-runtime/pkg/cache"
41+
"sigs.k8s.io/controller-runtime/pkg/client"
4042
"sigs.k8s.io/controller-runtime/pkg/controller"
4143
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4244
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -91,6 +93,20 @@ var (
9193
sshAfterInstallImage bool
9294
)
9395

96+
// strictManager is a ctrl.Manager that creates controller-runtime clients that enforce strict
97+
// schema validation. If a CRD's schema does not match the controller's schema, unexpected behavior
98+
// can occur. It's better to return an error than to perform a partial update where only some fields
99+
// are applied. Related:
100+
// https://www.reddit.com/r/kubernetes/comments/1oqnn6v/schema_mismatch_between_controller_and_crd/
101+
type strictManager struct {
102+
ctrl.Manager
103+
strictClient client.Client
104+
}
105+
106+
func (m *strictManager) GetClient() client.Client {
107+
return m.strictClient
108+
}
109+
94110
func main() {
95111
fs := pflag.CommandLine
96112
fs.StringVar(&metricsAddr, "metrics-bind-address", "localhost:8080", "The address the metric endpoint binds to.")
@@ -196,12 +212,17 @@ func main() {
196212
})
197213
}
198214

199-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
215+
origManager, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
200216
if err != nil {
201217
setupLog.Error(err, "unable to start manager")
202218
os.Exit(1)
203219
}
204220

221+
mgr := &strictManager{
222+
Manager: origManager,
223+
strictClient: client.WithFieldValidation(origManager.GetClient(), metav1.FieldValidationStrict),
224+
}
225+
205226
// Initialize event recorder.
206227
record.InitFromRecorder(mgr.GetEventRecorderFor("hetzner-controller"))
207228

0 commit comments

Comments
 (0)