Skip to content

Commit

Permalink
upsync vw: Enable status subresource
Browse files Browse the repository at this point in the history
  • Loading branch information
jmprusi committed Nov 23, 2022
1 parent 5916c3c commit d0b0f57
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
40 changes: 37 additions & 3 deletions pkg/virtual/syncer/builder/forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,25 @@ func NewSyncerRestProvider(ctx context.Context, clusterClient kcpdynamic.Cluster
// NewUpSyncerRestProvider returns a forwarding storage build function, with an optional storage wrapper e.g. to add label based filtering.
func NewUpSyncerRestProvider(ctx context.Context, clusterClient kcpdynamic.ClusterInterface, apiExportIdentityHash string, wrapper registry.StorageWrapper) apiserver.RestProviderFunc {
return func(resource schema.GroupVersionResource, kind schema.GroupVersionKind, listKind schema.GroupVersionKind, typer runtime.ObjectTyper, tableConvertor rest.TableConvertor, namespaceScoped bool, schemaValidator *validate.SchemaValidator, subresourcesSchemaValidator map[string]*validate.SchemaValidator, structuralSchema *structuralschema.Structural) (mainStorage rest.Storage, subresourceStorages map[string]rest.Storage) {
statusSchemaValidate, statusEnabled := subresourcesSchemaValidator["status"]

var statusSpec *apiextensions.CustomResourceSubresourceStatus
if statusEnabled {
statusSpec = &apiextensions.CustomResourceSubresourceStatus{}
}

strategy := customresource.NewStrategy(
typer,
namespaceScoped,
kind,
schemaValidator,
nil,
statusSchemaValidate,
map[string]*structuralschema.Structural{resource.Version: structuralSchema},
nil,
statusSpec,
nil,
)

storage, _ := registry.NewStorage(
storage, statusStorage := registry.NewStorage(
ctx,
resource,
apiExportIdentityHash,
Expand All @@ -162,6 +169,33 @@ func NewUpSyncerRestProvider(ctx context.Context, clusterClient kcpdynamic.Clust
wrapper,
)

// we want to expose some but not all the allowed endpoints, so filter by exposing just the funcs we need
subresourceStorages = make(map[string]rest.Storage)
if statusEnabled {
subresourceStorages["status"] = &struct {
registry.FactoryFunc
registry.DestroyerFunc

registry.GetterFunc
registry.UpdaterFunc
// patch is implicit as we have get + update

registry.TableConvertorFunc
registry.CategoriesProviderFunc
registry.ResetFieldsStrategyFunc
}{
FactoryFunc: statusStorage.FactoryFunc,
DestroyerFunc: statusStorage.DestroyerFunc,

GetterFunc: statusStorage.GetterFunc,
UpdaterFunc: statusStorage.UpdaterFunc,

TableConvertorFunc: statusStorage.TableConvertorFunc,
CategoriesProviderFunc: statusStorage.CategoriesProviderFunc,
ResetFieldsStrategyFunc: statusStorage.ResetFieldsStrategyFunc,
}
}

return &struct {
registry.FactoryFunc
registry.ListFactoryFunc
Expand Down
11 changes: 9 additions & 2 deletions test/e2e/virtual/syncer/virtualworkspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1548,12 +1548,19 @@ func TestUpsyncerVirtualWorkspace(t *testing.T) {
}

t.Log("Creating PV test-pv through upsyncer virtual workspace...")
_, err = kubelikeSyncerVWClient.CoreV1().PersistentVolumes().Cluster(kubelikeWorkspaceName).Create(ctx, pv, metav1.CreateOptions{})
pv, err = kubelikeSyncerVWClient.CoreV1().PersistentVolumes().Cluster(kubelikeWorkspaceName).Create(ctx, pv, metav1.CreateOptions{})
require.NoError(t, err)

pv.Status.Phase = corev1.VolumeAvailable

t.Log("Updating status of the PV test-pv through upsyncer virtual workspace...")
_, err = kubelikeSyncerVWClient.CoreV1().PersistentVolumes().Cluster(kubelikeWorkspaceName).UpdateStatus(ctx, pv, metav1.UpdateOptions{})
require.NoError(t, err)

t.Log("Checking if the PV test-pv was created in the source cluster...")
_, err = kubeClusterClient.CoreV1().PersistentVolumes().Cluster(kubelikeWorkspaceName).Get(ctx, "test-pv", metav1.GetOptions{})
pv, err = kubeClusterClient.CoreV1().PersistentVolumes().Cluster(kubelikeWorkspaceName).Get(ctx, "test-pv", metav1.GetOptions{})
require.NoError(t, err)
require.Equal(t, corev1.VolumeAvailable, pv.Status.Phase)
},
},
{
Expand Down

0 comments on commit d0b0f57

Please sign in to comment.