Skip to content

Commit

Permalink
Merge pull request #10778 from olemarkus/managed-file-public
Browse files Browse the repository at this point in the history
Add support for creating world-readable managedFiles
  • Loading branch information
k8s-ci-robot authored Feb 11, 2021
2 parents c00e561 + e0c3490 commit 9b7ed55
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/model/components/etcdmanager/tests/minimal/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Contents: |-
Lifecycle: null
Location: /control/etcd-cluster-spec
Name: etcd-cluster-spec-events
Public: null
---
Base: memfs://clusters.example.com/minimal.example.com/backups/etcd-main
Contents: |-
Expand All @@ -55,6 +56,7 @@ Contents: |-
Lifecycle: null
Location: /control/etcd-cluster-spec
Name: etcd-cluster-spec-main
Public: null
---
Base: null
Contents: |
Expand Down Expand Up @@ -112,6 +114,7 @@ Contents: |
Lifecycle: null
Location: manifests/etcd/events.yaml
Name: manifests-etcdmanager-events
Public: null
---
Base: null
Contents: |
Expand Down Expand Up @@ -169,3 +172,4 @@ Contents: |
Lifecycle: null
Location: manifests/etcd/main.yaml
Name: manifests-etcdmanager-main
Public: null
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Contents: |-
Lifecycle: null
Location: /control/etcd-cluster-spec
Name: etcd-cluster-spec-events
Public: null
---
Base: memfs://clusters.example.com/minimal.example.com/backups/etcd-main
Contents: |-
Expand All @@ -55,6 +56,7 @@ Contents: |-
Lifecycle: null
Location: /control/etcd-cluster-spec
Name: etcd-cluster-spec-main
Public: null
---
Base: null
Contents: |
Expand Down Expand Up @@ -118,6 +120,7 @@ Contents: |
Lifecycle: null
Location: manifests/etcd/events.yaml
Name: manifests-etcdmanager-events
Public: null
---
Base: null
Contents: |
Expand Down Expand Up @@ -181,3 +184,4 @@ Contents: |
Lifecycle: null
Location: manifests/etcd/main.yaml
Name: manifests-etcdmanager-main
Public: null
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Contents: |-
Lifecycle: null
Location: /control/etcd-cluster-spec
Name: etcd-cluster-spec-events
Public: null
---
Base: memfs://clusters.example.com/minimal.example.com/backups/etcd-main
Contents: |-
Expand All @@ -55,6 +56,7 @@ Contents: |-
Lifecycle: null
Location: /control/etcd-cluster-spec
Name: etcd-cluster-spec-main
Public: null
---
Base: null
Contents: |
Expand Down Expand Up @@ -115,6 +117,7 @@ Contents: |
Lifecycle: null
Location: manifests/etcd/events.yaml
Name: manifests-etcdmanager-events
Public: null
---
Base: null
Contents: |
Expand Down Expand Up @@ -175,3 +178,4 @@ Contents: |
Lifecycle: null
Location: manifests/etcd/main.yaml
Name: manifests-etcdmanager-main
Public: null
4 changes: 4 additions & 0 deletions pkg/model/components/etcdmanager/tests/proxy/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Contents: |-
Lifecycle: null
Location: /control/etcd-cluster-spec
Name: etcd-cluster-spec-events
Public: null
---
Base: memfs://clusters.example.com/minimal.example.com/backups/etcd-main
Contents: |-
Expand All @@ -55,6 +56,7 @@ Contents: |-
Lifecycle: null
Location: /control/etcd-cluster-spec
Name: etcd-cluster-spec-main
Public: null
---
Base: null
Contents: |
Expand Down Expand Up @@ -127,6 +129,7 @@ Contents: |
Lifecycle: null
Location: manifests/etcd/events.yaml
Name: manifests-etcdmanager-events
Public: null
---
Base: null
Contents: |
Expand Down Expand Up @@ -199,3 +202,4 @@ Contents: |
Lifecycle: null
Location: manifests/etcd/main.yaml
Name: manifests-etcdmanager-main
Public: null
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Contents: |
Lifecycle: null
Location: manifests/static/kube-apiserver-healthcheck.yaml
Name: manifests-static-kube-apiserver-healthcheck
Public: null
21 changes: 18 additions & 3 deletions upup/pkg/fi/fitasks/managedfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ManagedFile struct {
Base *string
Location *string
Contents fi.Resource
Public *bool
}

func (e *ManagedFile) Find(c *fi.Context) (*ManagedFile, error) {
Expand Down Expand Up @@ -102,9 +103,23 @@ func (_ *ManagedFile) Render(c *fi.Context, a, e, changes *ManagedFile) error {
}
p = p.Join(location)

acl, err := acls.GetACL(p, c.Cluster)
if err != nil {
return err
var acl vfs.ACL
if fi.BoolValue(e.Public) {
switch p.(type) {
case *vfs.S3Path:
acl = vfs.S3Acl{
RequestACL: fi.String("public-read"),
}
default:
return fmt.Errorf("the %q path does not support public ACL", p.Path())
}

} else {

acl, err = acls.GetACL(p, c.Cluster)
if err != nil {
return err
}
}

err = p.WriteFile(bytes.NewReader(data), acl)
Expand Down

0 comments on commit 9b7ed55

Please sign in to comment.