Skip to content

Commit a43359a

Browse files
committed
feat: remote storage class
1 parent bc6fad7 commit a43359a

File tree

5 files changed

+45
-27
lines changed

5 files changed

+45
-27
lines changed

cmd/deploy.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SYNOPSIS
3535
[-b|--build] [--builder] [--builder-image] [-p|--push]
3636
[--domain] [--platform] [--build-timestamp] [--pvc-size]
3737
[--service-account] [-c|--confirm] [-v|--verbose]
38-
[--registry-insecure]
38+
[--registry-insecure] [--remote-storage-class]
3939
4040
DESCRIPTION
4141
@@ -127,7 +127,7 @@ EXAMPLES
127127
128128
`,
129129
SuggestFor: []string{"delpoy", "deplyo"},
130-
PreRunE: bindEnv("build", "build-timestamp", "builder", "builder-image", "confirm", "domain", "env", "git-branch", "git-dir", "git-url", "image", "namespace", "path", "platform", "push", "pvc-size", "service-account", "registry", "registry-insecure", "remote", "username", "password", "token", "verbose"),
130+
PreRunE: bindEnv("build", "build-timestamp", "builder", "builder-image", "confirm", "domain", "env", "git-branch", "git-dir", "git-url", "image", "namespace", "path", "platform", "push", "pvc-size", "service-account", "registry", "registry-insecure", "remote", "username", "password", "token", "verbose", "remote-storage-class"),
131131
RunE: func(cmd *cobra.Command, args []string) error {
132132
return runDeploy(cmd, newClient)
133133
},
@@ -179,6 +179,8 @@ EXAMPLES
179179
"Directory in the Git repository containing the function (default is the root) ($FUNC_GIT_DIR)")
180180
cmd.Flags().BoolP("remote", "R", f.Local.Remote,
181181
"Trigger a remote deployment. Default is to deploy and build from the local system ($FUNC_REMOTE)")
182+
cmd.Flags().StringP("remote-storage-class", "", f.Build.RemoteStorageClass,
183+
"Specify a storage class to use for the volume on-cluster during remote builds")
182184
cmd.Flags().String("pvc-size", f.Build.PVCSize,
183185
"When triggering a remote deployment, set a custom volume size to allocate for the build operation ($FUNC_PVC_SIZE)")
184186
cmd.Flags().String("service-account", f.Deploy.ServiceAccountName,
@@ -517,6 +519,10 @@ type deployConfig struct {
517519
// be triggered in a remote environment rather than run locally.
518520
Remote bool
519521

522+
// RemoteStorageClass defines the storage class to use for the remote
523+
// volume when building on-cluster.
524+
RemoteStorageClass string
525+
520526
// PVCSize configures the PVC size used by the pipeline if --remote flag is set.
521527
PVCSize string
522528

@@ -538,6 +544,7 @@ func newDeployConfig(cmd *cobra.Command) deployConfig {
538544
GitURL: viper.GetString("git-url"),
539545
Namespace: viper.GetString("namespace"),
540546
Remote: viper.GetBool("remote"),
547+
RemoteStorageClass: viper.GetString("remote-storage-class"),
541548
PVCSize: viper.GetString("pvc-size"),
542549
Timestamp: viper.GetBool("build-timestamp"),
543550
ServiceAccountName: viper.GetString("service-account"),
@@ -573,6 +580,7 @@ func (c deployConfig) Configure(f fn.Function) (fn.Function, error) {
573580
f.Build.Git.URL = c.GitURL
574581
f.Build.Git.ContextDir = c.GitDir
575582
f.Build.Git.Revision = c.GitBranch // TODO: should match; perhaps "refSpec"
583+
f.Build.RemoteStorageClass = c.RemoteStorageClass
576584
f.Deploy.ServiceAccountName = c.ServiceAccountName
577585
f.Local.Remote = c.Remote
578586

docs/reference/func_deploy.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SYNOPSIS
1414
[-b|--build] [--builder] [--builder-image] [-p|--push]
1515
[--domain] [--platform] [--build-timestamp] [--pvc-size]
1616
[--service-account] [-c|--confirm] [-v|--verbose]
17-
[--registry-insecure]
17+
[--registry-insecure] [--remote-storage-class]
1818

1919
DESCRIPTION
2020

@@ -113,28 +113,29 @@ func deploy
113113
### Options
114114

115115
```
116-
--build string[="true"] Build the function. [auto|true|false]. ($FUNC_BUILD) (default "auto")
117-
--build-timestamp Use the actual time as the created time for the docker image. This is only useful for buildpacks builder.
118-
-b, --builder string Builder to use when creating the function's container. Currently supported builders are "pack" and "s2i". (default "pack")
119-
--builder-image string Specify a custom builder image for use by the builder other than its default. ($FUNC_BUILDER_IMAGE)
120-
-c, --confirm Prompt to confirm options interactively ($FUNC_CONFIRM)
121-
--domain string Domain to use for the function's route. Cluster must be configured with domain matching for the given domain (ignored if unrecognized) ($FUNC_DOMAIN)
122-
-e, --env stringArray Environment variable to set in the form NAME=VALUE. You may provide this flag multiple times for setting multiple environment variables. To unset, specify the environment variable name followed by a "-" (e.g., NAME-).
123-
-t, --git-branch string Git revision (branch) to be used when deploying via the Git repository ($FUNC_GIT_BRANCH)
124-
-d, --git-dir string Directory in the Git repository containing the function (default is the root) ($FUNC_GIT_DIR)
125-
-g, --git-url string Repository url containing the function to build ($FUNC_GIT_URL)
126-
-h, --help help for deploy
127-
-i, --image string Full image name in the form [registry]/[namespace]/[name]:[tag]@[digest]. This option takes precedence over --registry. Specifying digest is optional, but if it is given, 'build' and 'push' phases are disabled. ($FUNC_IMAGE)
128-
-n, --namespace string Deploy into a specific namespace. Will use the function's current namespace by default if already deployed, and the currently active context if it can be determined. ($FUNC_NAMESPACE) (default "default")
129-
-p, --path string Path to the function. Default is current directory ($FUNC_PATH)
130-
--platform string Optionally specify a specific platform to build for (e.g. linux/amd64). ($FUNC_PLATFORM)
131-
-u, --push Push the function image to registry before deploying. ($FUNC_PUSH) (default true)
132-
--pvc-size string When triggering a remote deployment, set a custom volume size to allocate for the build operation ($FUNC_PVC_SIZE)
133-
-r, --registry string Container registry + registry namespace. (ex 'ghcr.io/myuser'). The full image name is automatically determined using this along with function name. ($FUNC_REGISTRY)
134-
--registry-insecure Skip TLS certificate verification when communicating in HTTPS with the registry ($FUNC_REGISTRY_INSECURE)
135-
-R, --remote Trigger a remote deployment. Default is to deploy and build from the local system ($FUNC_REMOTE)
136-
--service-account string Service account to be used in the deployed function ($FUNC_SERVICE_ACCOUNT)
137-
-v, --verbose Print verbose logs ($FUNC_VERBOSE)
116+
--build string[="true"] Build the function. [auto|true|false]. ($FUNC_BUILD) (default "auto")
117+
--build-timestamp Use the actual time as the created time for the docker image. This is only useful for buildpacks builder.
118+
-b, --builder string Builder to use when creating the function's container. Currently supported builders are "pack" and "s2i". (default "pack")
119+
--builder-image string Specify a custom builder image for use by the builder other than its default. ($FUNC_BUILDER_IMAGE)
120+
-c, --confirm Prompt to confirm options interactively ($FUNC_CONFIRM)
121+
--domain string Domain to use for the function's route. Cluster must be configured with domain matching for the given domain (ignored if unrecognized) ($FUNC_DOMAIN)
122+
-e, --env stringArray Environment variable to set in the form NAME=VALUE. You may provide this flag multiple times for setting multiple environment variables. To unset, specify the environment variable name followed by a "-" (e.g., NAME-).
123+
-t, --git-branch string Git revision (branch) to be used when deploying via the Git repository ($FUNC_GIT_BRANCH)
124+
-d, --git-dir string Directory in the Git repository containing the function (default is the root) ($FUNC_GIT_DIR)
125+
-g, --git-url string Repository url containing the function to build ($FUNC_GIT_URL)
126+
-h, --help help for deploy
127+
-i, --image string Full image name in the form [registry]/[namespace]/[name]:[tag]@[digest]. This option takes precedence over --registry. Specifying digest is optional, but if it is given, 'build' and 'push' phases are disabled. ($FUNC_IMAGE)
128+
-n, --namespace string Deploy into a specific namespace. Will use the function's current namespace by default if already deployed, and the currently active context if it can be determined. ($FUNC_NAMESPACE) (default "default")
129+
-p, --path string Path to the function. Default is current directory ($FUNC_PATH)
130+
--platform string Optionally specify a specific platform to build for (e.g. linux/amd64). ($FUNC_PLATFORM)
131+
-u, --push Push the function image to registry before deploying. ($FUNC_PUSH) (default true)
132+
--pvc-size string When triggering a remote deployment, set a custom volume size to allocate for the build operation ($FUNC_PVC_SIZE)
133+
-r, --registry string Container registry + registry namespace. (ex 'ghcr.io/myuser'). The full image name is automatically determined using this along with function name. ($FUNC_REGISTRY)
134+
--registry-insecure Skip TLS certificate verification when communicating in HTTPS with the registry ($FUNC_REGISTRY_INSECURE)
135+
-R, --remote Trigger a remote deployment. Default is to deploy and build from the local system ($FUNC_REMOTE)
136+
--remote-storage-class string Specify a storage class to use for the volume on-cluster during remote builds
137+
--service-account string Service account to be used in the deployed function ($FUNC_SERVICE_ACCOUNT)
138+
-v, --verbose Print verbose logs ($FUNC_VERBOSE)
138139
```
139140

140141
### SEE ALSO

pkg/functions/function.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ type BuildSpec struct {
141141
// when using deployment and remote build process (only relevant when Remote is true).
142142
PVCSize string `yaml:"pvcSize,omitempty"`
143143

144+
// RemoteStorageClass specifies the storage class to use for the volume used
145+
// on-cluster during when built remotely.
146+
RemoteStorageClass string `yaml:"remoteStorageClass,omitempty"`
147+
144148
// Image stores last built image name NOT in func.yaml, but instead
145149
// in .func/built-image
146150
Image string `yaml:"-"`

pkg/k8s/persistent_volumes.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetPersistentVolumeClaim(ctx context.Context, name, namespaceOverride strin
3232
return client.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, name, metav1.GetOptions{})
3333
}
3434

35-
func CreatePersistentVolumeClaim(ctx context.Context, name, namespaceOverride string, labels map[string]string, annotations map[string]string, accessMode corev1.PersistentVolumeAccessMode, resourceRequest resource.Quantity) (err error) {
35+
func CreatePersistentVolumeClaim(ctx context.Context, name, namespaceOverride string, labels map[string]string, annotations map[string]string, accessMode corev1.PersistentVolumeAccessMode, resourceRequest resource.Quantity, storageClassName string) (err error) {
3636
client, namespace, err := NewClientAndResolvedNamespace(namespaceOverride)
3737
if err != nil {
3838
return
@@ -52,8 +52,13 @@ func CreatePersistentVolumeClaim(ctx context.Context, name, namespaceOverride st
5252
},
5353
},
5454
}
55+
5556
pvc.Spec.Resources.Requests[corev1.ResourceStorage] = resourceRequest
5657

58+
if storageClassName != "" {
59+
pvc.Spec.StorageClassName = &storageClassName
60+
}
61+
5762
_, err = client.CoreV1().PersistentVolumeClaims(namespace).Create(ctx, pvc, metav1.CreateOptions{})
5863
return
5964
}

pkg/pipelines/tekton/pipelines_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ func createPipelinePersistentVolumeClaim(ctx context.Context, f fn.Function, nam
568568
return fmt.Errorf("PVC size value could not be parsed. %w", err)
569569
}
570570
}
571-
err = createPersistentVolumeClaim(ctx, getPipelinePvcName(f), namespace, labels, f.Deploy.Annotations, corev1.ReadWriteOnce, pvcs)
571+
err = createPersistentVolumeClaim(ctx, getPipelinePvcName(f), namespace, labels, f.Deploy.Annotations, corev1.ReadWriteOnce, pvcs, f.Build.RemoteStorageClass)
572572
if err != nil && !k8serrors.IsAlreadyExists(err) {
573573
return fmt.Errorf("problem creating persistent volume claim: %v", err)
574574
}

0 commit comments

Comments
 (0)