Skip to content

Commit

Permalink
Merge pull request #3713 from werf/synchronization_address_corrections
Browse files Browse the repository at this point in the history
fix: corrections for KUBECONFIG config path merge list support for --synchronization kubernetes param
  • Loading branch information
distorhead committed Sep 15, 2021
2 parents c571f25 + 584114d commit 596026f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
35 changes: 25 additions & 10 deletions cmd/werf/common/synchronization.go
Expand Up @@ -108,7 +108,7 @@ func checkSynchronizationKubernetesParamsForWarnings(cmdData *CmdData) {
}

func GetSynchronization(ctx context.Context, cmdData *CmdData, projectName string, stagesStorage storage.StagesStorage) (*SynchronizationParams, error) {
getKubeParamsFunc := func(address string, configPathMergeList *[]string) (*SynchronizationParams, error) {
getKubeParamsFunc := func(address string, commonKubeInitializer *OndemandKubeInitializer) (*SynchronizationParams, error) {
res := &SynchronizationParams{}
res.SynchronizationType = KubernetesSynchronization
res.Address = address
Expand All @@ -117,9 +117,23 @@ func GetSynchronization(ctx context.Context, cmdData *CmdData, projectName strin
return nil, fmt.Errorf("unable to parse synchronization address %s: %s", res.Address, err)
} else {
res.KubeParams = params
res.KubeParams.ConfigPathMergeList = configPathMergeList
return res, nil
}

if res.KubeParams.ConfigPath == "" {
res.KubeParams.ConfigPath = commonKubeInitializer.KubeConfig
}
if res.KubeParams.ConfigContext == "" {
res.KubeParams.ConfigContext = commonKubeInitializer.KubeContext
}
if res.KubeParams.ConfigDataBase64 == "" {
res.KubeParams.ConfigDataBase64 = commonKubeInitializer.KubeConfigBase64
}
if res.KubeParams.ConfigPathMergeList == nil {
res.KubeParams.ConfigPathMergeList = commonKubeInitializer.KubeConfigPathMergeList
}

return res, nil

}

getHttpParamsFunc := func(synchronization string, stagesStorage storage.StagesStorage) (*SynchronizationParams, error) {
Expand Down Expand Up @@ -150,7 +164,7 @@ func GetSynchronization(ctx context.Context, cmdData *CmdData, projectName strin
return &SynchronizationParams{Address: *cmdData.Synchronization, SynchronizationType: LocalSynchronization}, nil
} else if strings.HasPrefix(*cmdData.Synchronization, "kubernetes://") {
checkSynchronizationKubernetesParamsForWarnings(cmdData)
return getKubeParamsFunc(*cmdData.Synchronization, cmdData.KubeConfigPathMergeList)
return getKubeParamsFunc(*cmdData.Synchronization, GetOndemandKubeInitializer())
} else if strings.HasPrefix(*cmdData.Synchronization, "http://") || strings.HasPrefix(*cmdData.Synchronization, "https://") {
return getHttpParamsFunc(*cmdData.Synchronization, stagesStorage)
} else {
Expand All @@ -166,10 +180,10 @@ func GetStagesStorageCache(synchronization *SynchronizationParams) (storage.Stag
if config, err := kube.GetKubeConfig(kube.KubeConfigOptions{
ConfigPath: synchronization.KubeParams.ConfigPath,
ConfigDataBase64: synchronization.KubeParams.ConfigDataBase64,
ConfigPathMergeList: *synchronization.KubeParams.ConfigPathMergeList,
ConfigPathMergeList: synchronization.KubeParams.ConfigPathMergeList,
Context: synchronization.KubeParams.ConfigContext,
}); err != nil {
return nil, fmt.Errorf("unable to load synchronization kube config %q (context %q)", synchronization.KubeParams.ConfigPath, synchronization.KubeParams.ConfigContext)
return nil, fmt.Errorf("unable to load synchronization kube config (context %q): %s", synchronization.KubeParams.ConfigContext, err)
} else if client, err := kubernetes.NewForConfig(config.Config); err != nil {
return nil, fmt.Errorf("unable to create synchronization kubernetes client: %s", err)
} else {
Expand All @@ -190,11 +204,12 @@ func GetStorageLockManager(ctx context.Context, synchronization *Synchronization
return storage.NewGenericLockManager(werf.GetHostLocker()), nil
case KubernetesSynchronization:
if config, err := kube.GetKubeConfig(kube.KubeConfigOptions{
ConfigPath: synchronization.KubeParams.ConfigPath,
ConfigDataBase64: synchronization.KubeParams.ConfigDataBase64,
Context: synchronization.KubeParams.ConfigContext,
ConfigPath: synchronization.KubeParams.ConfigPath,
ConfigDataBase64: synchronization.KubeParams.ConfigDataBase64,
ConfigPathMergeList: synchronization.KubeParams.ConfigPathMergeList,
Context: synchronization.KubeParams.ConfigContext,
}); err != nil {
return nil, fmt.Errorf("unable to load synchronization kube config %q (context %q)", synchronization.KubeParams.ConfigPath, synchronization.KubeParams.ConfigContext)
return nil, fmt.Errorf("unable to load synchronization kube config %q (context %q): %s", synchronization.KubeParams.ConfigPath, synchronization.KubeParams.ConfigContext, err)
} else if dynamicClient, err := dynamic.NewForConfig(config.Config); err != nil {
return nil, fmt.Errorf("unable to create synchronization kubernetes dynamic client: %s", err)
} else if client, err := kubernetes.NewForConfig(config.Config); err != nil {
Expand Down
Expand Up @@ -138,6 +138,14 @@ werf bundle publish [options]
STAGE_NAME should be one of the following: from, beforeInstall, importsBeforeInstall,
gitArchive, install, importsAfterInstall, beforeSetup, importsBeforeSetup, setup,
importsAfterSetup, gitCache, gitLatestPatch, dockerInstructions, dockerfile
--kube-config=''
Kubernetes config file path (default $WERF_KUBE_CONFIG, or $WERF_KUBECONFIG, or
$KUBECONFIG)
--kube-config-base64=''
Kubernetes config data as base64 string (default $WERF_KUBE_CONFIG_BASE64 or
$WERF_KUBECONFIG_BASE64 or $KUBECONFIG_BASE64)
--kube-context=''
Kubernetes config context (default $WERF_KUBE_CONTEXT)
--log-color-mode='auto'
Set log color mode.
Supported on, off and auto (based on the stdout’s file descriptor referring to a
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/synchronization.go
Expand Up @@ -13,7 +13,7 @@ type KubernetesSynchronizationParams struct {
ConfigContext string
ConfigPath string
ConfigDataBase64 string
ConfigPathMergeList *[]string
ConfigPathMergeList []string
Namespace string
}

Expand Down

0 comments on commit 596026f

Please sign in to comment.