Skip to content

Commit

Permalink
[v2] Capture stack outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
blampe committed Sep 20, 2024
1 parent 3cb8900 commit 39a6052
Show file tree
Hide file tree
Showing 10 changed files with 471 additions and 281 deletions.
419 changes: 255 additions & 164 deletions agent/pkg/proto/agent.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions agent/pkg/proto/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ message UpResult {
string stderr = 2;
UpdateSummary summary = 3;
optional string permalink = 4;
map<string, OutputValue> outputs = 5;
}

message OutputValue {
bytes value = 1;
bool secret = 2;
}

message UpdateSummary {
Expand Down
38 changes: 34 additions & 4 deletions agent/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,15 @@ func (s *Server) Up(in *pb.UpRequest, srv pb.AutomationService_UpServer) error {

s.log.Infow("up completed", "summary", res.Summary)

outputs, err := marshalOutputs(res.Outputs)
if err != nil {
return fmt.Errorf("marshaling outputs: %w", err)
}

resp := &pb.UpResult{
Stdout: res.StdOut,
Stderr: res.StdErr,
Outputs: outputs,
Summary: marshalUpdateSummary(res.Summary),
}
permalink, err := res.GetPermalink()
Expand Down Expand Up @@ -691,11 +697,35 @@ func parseTime(s *string) *timestamppb.Timestamp {

func marshalEngineEvent(evt apitype.EngineEvent) (*structpb.Struct, error) {
m := make(map[string]any)
j, _ := json.Marshal(evt)
_ = json.Unmarshal(j, &m)
data, err := structpb.NewStruct(m)
j, err := json.Marshal(evt)
if err != nil {
return nil, err
}
err = json.Unmarshal(j, &m)
if err != nil {
return nil, err
}
return data, nil
return structpb.NewStruct(m)
}

// marshalOutputs serializes outputs as a resource.PropertyMap to make
// downstream secret handling easier.
func marshalOutputs(outputs auto.OutputMap) (map[string]*pb.OutputValue, error) {
if len(outputs) == 0 {
return nil, nil
}

o := make(map[string]*pb.OutputValue, len(outputs))
for k, v := range outputs {
value, err := json.Marshal(v.Value)
if err != nil {
return nil, err
}
o[k] = &pb.OutputValue{
Value: value,
Secret: v.Secret,
}
}

return o, nil
}
4 changes: 4 additions & 0 deletions operator/api/auto/v1alpha1/update_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ type UpdateStatus struct {
// +optional
Message string `json:"message,omitempty"`

// Outputs names a secret containing the outputs for this update.
// +optional
Outputs string `json:"outputs,omitempty"`

// Represents the observations of an update's current state.
// Known .status.conditions.type are: "Complete", "Failed", and "Progressing"
// +patchMergeKey=type
Expand Down
4 changes: 4 additions & 0 deletions operator/config/crd/bases/auto.pulumi.com_updates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ spec:
format: int64
minimum: 0
type: integer
outputs:
description: Outputs names a secret containing the outputs for this
update.
type: string
permalink:
description: Represents the permalink URL in the Pulumi Console for
the operation. Not available for DIY backends.
Expand Down
9 changes: 9 additions & 0 deletions operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ kind: ClusterRole
metadata:
name: manager-role
rules:
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- update
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- get
- list
- watch
Expand Down
4 changes: 2 additions & 2 deletions operator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/djherbis/times v1.5.0 h1:79myA211VwPhFTqUk8xehWrsEO+zcIZj0zT8mXPVARU=
github.com/djherbis/times v1.5.0/go.mod h1:5q7FDLvbNg1L/KaBmPcWlVR9NmoKo3+ucqUA3ijQhA0=
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5 h1:m62nsMU279qRD9PQSWD1l66kmkXzuYcnVJqL4XLeV2M=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk=
github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
Expand Down
Loading

0 comments on commit 39a6052

Please sign in to comment.