Skip to content

Commit

Permalink
porch: added renderStatus to packagerevisonresources API
Browse files Browse the repository at this point in the history
  • Loading branch information
droot committed Oct 19, 2022
1 parent d3adf9f commit eb83914
Show file tree
Hide file tree
Showing 23 changed files with 155 additions and 105 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ kpt/kpt
*.exe
*.gif
bin/
porch/cmd/porch/__debug_bin

# Emacs temp files
*~
Expand Down
1 change: 1 addition & 0 deletions porch/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
vendor/
apiserver.local.config/
/apiserver/porch
cmd/porch/__debug_bin

# Development artifact path
.build/
Expand Down
10 changes: 8 additions & 2 deletions porch/api/porch/v1alpha1/types_packagerevisionresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type PackageRevisionResources struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec PackageRevisionResourcesSpec `json:"spec,omitempty"`
// Status PackageRevisionResourcesStatuc `json:"status,omitempty"`
Spec PackageRevisionResourcesSpec `json:"spec,omitempty"`
Status PackageRevisionResourcesStatus `json:"status,omitempty"`
}

// PackageRevisionResourcesList
Expand All @@ -54,3 +54,9 @@ type PackageRevisionResourcesSpec struct {
// Resources are the content of the package.
Resources map[string]string `json:"resources,omitempty"`
}

// PackageRevisionResourcesStatus represents state of the rendered package resources.
type PackageRevisionResourcesStatus struct {
// RenderStatus contains the result of rendering the package resources.
RenderStatus RenderStatus `json:"renderStatus,omitempty"`
}
13 changes: 13 additions & 0 deletions porch/api/porch/v1alpha1/types_packagerevisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha1

import (
fnresult "github.com/GoogleContainerTools/kpt/pkg/api/fnresult/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand Down Expand Up @@ -127,6 +128,18 @@ type Task struct {
Update *PackageUpdateTaskSpec `json:"update,omitempty"`
}

type TaskResult struct {
Type TaskType `json:"type"`
RenderStatus *RenderStatus `json:"renderStatus,omitempty"`
}

// RenderStatus represents the result of performing render operation
// on a package resources.
type RenderStatus struct {
Result fnresult.ResultList `json:"result,omitempty"`
Err string `json:"err"`
}

// PackageInitTaskSpec defines the package initialization task.
type PackageInitTaskSpec struct {
// `Subpackage` is a directory path to a subpackage to initialize. If unspecified, the main package will be initialized.
Expand Down
6 changes: 3 additions & 3 deletions porch/pkg/engine/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newPackageContextGeneratorMutation(packageConfig *builtins.PackageConfig) (

var _ mutation = &builtinEvalMutation{}

func (m *builtinEvalMutation) Apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.Task, error) {
func (m *builtinEvalMutation) Apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, *api.Task, error) {
ff := &runtimeutil.FunctionFilter{
Run: m.runner.Run,
Results: &yaml.RNode{},
Expand All @@ -70,12 +70,12 @@ func (m *builtinEvalMutation) Apply(ctx context.Context, resources repository.Pa
}

if err := pipeline.Execute(); err != nil {
return repository.PackageResources{}, nil, fmt.Errorf("failed to evaluate function %q: %w", m.function, err)
return repository.PackageResources{}, nil, nil, fmt.Errorf("failed to evaluate function %q: %w", m.function, err)
}

for k, v := range pr.extra {
result.Contents[k] = v
}

return result, nil, nil
return result, nil, nil, nil
}
2 changes: 1 addition & 1 deletion porch/pkg/engine/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestPackageContext(t *testing.T) {
t.Fatalf("Failed to get builtin function mutation: %v", err)
}

got, _, err := m.Apply(context.Background(), input)
got, _, _, err := m.Apply(context.Background(), input)
if err != nil {
t.Fatalf("Failed to apply builtin function mutation: %v", err)
}
Expand Down
12 changes: 6 additions & 6 deletions porch/pkg/engine/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type clonePackageMutation struct {
packageConfig *builtins.PackageConfig
}

func (m *clonePackageMutation) Apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.Task, error) {
func (m *clonePackageMutation) Apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, *api.Task, error) {
ctx, span := tracer.Start(ctx, "clonePackageMutation::Apply", trace.WithAttributes())
defer span.End()

Expand All @@ -67,7 +67,7 @@ func (m *clonePackageMutation) Apply(ctx context.Context, resources repository.P
}

if err != nil {
return repository.PackageResources{}, nil, err
return repository.PackageResources{}, nil, nil, err
}

// Add any pre-existing parts of the config that have not been overwritten by the clone operation.
Expand All @@ -82,11 +82,11 @@ func (m *clonePackageMutation) Apply(ctx context.Context, resources repository.P
// refactored once we finalize the task/mutation/commit model.
genPkgContextMutation, err := newPackageContextGeneratorMutation(m.packageConfig)
if err != nil {
return repository.PackageResources{}, nil, err
return repository.PackageResources{}, nil, nil, err
}
cloned, _, err = genPkgContextMutation.Apply(ctx, cloned)
cloned, _, _, err = genPkgContextMutation.Apply(ctx, cloned)
if err != nil {
return repository.PackageResources{}, nil, fmt.Errorf("failed to generate deployment context: %w", err)
return repository.PackageResources{}, nil, nil, fmt.Errorf("failed to generate deployment context %w", err)
}
}

Expand All @@ -99,7 +99,7 @@ func (m *clonePackageMutation) Apply(ctx context.Context, resources repository.P
klog.Infof("failed to add merge-key to resources %v", err)
}

return result, m.task, nil
return result, nil, m.task, nil
}

func (m *clonePackageMutation) cloneFromRegisteredRepository(ctx context.Context, ref *api.PackageRevisionRef) (repository.PackageResources, error) {
Expand Down
4 changes: 2 additions & 2 deletions porch/pkg/engine/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ func TestCloneGitBasicAuth(t *testing.T) {
},
}

_, _, err = cpm.Apply(context.Background(), repository.PackageResources{})
_, _, _, err = cpm.Apply(context.Background(), repository.PackageResources{})
if err == nil {
t.Errorf("Expected error (unauthorized); got none")
}

cpm.credentialResolver = auth

r, _, err := cpm.Apply(context.Background(), repository.PackageResources{})
r, _, _, err := cpm.Apply(context.Background(), repository.PackageResources{})
if err != nil {
t.Errorf("task apply failed: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions porch/pkg/engine/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type editPackageMutation struct {

var _ mutation = &editPackageMutation{}

func (m *editPackageMutation) Apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.Task, error) {
func (m *editPackageMutation) Apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, *api.Task, error) {
ctx, span := tracer.Start(ctx, "editPackageMutation::Apply", trace.WithAttributes())
defer span.End()

Expand All @@ -43,10 +43,10 @@ func (m *editPackageMutation) Apply(ctx context.Context, resources repository.Pa
referenceResolver: m.referenceResolver,
}).FetchResources(ctx, sourceRef, m.namespace)
if err != nil {
return repository.PackageResources{}, nil, fmt.Errorf("failed to fetch resources for package %q: %w", sourceRef.Name, err)
return repository.PackageResources{}, nil, nil, fmt.Errorf("failed to fetch resources for package %q: %w", sourceRef.Name, err)
}

return repository.PackageResources{
Contents: sourceResources.Spec.Resources,
}, &api.Task{}, nil
}, nil, &api.Task{}, nil
}
2 changes: 1 addition & 1 deletion porch/pkg/engine/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ info:
repoOpener: repoOpener,
}

res, _, err := epm.Apply(context.Background(), repository.PackageResources{})
res, _, _, err := epm.Apply(context.Background(), repository.PackageResources{})
if err != nil {
t.Errorf("task apply failed: %v", err)
}
Expand Down
Loading

0 comments on commit eb83914

Please sign in to comment.