Skip to content

Commit

Permalink
Merge pull request #3346 from ziyue-101/emergency_fix
Browse files Browse the repository at this point in the history
fix: only patch membership config for one membership
  • Loading branch information
google-oss-prow[bot] authored Dec 16, 2024
2 parents 19b0bf9 + d3c664b commit 2b39da1
Show file tree
Hide file tree
Showing 19 changed files with 3,490 additions and 5 deletions.
12 changes: 11 additions & 1 deletion mockgcp/mockgkehub/gkehubfeature.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *GKEHubFeature) UpdateFeature(ctx context.Context, req *pb.UpdateFeature
case "spec":
obj.Spec = req.GetResource().Spec
case "membershipSpecs":
obj.MembershipSpecs = req.GetResource().GetMembershipSpecs()
obj.MembershipSpecs = updateMembershipSpecsMap(obj.MembershipSpecs, req.GetResource().GetMembershipSpecs())
default:
return nil, status.Errorf(codes.InvalidArgument, "update_mask path %q not valid", path)
}
Expand All @@ -139,6 +139,16 @@ func (s *GKEHubFeature) UpdateFeature(ctx context.Context, req *pb.UpdateFeature
})
}

func updateMembershipSpecsMap(membershipSpecs, membershipSpecsPatch map[string]*pb.MembershipFeatureSpec) map[string]*pb.MembershipFeatureSpec {
if membershipSpecs == nil {
membershipSpecs = make(map[string]*pb.MembershipFeatureSpec)
}
for k, v := range membershipSpecsPatch {
membershipSpecs[k] = v
}
return membershipSpecs
}

func (s *GKEHubFeature) DeleteFeature(ctx context.Context, req *pb.DeleteFeatureRequest) (*longrunning.Operation, error) {
name, err := s.parseFeatureName(req.Name)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/direct/gkehub/featuremembership_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,15 @@ func (a *gkeHubAdapter) Delete(ctx context.Context, deleteOp *directbase.DeleteO

func (a *gkeHubAdapter) patchMembershipSpec(ctx context.Context) ([]byte, error) {
feature := a.actual
mSpecs := feature.MembershipSpecs
if mSpecs == nil {
mSpecs = make(map[string]featureapi.MembershipFeatureSpec)
}
mSpecs := make(map[string]featureapi.MembershipFeatureSpec)
// only change the feature configuration for the associated membership
desiredApiObj, err := featureMembershipSpecKRMtoMembershipFeatureSpecAPI(&a.desired.Spec)
if err != nil {
return nil, err
}
mSpecs[a.membershipID] = *desiredApiObj
// MembershipSpecs is a map of membership spec. Here we only patch one membership.
// GKE Hub server doesn't patch other memberships if they are not present in the membershipSpecs map.
feature.MembershipSpecs = mSpecs
op, err := a.hubClient.featureClient.Patch(a.featureID, feature).UpdateMask("membershipSpecs").Context(ctx).Do()
if err != nil {
Expand Down
Loading

0 comments on commit 2b39da1

Please sign in to comment.