Skip to content
Open
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
47 changes: 24 additions & 23 deletions apis/config/handlers/confighandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ConfigStoreHandler struct {
}

func (r *ConfigStoreHandler) DryRunCreateFn(ctx context.Context, key types.NamespacedName, obj runtime.Object, dryrun bool) (runtime.Object, error) {
c, target, err := r.prepareConfigAndTarget(ctx, key, obj)
c, target, err := r.prepareConfigAndTarget(ctx, obj)
if err != nil {
return obj, err
}
Expand All @@ -47,17 +47,17 @@ func (r *ConfigStoreHandler) DryRunCreateFn(ctx context.Context, key types.Names

intents := []*sdcpb.TransactionIntent{
{
Intent: config.GetGVKNSN(c),
Priority: int32(c.Spec.Priority),
Update: updates,
Intent: config.GetGVKNSN(c),
Priority: int32(c.Spec.Priority),
Update: updates,
// Dont set not Revertive
},
}

return targetmanager.RunDryRunTransaction(ctx, key, c, target, intents, dryrun)
return targetmanager.RunDryRunTransaction(ctx, c, target, intents, dryrun)
}
func (r *ConfigStoreHandler) DryRunUpdateFn(ctx context.Context, key types.NamespacedName, obj, old runtime.Object, dryrun bool) (runtime.Object, error) {
c, target, err := r.prepareConfigAndTarget(ctx, key, obj)
c, target, err := r.prepareConfigAndTarget(ctx, obj)
if err != nil {
return obj, err
}
Expand All @@ -69,17 +69,17 @@ func (r *ConfigStoreHandler) DryRunUpdateFn(ctx context.Context, key types.Names

intents := []*sdcpb.TransactionIntent{
{
Intent: config.GetGVKNSN(c),
Priority: int32(c.Spec.Priority),
Update: updates,
Intent: config.GetGVKNSN(c),
Priority: int32(c.Spec.Priority),
Update: updates,
// Dont set not Revertive
},
}

return targetmanager.RunDryRunTransaction(ctx, key, c, target, intents, dryrun)
return targetmanager.RunDryRunTransaction(ctx, c, target, intents, dryrun)
}
func (r *ConfigStoreHandler) DryRunDeleteFn(ctx context.Context, key types.NamespacedName, obj runtime.Object, dryrun bool) (runtime.Object, error) {
c, target, err := r.prepareConfigAndTarget(ctx, key, obj)
c, target, err := r.prepareConfigAndTarget(ctx, obj)
if err != nil {
return obj, err
}
Expand All @@ -91,37 +91,38 @@ func (r *ConfigStoreHandler) DryRunDeleteFn(ctx context.Context, key types.Names
},
}

return targetmanager.RunDryRunTransaction(ctx, key, c, target, intents, dryrun)
return targetmanager.RunDryRunTransaction(ctx, c, target, intents, dryrun)
}

// prepareConfigAndTarget validates labels, casts the object, fetches the Target
// and ensures it's ready.
// prepareConfigAndTarget validates labels, resolves the
// Target reference from the config's labels and fetches that Target, ensuring
// it's ready.
func (r *ConfigStoreHandler) prepareConfigAndTarget(
ctx context.Context,
key types.NamespacedName,
obj runtime.Object,
) (*config.Config, *configv1alpha1.Target, error) {
c, ok := obj.(*config.Config)
if !ok {
return nil, nil, fmt.Errorf("expected *config.Config, got %T", obj)
}

accessor, err := meta.Accessor(obj)
if err != nil {
return nil, nil, err
}

if _, err := config.GetTargetKey(accessor.GetLabels()); err != nil {
targetKey, err := config.GetTargetKey(accessor.GetLabels())
if err != nil {
return nil, nil, err
}

c, ok := obj.(*config.Config)
if !ok {
return nil, nil, fmt.Errorf("expected *config.Config, got %T", obj)
}

target := &configv1alpha1.Target{}
if err := r.Client.Get(ctx, key, target); err != nil {
if err := r.Client.Get(ctx, targetKey, target); err != nil {
return nil, nil, err
}

if !target.IsReady() {
return nil, nil, fmt.Errorf("target not ready %s", key)
return nil, nil, fmt.Errorf("target not ready %s", targetKey)
}

return c, target, nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/sdc/target/manager/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"context"
"fmt"

"github.com/henderiw/apiserver-store/pkg/storebackend"
"github.com/sdcio/config-server/apis/condition"
"github.com/sdcio/config-server/apis/config"
configv1alpha1 "github.com/sdcio/config-server/apis/config/v1alpha1"
dsclient "github.com/sdcio/config-server/pkg/sdc/dataserver/client"
sdcpb "github.com/sdcio/sdc-protos/sdcpb"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
)

Expand All @@ -35,7 +35,6 @@ import (
// and updates the Config status/conditions.
func RunDryRunTransaction(
ctx context.Context,
key types.NamespacedName,
c *config.Config,
target *configv1alpha1.Target,
intents []*sdcpb.TransactionIntent,
Expand All @@ -57,9 +56,11 @@ func RunDryRunTransaction(
}
}()

targetKey := storebackend.KeyFromNSN(target.GetNamespacedName())

req := &sdcpb.TransactionSetRequest{
TransactionId: config.GetGVKNSN(c),
DatastoreName: key.String(),
DatastoreName: targetKey.String(),
DryRun: dryrun,
Timeout: ptr.To(int32(60)),
Intents: intents,
Expand Down
Loading