mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-07 16:27:27 +00:00
wip
This commit is contained in:
parent
12efb1967e
commit
a01e6a6c3b
5 changed files with 37 additions and 13 deletions
|
|
@ -101,7 +101,7 @@ func createImageRepositoryRun(cmd *cobra.Command, args []string) error {
|
|||
var repo = imagev1.ImageRepository{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: objectName,
|
||||
Namespace: *kubeconfigArgs.Namespace,
|
||||
Namespace: GetDesiredNamespace(kubeconfigArgs),
|
||||
Labels: labels,
|
||||
},
|
||||
Spec: imagev1.ImageRepositorySpec{
|
||||
|
|
|
|||
|
|
@ -146,9 +146,11 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
ns := GetDesiredNamespace(kubeconfigArgs)
|
||||
|
||||
var listOpts []client.ListOption
|
||||
if !getArgs.allNamespaces {
|
||||
listOpts = append(listOpts, client.InNamespace(*kubeconfigArgs.Namespace))
|
||||
listOpts = append(listOpts, client.InNamespace(ns))
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
|
|
@ -190,12 +192,12 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
|||
logger.Failuref("%s object '%s' not found in %s namespace",
|
||||
get.kind,
|
||||
args[0],
|
||||
namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace),
|
||||
namespaceNameOrAny(getArgs.allNamespaces, ns),
|
||||
)
|
||||
} else if !getAll {
|
||||
logger.Failuref("no %s objects found in %s namespace",
|
||||
get.kind,
|
||||
namespaceNameOrAny(getArgs.allNamespaces, *kubeconfigArgs.Namespace),
|
||||
namespaceNameOrAny(getArgs.allNamespaces, ns),
|
||||
)
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||
opts := install.Options{
|
||||
BaseURL: installArgs.manifestsPath,
|
||||
Version: installArgs.version,
|
||||
Namespace: *kubeconfigArgs.Namespace,
|
||||
Namespace: GetDesiredNamespace(kubeconfigArgs),
|
||||
Components: components,
|
||||
Registry: installArgs.registry,
|
||||
ImagePullSecret: installArgs.imagePullSecret,
|
||||
|
|
@ -181,7 +181,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
logger.Successf("manifests build completed")
|
||||
logger.Actionf("installing components in %s namespace", *kubeconfigArgs.Namespace)
|
||||
logger.Actionf("installing components in %s namespace", opts.Namespace)
|
||||
|
||||
applyOutput, err := utils.Apply(ctx, kubeconfigArgs, kubeclientOptions, tmpDir, filepath.Join(tmpDir, manifest.Path))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.`,
|
|||
return fmt.Errorf("error getting namespace: %w", err)
|
||||
}
|
||||
|
||||
if ns == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if e := validation.IsDNS1123Label(ns); len(e) > 0 {
|
||||
return fmt.Errorf("namespace must be a valid DNS label: %q", ns)
|
||||
}
|
||||
|
|
@ -140,7 +144,6 @@ func init() {
|
|||
rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation")
|
||||
rootCmd.PersistentFlags().BoolVar(&rootArgs.verbose, "verbose", false, "print generated objects")
|
||||
|
||||
configureDefaultNamespace()
|
||||
kubeconfigArgs.APIServer = nil // prevent AddFlags from configuring --server flag
|
||||
kubeconfigArgs.Timeout = nil // prevent AddFlags from configuring --request-timeout flag, we have --timeout instead
|
||||
kubeconfigArgs.AddFlags(rootCmd.PersistentFlags())
|
||||
|
|
@ -198,8 +201,10 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func configureDefaultNamespace() {
|
||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||
func GetDesiredNamespace(cfg *genericclioptions.ConfigFlags) string {
|
||||
if *cfg.Namespace != "" {
|
||||
return *cfg.Namespace
|
||||
}
|
||||
fromEnv := os.Getenv("FLUX_SYSTEM_NAMESPACE")
|
||||
if fromEnv != "" {
|
||||
// namespace must be a valid DNS label. Assess against validation
|
||||
|
|
@ -207,11 +212,28 @@ func configureDefaultNamespace() {
|
|||
// may not be actively provided by end-user.
|
||||
if e := validation.IsDNS1123Label(fromEnv); len(e) > 0 {
|
||||
logger.Warningf(" ignoring invalid FLUX_SYSTEM_NAMESPACE: %q", fromEnv)
|
||||
return
|
||||
} else {
|
||||
return fromEnv
|
||||
}
|
||||
|
||||
kubeconfigArgs.Namespace = &fromEnv
|
||||
}
|
||||
|
||||
if _, has := os.LookupEnv("FLUX_NS_FOLLOW_KUBECONTEXT"); has {
|
||||
rawCfg, err := cfg.ToRawKubeConfigLoader().RawConfig()
|
||||
if err != nil {
|
||||
logger.Warningf(" failed parsing kubeconfig, ignoring: %q", fromEnv)
|
||||
} else {
|
||||
ctx := *cfg.Context
|
||||
if ctx == "" {
|
||||
ctx = rawCfg.CurrentContext
|
||||
}
|
||||
ns := rawCfg.Contexts[ctx].Namespace
|
||||
if ns != "" {
|
||||
return ns
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rootArgs.defaults.Namespace
|
||||
}
|
||||
|
||||
// readPasswordFromStdin reads a password from stdin and returns the input
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func buildComponentObjectRefs(components ...string) ([]object.ObjMetadata, error
|
|||
var objRefs []object.ObjMetadata
|
||||
for _, deployment := range components {
|
||||
objRefs = append(objRefs, object.ObjMetadata{
|
||||
Namespace: *kubeconfigArgs.Namespace,
|
||||
Namespace: GetDesiredNamespace(kubeconfigArgs),
|
||||
Name: deployment,
|
||||
GroupKind: schema.GroupKind{Group: "apps", Kind: "Deployment"},
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue