Skip to content
Snippets Groups Projects
Commit dcbad629 authored by Jessica Yuen's avatar Jessica Yuen
Browse files

Remove command update

Update is a deprecated command that was ported over from kubecfg. Since
ksonnet has not had any releases yet, it makes little sense to keep the
command.
parent f808801c
No related branches found
No related tags found
No related merge requests found
// Copyright 2017 The kubecfg 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 cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/ksonnet/ksonnet/metadata"
"github.com/ksonnet/ksonnet/pkg/kubecfg"
)
func init() {
RootCmd.AddCommand(updateCmd)
addEnvCmdFlags(updateCmd)
bindClientGoFlags(updateCmd)
bindJsonnetFlags(updateCmd)
updateCmd.PersistentFlags().Bool(flagCreate, true, "Create missing resources")
updateCmd.PersistentFlags().Bool(flagSkipGc, false, "Don't perform garbage collection, even with --"+flagGcTag)
updateCmd.PersistentFlags().String(flagGcTag, "", "Add this tag to updated objects, and garbage collect existing objects with this tag and not in config")
updateCmd.PersistentFlags().Bool(flagDryRun, false, "Perform only read-only operations")
}
var updateCmd = &cobra.Command{
Deprecated: "NOTE: Command 'update' is deprecated, use 'apply' instead",
Hidden: true,
Use: "update [<env>|-f <file-or-dir>]",
Short: `[DEPRECATED] Update (or optionally create) Kubernetes resources on the cluster using the
local configuration. Accepts JSON, YAML, or Jsonnet.`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
return fmt.Errorf("'update' takes at most a single argument, that is the name of the environment")
}
flags := cmd.Flags()
var err error
c := kubecfg.ApplyCmd{}
c.Create, err = flags.GetBool(flagCreate)
if err != nil {
return err
}
c.GcTag, err = flags.GetString(flagGcTag)
if err != nil {
return err
}
c.SkipGc, err = flags.GetBool(flagSkipGc)
if err != nil {
return err
}
c.DryRun, err = flags.GetBool(flagDryRun)
if err != nil {
return err
}
cwd, err := os.Getwd()
if err != nil {
return err
}
wd := metadata.AbsPath(cwd)
c.ClientPool, c.Discovery, err = restClientPool(cmd, nil)
if err != nil {
return err
}
c.Namespace, err = namespace()
if err != nil {
return err
}
envSpec, err := parseEnvCmd(cmd, args)
if err != nil {
return err
}
objs, err := expandEnvCmdObjs(cmd, envSpec, wd)
if err != nil {
return err
}
return c.Run(objs, wd)
},
Long: `NOTE: Command 'update' is deprecated, use 'apply' instead.
Update (or optionally create) Kubernetes resources on the cluster using the
local configuration. Use the '--create' flag to control whether we create them
if they do not exist (default: true).
ksonnet applications are accepted, as well as normal JSON, YAML, and Jsonnet
files.`,
Example: `# Create or update all resources described in a ksonnet application, and
# running in the 'dev' environment. Can be used in any subdirectory of the
# application.
ks update dev
# Create or update resources described in a YAML file. Automatically picks up
# the cluster's location from '$KUBECONFIG'.
ks update -f ./pod.yaml
# Update resources described in a YAML file, and running in cluster referred
# to by './kubeconfig'.
ks update --kubeconfig=./kubeconfig -f ./pod.yaml
# Display set of actions we will execute when we run 'update'.
ks update dev --dry-run`,
}
......@@ -30,7 +30,7 @@ var _ = Describe("flags", func() {
BeforeEach(func() {
c = corev1.NewForConfigOrDie(clusterConfigOrDie())
ns = createNsOrDie(c, "kubeflags")
args = []string{"update", "-vv"}
args = []string{"apply", "-vv"}
objs = []runtime.Object{
&v1.ConfigMap{
// Note: no explicit Namespace
......
// +build integration
package integration
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/pkg/api/v1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("update", func() {
var c corev1.CoreV1Interface
var ns string
const cmName = "testcm"
BeforeEach(func() {
c = corev1.NewForConfigOrDie(clusterConfigOrDie())
ns = createNsOrDie(c, "update")
})
AfterEach(func() {
deleteNsOrDie(c, ns)
})
Describe("A simple update", func() {
var cm *v1.ConfigMap
BeforeEach(func() {
cm = &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: cmName},
Data: map[string]string{"foo": "bar"},
}
})
JustBeforeEach(func() {
err := runKubecfgWith([]string{"update", "-vv", "-n", ns}, []runtime.Object{cm})
Expect(err).NotTo(HaveOccurred())
})
Context("With no existing state", func() {
It("should produce expected object", func() {
Expect(c.ConfigMaps(ns).Get("testcm", metav1.GetOptions{})).
To(WithTransform(cmData, HaveKeyWithValue("foo", "bar")))
})
})
Context("With existing object", func() {
BeforeEach(func() {
_, err := c.ConfigMaps(ns).Create(cm)
Expect(err).To(Not(HaveOccurred()))
})
It("should succeed", func() {
Expect(c.ConfigMaps(ns).Get("testcm", metav1.GetOptions{})).
To(WithTransform(cmData, HaveKeyWithValue("foo", "bar")))
})
})
Context("With modified object", func() {
BeforeEach(func() {
otherCm := &v1.ConfigMap{
ObjectMeta: cm.ObjectMeta,
Data: map[string]string{"foo": "not bar"},
}
_, err := c.ConfigMaps(ns).Create(otherCm)
Expect(err).NotTo(HaveOccurred())
})
It("should update the object", func() {
Expect(c.ConfigMaps(ns).Get("testcm", metav1.GetOptions{})).
To(WithTransform(cmData, HaveKeyWithValue("foo", "bar")))
})
})
})
Describe("An update with mixed namespaces", func() {
var ns2 string
BeforeEach(func() {
ns2 = createNsOrDie(c, "update")
})
AfterEach(func() {
deleteNsOrDie(c, ns2)
})
var objs []runtime.Object
BeforeEach(func() {
objs = []runtime.Object{
&v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: "nons"},
},
&v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Namespace: ns, Name: "ns1"},
},
&v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Namespace: ns2, Name: "ns2"},
},
}
})
JustBeforeEach(func() {
err := runKubecfgWith([]string{"update", "-vv", "-n", ns}, objs)
Expect(err).NotTo(HaveOccurred())
})
It("should create objects in the correct namespaces", func() {
Expect(c.ConfigMaps(ns).Get("nons", metav1.GetOptions{})).
NotTo(BeNil())
Expect(c.ConfigMaps(ns).Get("ns1", metav1.GetOptions{})).
NotTo(BeNil())
Expect(c.ConfigMaps(ns2).Get("ns2", metav1.GetOptions{})).
NotTo(BeNil())
})
})
})
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment