Skip to content
Snippets Groups Projects
Select Git revision
  • 53ca91301f6a36c0c87e7d6b06b1bd8c9ec1b283
  • main default protected
  • renovate/main-redis-5.x
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.35.2
  • 41.35.1
  • 41.35.0
  • 41.34.1
  • 41.34.0
  • 41.33.0
  • 41.32.3
  • 41.32.2
  • 41.32.1
  • 41.32.0
  • 41.31.1
  • 41.31.0
  • 41.30.5
  • 41.30.4
  • 41.30.3
  • 41.30.2
  • 41.30.1
  • 41.30.0
  • 41.29.1
  • 41.29.0
41 results

index.spec.ts

  • export_source_bucket.go 2.57 KiB
    /*
    Copyright 2020 The Flux authors
    
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
        http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    */
    
    package main
    
    import (
    	"github.com/spf13/cobra"
    	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    	"k8s.io/apimachinery/pkg/types"
    
    	sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
    )
    
    var exportSourceBucketCmd = &cobra.Command{
    	Use:   "bucket [name]",
    	Short: "Export Bucket sources in YAML format",
    	Long:  "The export source git command exports one or all Bucket sources in YAML format.",
    	Example: `  # Export all Bucket sources
      flux export source bucket --all > sources.yaml
    
      # Export a Bucket source including the static credentials
      flux export source bucket my-bucket --with-credentials > source.yaml`,
    	ValidArgsFunction: resourceNamesCompletionFunc(sourcev1.GroupVersion.WithKind(sourcev1.BucketKind)),
    	RunE: exportWithSecretCommand{
    		list:   bucketListAdapter{&sourcev1.BucketList{}},
    		object: bucketAdapter{&sourcev1.Bucket{}},
    	}.run,
    }
    
    func init() {
    	exportSourceCmd.AddCommand(exportSourceBucketCmd)
    }
    
    func exportBucket(source *sourcev1.Bucket) interface{} {
    	gvk := sourcev1.GroupVersion.WithKind(sourcev1.BucketKind)
    	export := sourcev1.Bucket{
    		TypeMeta: metav1.TypeMeta{
    			Kind:       gvk.Kind,
    			APIVersion: gvk.GroupVersion().String(),
    		},
    		ObjectMeta: metav1.ObjectMeta{
    			Name:        source.Name,
    			Namespace:   source.Namespace,
    			Labels:      source.Labels,
    			Annotations: source.Annotations,
    		},
    		Spec: source.Spec,
    	}
    	return export
    }
    
    func getBucketSecret(source *sourcev1.Bucket) *types.NamespacedName {
    	if source.Spec.SecretRef != nil {
    		namespacedName := types.NamespacedName{
    			Namespace: source.Namespace,
    			Name:      source.Spec.SecretRef.Name,
    		}
    
    		return &namespacedName
    	}
    
    	return nil
    }
    
    func (ex bucketAdapter) secret() *types.NamespacedName {
    	return getBucketSecret(ex.Bucket)
    }
    
    func (ex bucketListAdapter) secretItem(i int) *types.NamespacedName {
    	return getBucketSecret(&ex.BucketList.Items[i])
    }
    
    func (ex bucketAdapter) export() interface{} {
    	return exportBucket(ex.Bucket)
    }
    
    func (ex bucketListAdapter) exportItem(i int) interface{} {
    	return exportBucket(&ex.BucketList.Items[i])
    }