本文整理匯總了Golang中k8s/io/kubernetes/pkg/client/unversioned.Client.ConfigMaps方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.ConfigMaps方法的具體用法?Golang Client.ConfigMaps怎麽用?Golang Client.ConfigMaps使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/client/unversioned.Client
的用法示例。
在下文中一共展示了Client.ConfigMaps方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: loadTemplateData
func loadTemplateData(ns string, templateName string, c *k8sclient.Client, oc *oclient.Client) ([]byte, string, error) {
typeOfMaster := util.TypeOfMaster(c)
if typeOfMaster == util.Kubernetes {
catalogName := "catalog-" + templateName
configMap, err := c.ConfigMaps(ns).Get(catalogName)
if err != nil {
return nil, "", err
}
for k, v := range configMap.Data {
if strings.LastIndex(k, ".json") >= 0 {
return []byte(v), "json", nil
}
if strings.LastIndex(k, ".yml") >= 0 || strings.LastIndex(k, ".yaml") >= 0 {
return []byte(v), "yaml", nil
}
}
return nil, "", fmt.Errorf("Could not find a key for the catalog %s which ends with `.json` or `.yml`", catalogName)
} else {
template, err := oc.Templates(ns).Get(templateName)
if err != nil {
return nil, "", err
}
data, err := json.Marshal(template)
return data, "json", err
}
return nil, "", nil
}
示例2: validateConfigMaps
func validateConfigMaps(c *k8sclient.Client, f *cmdutil.Factory) (Result, error) {
ns, _, err := f.DefaultNamespace()
if err != nil {
return Failure, err
}
list, err := c.ConfigMaps(ns).List(api.ListOptions{})
if err == nil && list != nil {
return Success, err
}
return Failure, err
}
示例3: deleteConfigMaps
func deleteConfigMaps(c *k8sclient.Client, ns string, selector labels.Selector) error {
cmps, err := c.ConfigMaps(ns).List(api.ListOptions{LabelSelector: selector})
if err != nil {
return err
}
for _, cm := range cmps.Items {
err := c.ConfigMaps(ns).Delete(cm.Name)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to delete ConfigMap %s", cm.Name))
}
}
return nil
}
示例4: GetConfigMapDetail
// GetConfigMapDetail returns returns detailed information about a config map
func GetConfigMapDetail(client *client.Client, namespace, name string) (*ConfigMapDetail, error) {
log.Printf("Getting details of %s config map in %s namespace", name, namespace)
rawConfigMap, err := client.ConfigMaps(namespace).Get(name)
if err != nil {
return nil, err
}
return getConfigMapDetail(rawConfigMap), nil
}
示例5: updateExposeControllerConfig
func updateExposeControllerConfig(c *k8sclient.Client, ns string, apiserver string, domain string, mini bool, useLoadBalancer bool) {
// create a populate the exposecontroller config map
cfgms := c.ConfigMaps(ns)
_, err := cfgms.Get(exposecontrollerCM)
if err == nil {
util.Infof("\nRecreating configmap %s \n", exposecontrollerCM)
err = cfgms.Delete(exposecontrollerCM)
if err != nil {
printError("\nError deleting ConfigMap: "+exposecontrollerCM, err)
}
}
apiserverAndPort := apiserver
if !strings.Contains(apiserverAndPort, ":") {
apiserverAndPort = apiserverAndPort + ":8443"
}
domainData := "domain: " + domain + "\n"
exposeData := exposeRule + ": " + defaultExposeRule(c, mini, useLoadBalancer) + "\n"
apiserverData := "apiserver: " + apiserverAndPort + "\n"
configFile := map[string]string{
"config.yml": domainData + exposeData + apiserverData,
}
configMap := kapi.ConfigMap{
ObjectMeta: kapi.ObjectMeta{
Name: exposecontrollerCM,
Labels: map[string]string{
"provider": "fabric8",
},
},
Data: configFile,
}
_, err = cfgms.Create(&configMap)
if err != nil {
printError("Failed to create ConfigMap: "+exposecontrollerCM, err)
}
}
示例6: installTemplates
func installTemplates(kc *k8sclient.Client, c *oclient.Client, fac *cmdutil.Factory, v string, templateUrl string, dockerRegistry string, arch string, domain string) error {
ns, _, err := fac.DefaultNamespace()
if err != nil {
util.Fatal("No default namespace")
return err
}
templates := c.Templates(ns)
util.Infof("Downloading templates for version %v\n", v)
uri := fmt.Sprintf(templateUrl, v)
resp, err := http.Get(uri)
if err != nil {
util.Fatalf("Cannot get fabric8 template to deploy: %v", err)
}
defer resp.Body.Close()
tmpFileName := "/tmp/fabric8-template-distros.tar.gz"
t, err := os.OpenFile(tmpFileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)
if err != nil {
return err
}
defer t.Close()
_, err = io.Copy(t, resp.Body)
if err != nil {
return err
}
r, err := zip.OpenReader(tmpFileName)
if err != nil {
return err
}
defer r.Close()
typeOfMaster := util.TypeOfMaster(kc)
for _, f := range r.File {
mode := f.FileHeader.Mode()
if mode.IsDir() {
continue
}
rc, err := f.Open()
if err != nil {
return err
}
defer rc.Close()
util.Infof("Loading template %s\n", f.Name)
jsonData, err := ioutil.ReadAll(rc)
if err != nil {
util.Fatalf("Cannot get fabric8 template to deploy: %v", err)
}
jsonData, err = adaptFabric8ImagesInResourceDescriptor(jsonData, dockerRegistry, arch)
if err != nil {
util.Fatalf("Cannot append docker registry: %v", err)
}
jsonData = replaceDomain(jsonData, domain, ns, typeOfMaster)
var v1tmpl tapiv1.Template
err = json.Unmarshal(jsonData, &v1tmpl)
if err != nil {
util.Fatalf("Cannot get fabric8 template to deploy: %v", err)
}
var tmpl tapi.Template
err = api.Scheme.Convert(&v1tmpl, &tmpl)
if err != nil {
util.Fatalf("Cannot get fabric8 template to deploy: %v", err)
return err
}
name := tmpl.ObjectMeta.Name
if typeOfMaster == util.Kubernetes {
appName := name
name = "catalog-" + appName
// lets install ConfigMaps for the templates
// TODO should the name have a prefix?
configmap := api.ConfigMap{
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: ns,
Labels: map[string]string{
"name": appName,
"provider": "fabric8.io",
"kind": "catalog",
},
},
Data: map[string]string{
name + ".json": string(jsonData),
},
}
configmaps := kc.ConfigMaps(ns)
_, err = configmaps.Get(name)
if err == nil {
err = configmaps.Delete(name)
if err != nil {
util.Errorf("Could not delete configmap %s due to: %v\n", name, err)
//.........這裏部分代碼省略.........
示例7: DoTestConfigMap
func DoTestConfigMap(t *testing.T, client *client.Client) {
ns := "ns"
cfg := api.ConfigMap{
ObjectMeta: api.ObjectMeta{
Name: "configmap",
Namespace: ns,
},
Data: map[string]string{
"data-1": "value-1",
"data-2": "value-2",
"data-3": "value-3",
},
}
if _, err := client.ConfigMaps(cfg.Namespace).Create(&cfg); err != nil {
t.Errorf("unable to create test configMap: %v", err)
}
defer deleteConfigMapOrErrorf(t, client, cfg.Namespace, cfg.Name)
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "XXX",
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "fake-name",
Image: "fakeimage",
Env: []api.EnvVar{
{
Name: "CONFIG_DATA_1",
ValueFrom: &api.EnvVarSource{
ConfigMapKeyRef: &api.ConfigMapKeySelector{
LocalObjectReference: api.LocalObjectReference{
Name: "configmap",
},
Key: "data-1",
},
},
},
{
Name: "CONFIG_DATA_2",
ValueFrom: &api.EnvVarSource{
ConfigMapKeyRef: &api.ConfigMapKeySelector{
LocalObjectReference: api.LocalObjectReference{
Name: "configmap",
},
Key: "data-2",
},
},
}, {
Name: "CONFIG_DATA_3",
ValueFrom: &api.EnvVarSource{
ConfigMapKeyRef: &api.ConfigMapKeySelector{
LocalObjectReference: api.LocalObjectReference{
Name: "configmap",
},
Key: "data-3",
},
},
},
},
},
},
},
}
pod.ObjectMeta.Name = "uses-configmap"
if _, err := client.Pods(ns).Create(pod); err != nil {
t.Errorf("Failed to create pod: %v", err)
}
defer deletePodOrErrorf(t, client, ns, pod.Name)
}
示例8: deleteConfigMapOrErrorf
func deleteConfigMapOrErrorf(t *testing.T, c *client.Client, ns, name string) {
if err := c.ConfigMaps(ns).Delete(name); err != nil {
t.Errorf("unable to delete ConfigMap %v: %v", name, err)
}
}
示例9: mapWatchFunc
func mapWatchFunc(c *client.Client, ns string) func(options api.ListOptions) (watch.Interface, error) {
return func(options api.ListOptions) (watch.Interface, error) {
return c.ConfigMaps(ns).Watch(options)
}
}
示例10: mapListFunc
func mapListFunc(c *client.Client, ns string) func(api.ListOptions) (runtime.Object, error) {
return func(opts api.ListOptions) (runtime.Object, error) {
return c.ConfigMaps(ns).List(opts)
}
}
示例11:
By("Generate event list options")
selector := fields.Set{
"involvedObject.kind": "Node",
"involvedObject.name": node.Name,
"involvedObject.namespace": api.NamespaceAll,
"source": source,
}.AsSelector()
eventListOptions = api.ListOptions{FieldSelector: selector}
By("Create the test log file")
tmpDir = "/tmp/" + name
cmd := fmt.Sprintf("mkdir %s; > %s/%s", tmpDir, tmpDir, logFile)
Expect(framework.IssueSSHCommand(cmd, framework.TestContext.Provider, node)).To(Succeed())
By("Create config map for the node problem detector")
_, err = c.ConfigMaps(ns).Create(&api.ConfigMap{
ObjectMeta: api.ObjectMeta{
Name: configName,
},
Data: map[string]string{configFile: config},
})
Expect(err).NotTo(HaveOccurred())
By("Create the node problem detector")
_, err = c.Pods(ns).Create(&api.Pod{
ObjectMeta: api.ObjectMeta{
Name: name,
},
Spec: api.PodSpec{
NodeName: node.Name,
SecurityContext: &api.PodSecurityContext{HostNetwork: true},
Volumes: []api.Volume{
{
Name: configVolume,
VolumeSource: api.VolumeSource{
示例12: installTemplates
//.........這裏部分代碼省略.........
if len(name) <= 0 {
template = false
name = f.Name
idx := strings.LastIndex(name, "/")
if idx > 0 {
name = name[idx+1:]
}
idx = strings.Index(name, ".")
if idx > 0 {
name = name[0:idx]
}
}
if typeOfMaster == util.Kubernetes {
appName := name
name = "catalog-" + appName
// lets install ConfigMaps for the templates
// TODO should the name have a prefix?
configmap := api.ConfigMap{
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: ns,
Labels: map[string]string{
"name": appName,
"provider": "fabric8.io",
"kind": "catalog",
},
},
Data: map[string]string{
name + configMapKeySuffix: string(jsonData),
},
}
configmaps := kc.ConfigMaps(ns)
_, err = configmaps.Get(name)
if err == nil {
err = configmaps.Delete(name)
if err != nil {
util.Errorf("Could not delete configmap %s due to: %v\n", name, err)
}
}
_, err = configmaps.Create(&configmap)
if err != nil {
util.Fatalf("Failed to create configmap %v", err)
return err
}
} else {
if !template {
templateName := name
var v1List v1.List
if configMapKeySuffix == ".json" {
err = json.Unmarshal(jsonData, &v1List)
} else {
err = yaml.Unmarshal(jsonData, &v1List)
}
if err != nil {
util.Fatalf("Cannot unmarshal List %s to deploy. error: %v\ntemplate: %s", templateName, err, string(jsonData))
}
if len(v1List.Items) == 0 {
// lets check if its an RC / ReplicaSet or something
_, groupVersionKind, err := api.Codecs.UniversalDeserializer().Decode(jsonData, nil, nil)
if err != nil {
printResult(templateName, Failure, err)
} else {
kind := groupVersionKind.Kind
util.Infof("Processing resource of kind: %s version: %s\n", kind, groupVersionKind.Version)