Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Force configmap ownership when updating #540

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions coordinator/impl/k8s_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package impl
import (
"context"
"encoding/json"
pb "google.golang.org/protobuf/proto"
"log/slog"
"os"

Expand Down Expand Up @@ -102,6 +103,7 @@ func (c *clientImpl[Resource]) Upsert(namespace, name string, resource *Resource

result, err := client.Patch(ctx, name, types.ApplyPatchType, desiredBytes, metav1.PatchOptions{
FieldManager: fieldManager,
Force: pb.Bool(true),
})

if errors.IsNotFound(err) {
Expand Down
10 changes: 7 additions & 3 deletions coordinator/impl/metadata_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package impl

import (
"log/slog"
"os"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -86,6 +85,8 @@ func (m *metadataProviderConfigMap) getWithoutLock() (*model.ClusterStatus, Vers
}

version := Version(cm.ResourceVersion)
slog.Debug("Get metadata successful",
slog.String("version", cm.ResourceVersion))
m.metadataSize.Store(int64(len(data)))
return status, version, nil
}
Expand All @@ -103,13 +104,16 @@ func (m *metadataProviderConfigMap) Store(status *model.ClusterStatus, expectedV
}

if version != expectedVersion {
slog.Error("Store metadata failed for version mismatch",
slog.Any("local-version", version),
slog.Any("expected-version", expectedVersion))
panic(ErrMetadataBadVersion)
}

data := configMap(m.name, status, expectedVersion)
cm, err := K8SConfigMaps(m.kubernetes).Upsert(m.namespace, m.name, data)
if k8serrors.IsConflict(err) {
panic(ErrMetadataBadVersion)
panic(err)
}
version = Version(cm.ResourceVersion)
m.metadataSize.Store(int64(len(data.Data["status"])))
Expand All @@ -127,7 +131,7 @@ func configMap(name string, status *model.ClusterStatus, version Version) *corev
"unable to marshal cluster status",
slog.Any("error", err),
)
os.Exit(1)
panic(err)
}

cm := &corev1.ConfigMap{
Expand Down
Loading