-
Notifications
You must be signed in to change notification settings - Fork 1
Configure Minio buckets, policies, and users #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 41 commits
939bc38
b6497ea
f71086b
7afd928
e26c69b
d915ff1
757a85f
3b49c27
d8da113
5933dcb
0ebd29f
363f016
2a38503
ca3f047
fad0c0b
a6280d1
1a677ae
089ef92
5f132e6
46a41c4
cbdbe8a
181be87
8818825
9df84ba
a6fd45f
0913ef9
d7c7595
e9fea99
deffadd
e298a73
55e0119
384a7de
4de7a87
6b695e9
7743103
af03327
b6a8a6c
5861beb
2e7fec3
aeac722
9e801c5
8adcfef
64b3be3
ea2cf73
7905150
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import os | ||
| from pulumi import ComponentResource, ResourceOptions | ||
| from pulumi_kubernetes.batch.v1 import ( | ||
| Job, | ||
| JobSpecArgs, | ||
| ) | ||
| from pulumi_kubernetes.core.v1 import ( | ||
| ConfigMap, | ||
| ConfigMapVolumeSourceArgs, | ||
| ContainerArgs, | ||
| EnvVarArgs, | ||
| Namespace, | ||
| PodSpecArgs, | ||
| PodTemplateSpecArgs, | ||
| SecurityContextArgs, | ||
| VolumeMountArgs, | ||
| VolumeArgs, | ||
| ) | ||
| from pulumi_kubernetes.helm.v4 import Chart | ||
| from pulumi_kubernetes.meta.v1 import ObjectMetaArgs | ||
|
|
||
|
|
||
| def load_policy(name: str) -> str: | ||
| """ | ||
| Load a policy from the policies directory. | ||
| """ | ||
| with open( | ||
| os.path.join(os.path.dirname(__file__), "minio_policies", name), "r" | ||
| ) as f: | ||
| return f.read() | ||
JimMadge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class MinioConfigArgs: | ||
| def __init__( | ||
| self, minio_tenant_ns: Namespace, minio_tenant: Chart, minio_credentials: dict | ||
| ): | ||
| self.minio_tenant_ns = minio_tenant_ns | ||
| self.minio_tenant = minio_tenant | ||
| self.minio_credentials = minio_credentials | ||
|
|
||
|
|
||
| class MinioConfigJob(ComponentResource): | ||
| def __init__( | ||
| self, name: str, args: MinioConfigArgs, opts: ResourceOptions | None = None | ||
| ) -> None: | ||
| super().__init__("fridge:k8s:MinioConfigJob", name, {}, opts) | ||
| child_opts = ResourceOptions.merge(opts, ResourceOptions(parent=self)) | ||
|
|
||
| minio_setup_sh = """ | ||
| echo "Configuring ingress and egress buckets with anonymous S3 policies" | ||
| mc anonymous set upload $1/egress | ||
| mc anonymous set download $1/ingress | ||
| """ | ||
|
|
||
| # Create a ConfigMap for MinIO configuration | ||
| minio_config_map = ConfigMap( | ||
| "minio-configuration", | ||
| metadata=ObjectMetaArgs( | ||
| name="minio-configuration", | ||
| namespace=args.minio_tenant_ns.metadata.name, | ||
| ), | ||
| data={ | ||
| "MINIO_ALIAS": "argoartifacts", | ||
| "MINIO_URL": "http://minio.argo-artifacts.svc.cluster.local:80", | ||
| "MINIO_NAMESPACE": args.minio_tenant_ns.metadata.name, | ||
| "setup.sh": minio_setup_sh, | ||
| }, | ||
| opts=child_opts, | ||
| ) | ||
|
|
||
| # Create a Job to configure MinIO | ||
| Job( | ||
| "minio-config-job", | ||
| metadata=ObjectMetaArgs( | ||
| name="minio-config-job", | ||
| namespace=args.minio_tenant_ns.metadata.name, | ||
| labels={"app": "minio-config-job"}, | ||
| ), | ||
| spec=JobSpecArgs( | ||
| backoff_limit=1, | ||
| template=PodTemplateSpecArgs( | ||
| spec=PodSpecArgs( | ||
| containers=[ | ||
| ContainerArgs( | ||
| name="minio-config-job", | ||
| image="minio/mc:latest", | ||
| command=[ | ||
| "/bin/sh", | ||
| "-c", | ||
| ], | ||
| args=[ | ||
| "mc --insecure alias set argoartifacts http://minio.argo-artifacts.svc.cluster.local:80 $(MINIO_ROOT_USER) $(MINIO_ROOT_PASSWORD) &&" | ||
| "/tmp/scripts/setup.sh argoartifacts;", | ||
| ], | ||
|
Comment on lines
84
to
86
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to pass some commands as an argument here and others in a script?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @craddm possibly explain better, but 'mc' expects the alias to set first so the subsequent commands can refer to that alias. The script includes a bunch of mc commands, but alternatively we can have those here as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, does it not work if the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified this so all the commands are in the script, and the script now gets everything from the environment variables instead |
||
| resources={ | ||
| "requests": { | ||
| "cpu": "100m", | ||
| "memory": "128Mi", | ||
| }, | ||
| "limits": { | ||
| "cpu": "100m", | ||
| "memory": "128Mi", | ||
| }, | ||
| }, | ||
| env=[ | ||
| EnvVarArgs(name="MC_CONFIG_DIR", value="/tmp/.mc"), | ||
| EnvVarArgs( | ||
| name="MINIO_ROOT_USER", | ||
| value=args.minio_credentials.get( | ||
| "minio_root_user", "" | ||
| ), | ||
| ), | ||
| EnvVarArgs( | ||
| name="MINIO_ROOT_PASSWORD", | ||
| value=args.minio_credentials.get( | ||
| "minio_root_password", "" | ||
| ), | ||
| ), | ||
| ], | ||
| security_context=SecurityContextArgs( | ||
| allow_privilege_escalation=False, | ||
| capabilities={"drop": ["ALL"]}, | ||
| run_as_group=1000, | ||
| run_as_non_root=True, | ||
| run_as_user=1000, | ||
| seccomp_profile={"type": "RuntimeDefault"}, | ||
| ), | ||
| volume_mounts=[ | ||
| VolumeMountArgs( | ||
| name="minio-config-volume", | ||
| mount_path="/tmp/scripts/", | ||
| ) | ||
| ], | ||
| ) | ||
| ], | ||
| volumes=[ | ||
| VolumeArgs( | ||
| name="minio-config-volume", | ||
| config_map=ConfigMapVolumeSourceArgs( | ||
| name=minio_config_map.metadata.name, | ||
| default_mode=0o777, | ||
| ), | ||
| ) | ||
| ], | ||
| restart_policy="Never", | ||
| ), | ||
| ), | ||
| ), | ||
| opts=child_opts, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.