GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Deploy a function from a git repository without a local copy by gauron99 · Pull Request #4064 · knative/func

feat: Deploy a function from a git repository without a local copy #4064

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.

Sign up for GitHub

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

Merged
knative-prow merged 3 commits into knative:main from gauron99:push-zwpsoszkmytz
Sep 29, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat: Deploy a function from a git repository without a local copy #4064

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
07c6541
feat: load a function from a git repository without a checkout
gauron99 Sep 24, 2026
a4ac621
fix: remote pipeline builds a function with no local directory
gauron99 Sep 24, 2026
78a8d01
feat: deploy --remote --source reads the function from the repository
gauron99 Sep 24, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

204 changes: 166 additions & 38 deletions 204 cmd/deploy.go
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"errors"
"fmt"
"io"
"os"
"slices"
"strconv"
"strings"

"github.com/AlecAivazis/survey/v2"
"github.com/google/go-containerregistry/pkg/name"
"github.com/ory/viper"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/api/resource"
"knative.dev/client/pkg/util"
"knative.dev/func/cmd/common"
Expand Down Expand Up @@ -81,6 +84,18 @@ DESCRIPTION
eliminating the need for a local container engine. To trigger deployment
of a git repository instead of local source, combine with '--source':
'{{rootCmdUse}} deploy --remote --source=git.example.com/alice/f.git'
A branch, tag or commit is given with '--revision':
'{{rootCmdUse}} deploy --remote --source=git.example.com/alice/f.git --revision=v1.2.0'
The function is then read from the repository, so no local copy is
needed, and nothing is written locally: to change the function, clone
the repository, edit it and deploy the working tree. Choose the
directory within the repository with '--source-dir'. The function is
deployed as configured by the func.yaml committed there: of the flags
which configure a function, only '--builder', '--registry',
'--registry-insecure' and '--namespace' apply, the latter only if the
func.yaml names no other namespace. A repository set in the local
func.yaml (build.source) instead of with '--source' is built with the
local function's settings.

Domain
When deploying, a function's route is automatically generated using the
Expand Down Expand Up @@ -268,53 +283,55 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {
// Initialize config first
cfg = newDeployConfig(cmd)

// Create function object to check if initialized
if f, err = fn.NewFunction(cfg.Path); err != nil {
return
}
// Only a repository given as a flag or environment variable deploys by
// reference. One in the local func.yaml (build.source) is built with the
// local function's settings, as before.
if cfg.Remote && cfg.Source != "" && flagGiven(cmd, "source") {
// A function deployed by reference: read from the repository, never
// from nor to the current directory, so its Root is empty.
if f, cfg, err = gitFunction(cmd, cfg); err != nil {
Comment thread
gauron99 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

return
}
Comment thread
gauron99 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

} else {
// Create function object to check if initialized
if f, err = fn.NewFunction(cfg.Path); err != nil {
return
}

// Check if function exists BEFORE prompting for config
if !f.Initialized() {
if !cfg.Remote || f.Build.Source.URL == "" {
// Only error if this is not a fully remote build
// Check if function exists BEFORE prompting for config
if !f.Initialized() {
return NewErrNotInitializedFromPath(f.Root, "deploy")
} else {
// TODO: this case is not supported because the pipeline
// implementation requires the function's name, which is in the
// remote repository. We should inspect the remote repository.
// For now, give a more helpful error.
return errors.New("please ensure the function's source is also available locally")
}
}

// Now that we know function exists, proceed with prompting
if cfg, err = cfg.Prompt(); err != nil {
if errors.Is(err, fn.ErrRegistryRequired) {
return NewErrRegistryRequired(err, "deploy")
// Now that we know function exists, proceed with prompting
if cfg, err = cfg.Prompt(); err != nil {
if errors.Is(err, fn.ErrRegistryRequired) {
return NewErrRegistryRequired(err, "deploy")
}
return
}
if err = cfg.Validate(cmd); err != nil {
return wrapValidateError(err, "deploy")
}
return
}
if err = cfg.Validate(cmd); err != nil {
return wrapValidateError(err, "deploy")
}

// Warn if registry changed but registryInsecure is still true
warnRegistryInsecureChange(cmd.OutOrStderr(), cfg.Registry, f)
// Warn if registry changed but registryInsecure is still true
warnRegistryInsecureChange(cmd.OutOrStderr(), cfg.Registry, f)

// Warn if expose flag is used with deployer where it has no effect
warnExposeIgnore(cmd.OutOrStderr(), cfg.Expose, cfg.Deployer)
// Warn if expose flag is used with deployer where it has no effect
warnExposeIgnore(cmd.OutOrStderr(), cfg.Expose, cfg.Deployer)

// Warn if scale.kpa is set with a deployer that ignores it
warnScaleKpaIgnore(cmd.OutOrStderr(), f.Scale, cfg.Deployer)
// Warn if scale.kpa is set with a deployer that ignores it
warnScaleKpaIgnore(cmd.OutOrStderr(), f.Scale, cfg.Deployer)

// Back-compat: a function deployed before the deployer was recorded has a
// namespace but no deployer, which historically could only mean knative.
if f.Deploy.Namespace != "" && f.Deploy.Deployer == "" {
f.Deploy.Deployer = deployers.Knative
}
// Back-compat: a function deployed before the deployer was recorded has a
// namespace but no deployer, which historically could only mean knative.
if f.Deploy.Namespace != "" && f.Deploy.Deployer == "" {
f.Deploy.Deployer = deployers.Knative
}

if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg
return
if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg
return
}
}
if err = f.Validate(); err != nil {
return
Expand Down Expand Up @@ -441,6 +458,12 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {
}
}

// A function deployed by reference is not written: to change it, clone
// the repository, edit it and deploy the working tree.
if f.Root == "" {
return nil
}

// Write
if err = f.Write(); err != nil {
return
Expand Down Expand Up @@ -938,7 +961,8 @@ func printDeployMessages(out io.Writer, f fn.Function) {
// -------------------
// When doing a remote build with --revision, warn if the local branch
// doesn't match, as this can lead to confusion about which func.yaml is used.
if f.Local.Remote && f.Build.Source.URL != "" && f.Build.Source.Revision != "" {
// A function read from the repository (no Root) has no local func.yaml.
if f.Root != "" && f.Local.Remote && f.Build.Source.URL != "" && f.Build.Source.Revision != "" {
// Doing a remote build, specified a git repository to pull from, and
// specified a reference within that remote.
currentBranch, err := common.DefaultCurrentBranch(f.Root)
Expand Down Expand Up @@ -984,3 +1008,107 @@ func warnScaleKpaIgnore(w io.Writer, scale *fn.ScaleOptions, deployer string) {
"supports kpa (concurrency/rps) autoscaling.\n")
}
}

// gitFlags are the only flags a deployment from a git repository takes:
// those which locate the function, those which the pipeline alone uses or
// which depend on where the function is deployed, and those which are not
// its settings. The function is otherwise deployed as configured by the
// func.yaml committed there.
var gitFlags = []string{"remote", "source", "revision", "source-dir", "builder",
"registry", "registry-insecure", "registry-authfile", "namespace", "username",
"password", "token", "verbose"}

// gitFunction returns the function committed to the git repository cfg
// names, for a remote pipeline which builds the commit it was read at, and
// cfg configured for it. The function is read into memory and has no Root.
// Settings it leaves empty default as for any function, never to those of a
// function in the current directory.
func gitFunction(cmd *cobra.Command, cfg deployConfig) (f fn.Function, _ deployConfig, err error) {
var extra []string
cmd.Flags().VisitAll(func(fl *pflag.Flag) {
if flagGiven(cmd, fl.Name) && !slices.Contains(gitFlags, fl.Name) {
extra = append(extra, "--"+fl.Name)
}
})
if len(extra) > 0 {
return f, cfg, fmt.Errorf("%s cannot be used with --source: the function is deployed as "+
"configured by the func.yaml in the repository. To change it, clone the "+
"repository, edit it and deploy the working tree", strings.Join(extra, ", "))
}

// The revision may also be given as the URL's fragment (<url>#<revision>),
// which then wins, as it does in Configure.
source := fn.Source{URL: cfg.Source, Revision: cfg.Revision, Dir: cfg.SourceDir}
if parts := strings.SplitN(cfg.Source, "#", 2); len(parts) == 2 {
source.URL, source.Revision = parts[0], parts[1]
}
if f, err = fn.NewFunctionFromGit(cmd.Context(), source); err != nil {
return f, cfg, err
}
f.Local.Remote = true

global, err := config.NewDefault()
if err != nil {
return f, cfg, err
}
if flagGiven(cmd, "builder") {
f.Build.Builder = cfg.Builder
}
if f.Build.Builder == "" {
f.Build.Builder = global.Builder
}
if flagGiven(cmd, "registry") {
f.Registry = cfg.Registry
}
if f.Registry == "" {
f.Registry = global.Registry
}
if flagGiven(cmd, "registry-insecure") {
f.RegistryInsecure = cfg.RegistryInsecure
}
// The cluster deploys into the namespace the func.yaml names, and only
// without one into the namespace the pipeline runs in.
if flagGiven(cmd, "namespace") {
committed := f.Namespace
if committed == "" {
committed = f.Deploy.Namespace
}
if committed != "" && committed != cfg.Namespace {
return f, cfg, fmt.Errorf("--namespace %q conflicts with the namespace %q in the "+
"repository's func.yaml, which the function is deployed into", cfg.Namespace, committed)
}
f.Namespace = cfg.Namespace
} else {
f.Namespace = defaultNamespace(f, cfg.Verbose)
}

// Check the namespace and domain the function is deployed with, as a
// local deployment checks them in deployConfig.Validate. Function.Validate
// checks the rest.
if f.Namespace != "" && utils.ValidateNamespace(f.Namespace) != nil {
return f, cfg, wrapValidateError(fn.ErrInvalidNamespace, "deploy")
}
if f.Domain != "" && utils.ValidateDomain(f.Domain) != nil {
return f, cfg, wrapValidateError(fn.ErrInvalidDomain, "deploy")
}

// The client is configured by cfg, whose defaults came from the current
// directory. The deployer is the one the cluster deploys with: the
// function's, else the one it was last deployed with, else the default.
deployer := f.Deployer
if deployer == "" {
deployer = f.Deploy.Deployer
}
if deployer == "" {
deployer = deployers.Default
}
cfg.Builder, cfg.Registry, cfg.RegistryInsecure, cfg.Deployer = f.Build.Builder, f.Registry, f.RegistryInsecure, deployer
return f, cfg, nil
}

// flagGiven reports whether the flag was set on the command line or with its
// environment variable, as opposed to taking its default.
func flagGiven(cmd *cobra.Command, flag string) bool {
env := "FUNC_" + strings.ToUpper(strings.ReplaceAll(flag, "-", "_"))
return cmd.Flags().Changed(flag) || os.Getenv(env) != ""
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.