Skip to content

Commit 320b000

Browse files
authored
add support to push to remote registry (#18)
* add support to push to remote registry * ensure default to deploy is true Signed-off-by: vsoch <vsoch@users.noreply.github.com>
1 parent 2627284 commit 320b000

18 files changed

Lines changed: 344 additions & 31 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Binaries for programs and plugins
33
./vendor
44
*.exe
5+
.env
56
*.exe~
67
*.dll
78
*.so

api/v1alpha1/orascache_types.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,29 @@ type OrasCacheSpec struct {
2323
// +optional
2424
Image string `json:"image"`
2525

26+
// Names of secrets for the operator
27+
// +optional
28+
Secrets Secrets `json:"secrets"`
29+
30+
// Skip deploying the registry (stateful set) implying all references
31+
// are for a remote (existing) registry
32+
// +kubebuilder:default=true
33+
// +default=true
34+
// +optional
35+
Deploy bool `json:"deploy"`
36+
}
37+
38+
type Secrets struct {
39+
40+
// Secrets for the environment for the ORAS operator sidecar pod to push
41+
// e.g., oras pull -u username -p password myregistry.io/myimage:latest
42+
// This should have ORAS_USER and ORAS_PASS
43+
// +optional
44+
OrasEnv string `json:"orasEnv"`
45+
2646
// Secret for the registry REGISTRY_HTTP_SECRET
2747
// +optional
28-
Secret string `json:"secret"`
48+
RegistryHttp string `json:"registryHttp"`
2949
}
3050

3151
// OrasCacheStatus defines the observed state of OrasCache

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cache.converged-computing.github.io_orascaches.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,28 @@ spec:
3535
spec:
3636
description: OrasCacheSpec defines the desired state of OrasCache
3737
properties:
38+
deploy:
39+
default: true
40+
description: Skip deploying the registry (stateful set) implying all
41+
references are for a remote (existing) registry
42+
type: boolean
3843
image:
3944
default: ghcr.io/oras-project/registry:latest
4045
description: Image is the oras registry to deploy
4146
type: string
42-
secret:
43-
description: Secret for the registry REGISTRY_HTTP_SECRET
44-
type: string
47+
secrets:
48+
description: Names of secrets for the operator
49+
properties:
50+
orasEnv:
51+
description: Secrets for the environment for the ORAS operator
52+
sidecar pod to push e.g., oras pull -u username -p password
53+
myregistry.io/myimage:latest This should have ORAS_USER and
54+
ORAS_PASS
55+
type: string
56+
registryHttp:
57+
description: Secret for the registry REGISTRY_HTTP_SECRET
58+
type: string
59+
type: object
4560
type: object
4661
status:
4762
description: OrasCacheStatus defines the observed state of OrasCache

controllers/oras/orascache_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ func (r *OrasCacheReconciler) ensureOrasCache(
107107
}
108108

109109
// The service running the oras registry is a stateful set
110-
_, result, _, err = r.getStatefulSet(ctx, spec)
111-
if err != nil {
112-
return result, err
110+
// But only deploy if we are requested to!
111+
if spec.Spec.Deploy {
112+
_, result, _, err = r.getStatefulSet(ctx, spec)
113+
if err != nil {
114+
return result, err
115+
}
113116
}
114117
return ctrl.Result{}, nil
115118
}

controllers/oras/statefulset.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,30 @@ func (r *OrasCacheReconciler) createStatefulSet(
120120
},
121121
}
122122

123+
// Prepare environment variables
123124
// Do we have a secret?
124-
if spec.Spec.Secret != "" {
125-
env := []corev1.EnvVar{{
125+
if spec.Spec.Secrets.RegistryHttp != "" {
126+
env := []corev1.EnvVar{}
127+
env = append(env, corev1.EnvVar{
126128
Name: "REGISTRY_HTTP_SECRET",
127-
Value: spec.Spec.Secret,
128-
}}
129+
Value: spec.Spec.Secrets.RegistryHttp,
130+
})
129131
set.Spec.Template.Spec.Containers[0].Env = env
130132
}
131133

134+
// Are we also adding environment variables from a secret?
135+
if spec.Spec.Secrets.OrasEnv != "" {
136+
set.Spec.Template.Spec.Containers[0].EnvFrom = []v1.EnvFromSource{
137+
{
138+
SecretRef: &corev1.SecretEnvSource{
139+
LocalObjectReference: corev1.LocalObjectReference{
140+
Name: spec.Spec.Secrets.OrasEnv,
141+
},
142+
},
143+
},
144+
}
145+
}
146+
132147
// Controller reference always needs to be set before creation
133148
ctrl.SetControllerReference(spec, set, r.Scheme)
134149
err := r.Client.Create(ctx, set)

docs/getting_started/custom-resource-definition.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,40 @@ spec:
4343
image: ghcr.io/oras-project/registry:latest
4444
```
4545
46-
#### secret
46+
#### deploy
4747
48-
In the case of deploying more than one registry, the push secret can be customized.
48+
If deploy is set to false, this indicates that you don't want the operator to deploy a stateful set local registry.
49+
This means that you'll need to provide all jobs / pods with a remote `registry` field to replace it, and (likely) a secret to pull or push.
50+
See [orasEnv](#orasEnv) below for details.
4951

5052
```yaml
5153
spec:
52-
# We can use all the defaults here (this is a default)
53-
secret: mysecret
54+
deploy: false
55+
```
56+
57+
#### secrets
58+
59+
There are several secrets that can be added, if needed.
60+
61+
##### orasEnv
62+
63+
If you deploy a secret to the namespace that you want the ORAS operator to use (providing in the environment to the pod)
64+
you can define the name here.
65+
66+
```yaml
67+
spec:
68+
secrets:
69+
orasEnv: mysecret-name
70+
```
71+
72+
##### registryHttp
73+
74+
In the case of deploying more than one registry pod (not supported yet), the push secret can be customized.
75+
76+
```yaml
77+
spec:
78+
secrets:
79+
registryHttp: mysecret
5480
```
5581

5682
Note that this is not supported yet - likely we would want to add custom volumes (for shared storage) between more than one pod in the stateful set.

docs/getting_started/user-guide.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,38 @@ once, first for the job, and then for the underlying pod(s) it creates. Annotati
149149
| output-uri | The output unique resource identifier for the registry step, including repository, name, and tag | false | false |NA will be used if not defined, meaning the step has no outputs |
150150
| oras-cache | The name of the sidecar orchestrator | false | false | oras |
151151
| oras-container | The container with oras to run for the service | false | false | ghcr.io/oras-project/oras:v1.1.0 |
152+
| registry | A custom remote registry URI for all containers | false | false | unset |
153+
| oras-env | A secret in the same namespace to add to the sidecar | false | false | unset |
152154
| container | The name of the launcher container | false | false | assumes the first container found requires the launcher |
153155
| entrypoint | The https address of the application entrypoint to wget | false | false | [entrypoint.sh](https://raw.githubusercontent.com/converged-computing/oras-operator/main/hack/entrypoint.sh) |
154156
| oras-entrypoint | The https address of the oras cache sidecar entrypoint to wget | false | false | [oras-entrypoint.sh](https://raw.githubusercontent.com/converged-computing/oras-operator/main/hack/oras-entrypoint.sh) |
155157
| debug | Print all discovered settings in the operator log | false | false | "false" |
156158
| unpack | Unpack a directory compressed to .tar.gz | false | false | "true" |
157159
158160
There should not be a need to change the oras-cache (sidecar container) unless for some reason you have another container in the pod also called oras. It is exposed for this rare case.
161+
More details about specific annotations are provided below.
159162
160-
Note that when List is true, this means the annotation can be provided as a list, and more than one value can be added with the pattern `<prefix>/<field>_<count>`. Currently the only supported list field is `input-uri`, anticipating that multiple parent steps might feed into one child step.
163+
#### Registry
164+
165+
By default, the URIs that are provided are prefixed with the registry that the ORAS Operator has deployed on the same cluster. However, if registry is supplied,
166+
it is assumed to be used for the entire job or pod definition, and this registry is used instead. If you absolutely don't need the local registry you can
167+
set "deploy" to false in the operator CRD (and it will be skipped). Also note that if you are pushing to a remote registry, you'll need to provide
168+
the name of a secret with your login and password via `oras-env`, discussed next.
169+
170+
#### oras-env
171+
172+
This should be the name of a secret in the same namespace as your pod or job that has one or more secrets to add to the environment. As an example to create such a secret:
173+
174+
```bash
175+
kubectl create secret generic oras-env --from-literal="ORAS_USER=${ORAS_USER}" --from-literal="ORAS_PUSH_PASS=${ORAS_PASS}" --from-literal="ORAS_PULL_PASS=${ORAS_PASS}"
176+
```
177+
The most common use case here is to provide credentials for pushing or pulling to a remote registry (when deploy is false). We provide the same credential twice for pull and push because it could
178+
be the case that you only want to add for one or the other, and in fact adding to a command that doesn't require it could result in an error. The secret must be in the same namespace
179+
as your job or pod.
180+
181+
#### Multiple input-uri
182+
183+
Note that when List is true, this means the annotation can be provided as a list, and more than one value can be added with the pattern `<prefix>/<field>_<count>`. Currently the only supported list field is `input-uri`, anticipating that multiple parent steps might feed into one child step. Here is an example with multiple input uris.
161184

162185
```yaml
163186
kind: Pod
@@ -215,6 +238,7 @@ kubectl logs -n oras-operator-system oras-operator-controller-manager-ff66845dd-
215238
You can then try one of the [examples](https://github.com/converged-computing/oras-operator/tree/main/examples) in the repository. A brief description of each is provided here,
216239
and likely we will add more detail as we develop them.
217240

218-
- [tests/registry](https://github.com/converged-computing/oras-operator/tree/main/examples/tests/registry/roas.yaml): a basic example of creating an ORAS registry cache
241+
- [registry](https://github.com/converged-computing/oras-operator/tree/main/examples/registry): demonstrates interaction with a remote registry and disable of a local (namespaced) deployment
242+
- [tests/registry](https://github.com/converged-computing/oras-operator/tree/main/examples/tests/registry/oras.yaml): a basic example of creating an ORAS registry cache
219243
- [tests/hello-world](https://github.com/converged-computing/oras-operator/tree/main/examples/tests/hello-world): Writing one "hello-world" output and saving to an ORAS registry cache
220244
- [workflows/metrics](https://github.com/converged-computing/oras-operator/tree/main/examples/woirkflow/metrics): Running two Metrics Operator apps/metrics (LAMMPS and HWLOC) and getting results for each!

examples/dist/oras-operator-arm.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,24 @@ spec:
5353
spec:
5454
description: OrasCacheSpec defines the desired state of OrasCache
5555
properties:
56+
deploy:
57+
default: true
58+
description: Skip deploying the registry (stateful set) implying all references are for a remote (existing) registry
59+
type: boolean
5660
image:
5761
default: ghcr.io/oras-project/registry:latest
5862
description: Image is the oras registry to deploy
5963
type: string
60-
secret:
61-
description: Secret for the registry REGISTRY_HTTP_SECRET
62-
type: string
64+
secrets:
65+
description: Names of secrets for the operator
66+
properties:
67+
orasEnv:
68+
description: Secrets for the environment for the ORAS operator sidecar pod to push e.g., oras pull -u username -p password myregistry.io/myimage:latest This should have ORAS_USER and ORAS_PASS
69+
type: string
70+
registryHttp:
71+
description: Secret for the registry REGISTRY_HTTP_SECRET
72+
type: string
73+
type: object
6374
type: object
6475
status:
6576
description: OrasCacheStatus defines the observed state of OrasCache

examples/dist/oras-operator-dev.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,24 @@ spec:
5353
spec:
5454
description: OrasCacheSpec defines the desired state of OrasCache
5555
properties:
56+
deploy:
57+
default: true
58+
description: Skip deploying the registry (stateful set) implying all references are for a remote (existing) registry
59+
type: boolean
5660
image:
5761
default: ghcr.io/oras-project/registry:latest
5862
description: Image is the oras registry to deploy
5963
type: string
60-
secret:
61-
description: Secret for the registry REGISTRY_HTTP_SECRET
62-
type: string
64+
secrets:
65+
description: Names of secrets for the operator
66+
properties:
67+
orasEnv:
68+
description: Secrets for the environment for the ORAS operator sidecar pod to push e.g., oras pull -u username -p password myregistry.io/myimage:latest This should have ORAS_USER and ORAS_PASS
69+
type: string
70+
registryHttp:
71+
description: Secret for the registry REGISTRY_HTTP_SECRET
72+
type: string
73+
type: object
6374
type: object
6475
status:
6576
description: OrasCacheStatus defines the observed state of OrasCache

0 commit comments

Comments
 (0)