本文整理匯總了Golang中github.com/openshift/origin/pkg/client.Client.Templates方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Templates方法的具體用法?Golang Client.Templates怎麽用?Golang Client.Templates使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/origin/pkg/client.Client
的用法示例。
在下文中一共展示了Client.Templates方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: runTemplate
func runTemplate(c *k8sclient.Client, oc *oclient.Client, appToRun string, ns string, domain string, apiserver string, pv bool) {
util.Info("\n\nInstalling: ")
util.Successf("%s\n\n", appToRun)
typeOfMaster := util.TypeOfMaster(c)
if typeOfMaster == util.Kubernetes {
jsonData, format, err := loadTemplateData(ns, appToRun, c, oc)
if err != nil {
printError("Failed to load app "+appToRun, err)
}
createTemplate(jsonData, format, appToRun, ns, domain, apiserver, c, oc, pv)
} else {
tmpl, err := oc.Templates(ns).Get(appToRun)
if err != nil {
printError("Failed to load template "+appToRun, err)
}
util.Infof("Loaded template with %d objects", len(tmpl.Objects))
processTemplate(tmpl, ns, domain, apiserver)
objectCount := len(tmpl.Objects)
util.Infof("Creating "+appToRun+" template resources from %d objects\n", objectCount)
for _, o := range tmpl.Objects {
err = processItem(c, oc, &o, ns, pv)
}
}
}
示例3: getTemplates
func getTemplates(c *oclient.Client, ns string) *tapi.TemplateList {
templates, err := c.Templates(ns).List(api.ListOptions{})
if err != nil {
util.Fatalf("No Templates found in namespace %s\n", ns)
}
return templates
}
示例4: getTemplates
func getTemplates(c *oclient.Client, ns string) *tapi.TemplateList {
rc, err := c.Templates(ns).List(labels.Everything(), fields.Everything())
if err != nil {
util.Fatalf("No Templates found in namespace %s\n", ns)
}
return rc
}
示例5: validateTemplates
func validateTemplates(c *oclient.Client, f *cmdutil.Factory) (Result, error) {
ns, _, err := f.DefaultNamespace()
if err != nil {
return Failure, err
}
rc, err := c.Templates(ns).Get("management")
if rc != nil {
return Success, err
}
return Failure, err
}
示例6: downloadTemplateDockerImages
func downloadTemplateDockerImages(cmd *cobra.Command, ns string, c *oclient.Client, fac *cmdutil.Factory, name string) (Result, error) {
rc, err := c.Templates(ns).Get(name)
if err != nil {
util.Fatalf("No Template %s found in namespace %s\n", name, ns)
}
// convert Template.Objects to Kubernetes resources
_ = runtime.DecodeList(rc.Objects, api.Scheme, runtime.UnstructuredJSONScheme)
for _, rc := range rc.Objects {
switch rc := rc.(type) {
case *api.ReplicationController:
for _, container := range rc.Spec.Template.Spec.Containers {
err = downloadDockerImage(container.Image)
if err != nil {
return Failure, err
}
}
}
}
return Success, nil
}
示例7: 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)
//.........這裏部分代碼省略.........
示例8: installTemplates
func installTemplates(c *oclient.Client, fac *cmdutil.Factory, v string, templateUrl 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()
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)
}
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
_, err = templates.Get(name)
if err == nil {
err = templates.Delete(name)
if err != nil {
util.Errorf("Could not delete template %s due to: %v\n", name, err)
}
}
_, err = templates.Create(&tmpl)
if err != nil {
util.Fatalf("Failed to create template %v", err)
return err
}
}
return nil
}
示例9: 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)
uri := fmt.Sprintf(templateUrl, v)
util.Infof("Downloading apps from: %v\n", uri)
resp, err := http.Get(uri)
if err != nil {
util.Fatalf("Cannot get fabric8 template to deploy: %v", err)
}
defer resp.Body.Close()
tmpFileName := path.Join(os.TempDir(), "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()
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
lowerName := strings.ToLower(f.Name)
// if the folder starts with kubernetes/ or openshift/ then lets filter based on the cluster:
if strings.HasPrefix(lowerName, "kubernetes/") && typeOfMaster != util.Kubernetes {
//util.Info("Ignoring as on openshift!")
continue
}
if strings.HasPrefix(lowerName, "openshift/") && typeOfMaster == util.Kubernetes {
//util.Info("Ignoring as on kubernetes!")
continue
}
configMapKeySuffix := ".json"
if strings.HasSuffix(lowerName, ".yml") || strings.HasSuffix(lowerName, ".yaml") {
configMapKeySuffix = ".yml"
err = yaml.Unmarshal(jsonData, &v1tmpl)
} else if strings.HasSuffix(lowerName, ".json") {
err = json.Unmarshal(jsonData, &v1tmpl)
} else {
continue
}
if err != nil {
util.Fatalf("Cannot unmarshall the fabric8 template %s to deploy: %v", f.Name, err)
}
util.Infof("Loading template %s\n", f.Name)
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
template := true
if len(name) <= 0 {
template = false
name = f.Name
idx := strings.LastIndex(name, "/")
if idx > 0 {
//.........這裏部分代碼省略.........