diff --git a/.vscode/launch.json b/.vscode/launch.json index 2be72fd5..af69815a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,17 +12,15 @@ "program": "${workspaceFolder}/cmd/porch/main.go", "args": [ "--secure-port=4443", - // "--v=7", - // "--standalone-debug-mode", "--kubeconfig=${env:KUBECONFIG}", "--cache-directory=${workspaceFolder}/.cache", - "--function-runner=172.18.255.201:9445", + "--function-runner=${env:FUNCTION_RUNNER_IP}:9445", "--repo-sync-frequency=60s" ], "cwd": "${workspaceFolder}", "env": { "CERT_STORAGE_DIR": "${workspaceFolder}/.build/pki/tmp", - "WEBHOOK_HOST": "localhost" + "WEBHOOK_HOST": "localhost" } }, { diff --git a/Makefile b/Makefile index dc3e4e76..eb0d0fa3 100644 --- a/Makefile +++ b/Makefile @@ -322,7 +322,7 @@ load-images-to-kind: ## Build porch images and load them into a kind cluster .PHONY: deploy-current-config deploy-current-config: ## Deploy the configuration that is currently in $(DEPLOYPORCHCONFIGDIR) kpt fn render $(DEPLOYPORCHCONFIGDIR) - kpt live init $(DEPLOYPORCHCONFIGDIR) --name porch --namespace porch-system --inventory-id porch-test || true + kpt live init $(DEPLOYPORCHCONFIGDIR) --name porch --namespace porch-system --inventory-id nephio || true kpt live apply --inventory-policy=adopt --server-side --force-conflicts $(DEPLOYPORCHCONFIGDIR) @kubectl rollout status deployment function-runner --namespace porch-system 2>/dev/null || true @kubectl rollout status deployment porch-controllers --namespace porch-system 2>/dev/null || true diff --git a/api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml b/api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml index 1c482642..b7464bf9 100644 --- a/api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml +++ b/api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml @@ -77,9 +77,11 @@ spec: Ignored if `type` is not `git`. properties: branch: + default: main description: Name of the branch containing the packages. Finalized packages will be committed to this branch (if the repository allows write access). If unspecified, defaults to "main". + minLength: 1 type: string createBranch: description: CreateBranch specifies if Porch should create the @@ -176,9 +178,11 @@ spec: Must be unspecified if `type` is not `git`. properties: branch: + default: main description: Name of the branch containing the packages. Finalized packages will be committed to this branch (if the repository allows write access). If unspecified, defaults to "main". + minLength: 1 type: string createBranch: description: CreateBranch specifies if Porch should create diff --git a/api/porchconfig/v1alpha1/types.go b/api/porchconfig/v1alpha1/types.go index da863a69..0eba861f 100644 --- a/api/porchconfig/v1alpha1/types.go +++ b/api/porchconfig/v1alpha1/types.go @@ -92,6 +92,8 @@ type GitRepository struct { // Address of the Git repository, for example: // `https://github.com/GoogleCloudPlatform/blueprints.git` Repo string `json:"repo"` + // +kubebuilder:default=main + // +kubebuilder:validation:MinLength=1 // Name of the branch containing the packages. Finalized packages will be committed to this branch (if the repository allows write access). If unspecified, defaults to "main". Branch string `json:"branch,omitempty"` // CreateBranch specifies if Porch should create the package branch if it doesn't exist. diff --git a/pkg/git/git.go b/pkg/git/git.go index 46350ee2..0276c23d 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -121,6 +121,9 @@ func OpenRepository(ctx context.Context, name, namespace string, spec *configapi return nil, fmt.Errorf("error cloning git repository %q, cannot create remote: %v", spec.Repo, err) } + // NOTE: the spec.git.branch field in the Repository CRD (OpenAPI schema) is defined with + // MinLength=1 validation and its default value is set to "main". This means that + // it should never be empty at this point. The following code is left here as a last resort failsafe. branch := MainBranch if spec.Branch != "" { branch = BranchName(spec.Branch) @@ -140,8 +143,8 @@ func OpenRepository(ctx context.Context, name, namespace string, spec *configapi } if opts.UseGitCaBundle { - if caBundle, err := opts.CredentialResolver.ResolveCredential(ctx, namespace, namespace + "-ca-bundle"); err != nil { - klog.Errorf("failed to obtain caBundle from secret %s/%s: %v", namespace, namespace + "-ca-bundle", err) + if caBundle, err := opts.CredentialResolver.ResolveCredential(ctx, namespace, namespace+"-ca-bundle"); err != nil { + klog.Errorf("failed to obtain caBundle from secret %s/%s: %v", namespace, namespace+"-ca-bundle", err) } else { repository.caBundle = []byte(caBundle.ToString()) } @@ -1095,8 +1098,8 @@ func (r *gitRepository) pushAndCleanup(ctx context.Context, ph *pushRefSpecBuild Auth: auth, RequireRemoteRefs: require, // TODO(justinsb): Need to ensure this is a compare-and-swap - Force: true, - CABundle: r.caBundle, + Force: true, + CABundle: r.caBundle, }) }); err != nil { return err