-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:warn: Fakeclient: Add apply support
This change is a POC for adding apply patch support to the fake client. This relies on the upstream support for this which is implemented in a new [FieldManagedObjectTracker][0]. In order to support many types, a custom `multiTypeConverter` is added. [0]: https://github.com/kubernetes/kubernetes/blob/4dc7a48ac6fb631a84e1974772bf7b8fd0bb9c59/staging/src/k8s.io/client-go/testing/fixture.go#L643
- Loading branch information
1 parent
d6b3440
commit b8202b9
Showing
4 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2025 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package fake | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
utilerror "k8s.io/apimachinery/pkg/util/errors" | ||
Check failure on line 23 in pkg/client/fake/typeconverter.go
|
||
"k8s.io/apimachinery/pkg/util/managedfields" | ||
"sigs.k8s.io/structured-merge-diff/v4/typed" | ||
) | ||
|
||
type multiTypeConverter struct { | ||
upstream []managedfields.TypeConverter | ||
} | ||
|
||
func (m multiTypeConverter) ObjectToTyped(r runtime.Object, o ...typed.ValidationOptions) (*typed.TypedValue, error) { | ||
var errs []error | ||
for _, u := range m.upstream { | ||
res, err := u.ObjectToTyped(r, o...) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
return nil, fmt.Errorf("failed to convert Object to Typed: %w", utilerror.NewAggregate(errs)) | ||
} | ||
|
||
func (m multiTypeConverter) TypedToObject(v *typed.TypedValue) (runtime.Object, error) { | ||
var errs []error | ||
for _, u := range m.upstream { | ||
res, err := u.TypedToObject(v) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
return nil, fmt.Errorf("failed to convert TypedValue to Object: %w", utilerror.NewAggregate(errs)) | ||
} |