本文整理匯總了Golang中github.com/fabric8io/gofabric8/util.Errorf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Errorf函數的具體用法?Golang Errorf怎麽用?Golang Errorf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Errorf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: downloadKubernetes
func downloadKubernetes(d downloadProperties) (err error) {
os := runtime.GOOS
arch := runtime.GOARCH
if runtime.GOOS == "windows" {
d.kubeBinary += ".exe"
}
_, err = exec.LookPath(d.kubeBinary)
if err != nil {
latestVersion, err := getLatestVersionFromGitHub(d.kubeDistroOrg, d.kubeDistroRepo)
if err != nil {
util.Errorf("Unable to get latest version for %s/%s %v", d.kubeDistroOrg, d.kubeDistroRepo, err)
return err
}
kubeURL := fmt.Sprintf(d.downloadURL+d.kubeDistroRepo+"/releases/"+d.extraPath+"v%s/%s-%s-%s", latestVersion, d.kubeDistroRepo, os, arch)
if runtime.GOOS == "windows" {
kubeURL += ".exe"
}
util.Infof("Downloading %s...\n", kubeURL)
fullPath := filepath.Join(getFabric8BinLocation(), d.kubeBinary)
err = downloadFile(fullPath, kubeURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, kubeURL, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)
} else {
util.Successf("%s is already available on your PATH\n", d.kubeBinary)
}
return nil
}
示例2: openService
func openService(ns string, serviceName string, c *k8sclient.Client, printURL bool, retry bool) {
if retry {
if err := RetryAfter(40, func() error { return CheckService(ns, serviceName, c) }, 10*time.Second); err != nil {
util.Errorf("Could not find finalized endpoint being pointed to by %s: %v", serviceName, err)
os.Exit(1)
}
}
svcs, err := c.Services(ns).List(kubeApi.ListOptions{})
if err != nil {
util.Errorf("No services found %v\n", err)
}
found := false
for _, service := range svcs.Items {
if serviceName == service.Name {
url := service.ObjectMeta.Annotations[exposeURLAnnotation]
if printURL {
util.Successf("%s\n", url)
} else {
util.Successf("\nOpening URL %s\n", url)
browser.OpenURL(url)
}
found = true
break
}
}
if !found {
util.Errorf("No service %s in namespace %s\n", serviceName, ns)
}
}
示例3: downloadFunktion
func downloadFunktion() (err error) {
os := runtime.GOOS
arch := runtime.GOARCH
_, err = exec.LookPath(funktion)
if err != nil {
latestVersion, err := getLatestVersionFromGitHub(fabric8io, funktionOperator)
if err != nil {
util.Errorf("Unable to get latest version for %s/%s %v", fabric8io, funktionOperator, err)
return err
}
funktionURL := fmt.Sprintf(githubURL+fabric8io+"/"+funktionOperator+"/releases/download/v%s/%s-%s-%s", latestVersion, funktionOperator, os, arch)
if runtime.GOOS == "windows" {
funktionURL += ".exe"
}
util.Infof("Downloading %s...\n", funktionURL)
fullPath := filepath.Join(getFabric8BinLocation(), funktion)
err = downloadFile(fullPath, funktionURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, funktionURL, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)
} else {
util.Successf("%s is already available on your PATH\n", funktion)
}
return nil
}
示例4: downloadKubernetes
func downloadKubernetes(isMinishift bool) (err error) {
os := runtime.GOOS
arch := runtime.GOARCH
if isMinishift {
kubeDistroOrg = minishiftOwner
kubeDistroRepo = minishift
kubeDownloadURL = minishiftDownloadURL
downloadPath = "download/"
kubeBinary = minishift
}
_, err = exec.LookPath(kubeBinary)
if err != nil {
latestVersion, err := getLatestVersionFromGitHub(kubeDistroOrg, kubeDistroRepo)
if err != nil {
util.Errorf("Unable to get latest version for %s/%s %v", kubeDistroOrg, kubeDistroRepo, err)
return err
}
kubeURL := fmt.Sprintf(kubeDownloadURL+kubeDistroRepo+"/releases/"+downloadPath+"v%s/%s-%s-%s", latestVersion, kubeDistroRepo, os, arch)
util.Infof("Downloading %s...", kubeURL)
err = downloadFile(writeFileLocation+kubeBinary, kubeURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", writeFileLocation+kubeBinary, kubeURL, err)
return err
}
util.Successf("Downloaded %s\n", kubeBinary)
} else {
util.Successf("%s is already available on your PATH\n", kubeBinary)
}
return nil
}
示例5: createRoutesForDomain
func createRoutesForDomain(ns string, domain string, c *k8sclient.Client, oc *oclient.Client, fac *cmdutil.Factory) error {
rc, err := c.Services(ns).List(labels.Everything())
if err != nil {
util.Errorf("Failed to load services in namespace %s with error %v", ns, err)
return err
}
items := rc.Items
for _, service := range items {
// TODO use the external load balancer as a way to know if we should create a route?
name := service.ObjectMeta.Name
if name != "kubernetes" {
routes := oc.Routes(ns)
_, err = routes.Get(name)
if err != nil {
hostName := name + "." + domain
route := rapi.Route{
ObjectMeta: kapi.ObjectMeta{
Name: name,
},
Host: hostName,
ServiceName: name,
}
// lets create the route
_, err = routes.Create(&route)
if err != nil {
util.Errorf("Failed to create the route %s with error %v", name, err)
return err
}
}
}
}
return nil
}
示例6: deployFabric8SASSecurityContextConstraints
func deployFabric8SASSecurityContextConstraints(c *k8sclient.Client, f *cmdutil.Factory, ns string) (Result, error) {
name := Fabric8SASSCC
scc := kapi.SecurityContextConstraints{
ObjectMeta: kapi.ObjectMeta{
Name: name,
},
SELinuxContext: kapi.SELinuxContextStrategyOptions{
Type: kapi.SELinuxStrategyRunAsAny,
},
RunAsUser: kapi.RunAsUserStrategyOptions{
Type: kapi.RunAsUserStrategyRunAsAny,
},
Groups: []string{"system:serviceaccounts"},
Volumes: []kapi.FSType{kapi.FSTypeGitRepo, kapi.FSTypeConfigMap, kapi.FSTypeSecret, kapi.FSTypeEmptyDir},
}
_, err := c.SecurityContextConstraints().Get(name)
if err == nil {
err = c.SecurityContextConstraints().Delete(name)
if err != nil {
return Failure, err
}
}
_, err = c.SecurityContextConstraints().Create(&scc)
if err != nil {
util.Errorf("Cannot create SecurityContextConstraints: %v\n", err)
util.Errorf("Failed to create SecurityContextConstraints %v in namespace %s: %v\n", scc, ns, err)
return Failure, err
}
util.Infof("SecurityContextConstraints %s is setup correctly\n", name)
return Success, err
}
示例7: createPV
func createPV(c *k8sclient.Client, ns string, pvcNames []string, sshCommand string) (Result, error) {
for _, pvcName := range pvcNames {
hostPath := path.Join("/data", ns, pvcName)
nsPvcName := ns + "-" + pvcName
pvs := c.PersistentVolumes()
rc, err := pvs.List(api.ListOptions{})
if err != nil {
util.Errorf("Failed to load PersistentVolumes with error %v\n", err)
}
items := rc.Items
for _, volume := range items {
if nsPvcName == volume.ObjectMeta.Name {
util.Infof("Already created PersistentVolumes for %s\n", nsPvcName)
}
}
// we no longer need to do chmod on kubernetes as we have init containers now
typeOfMaster := util.TypeOfMaster(c)
if typeOfMaster != util.Kubernetes || len(sshCommand) > 0 {
err = configureHostPathVolume(c, ns, hostPath, sshCommand)
if err != nil {
util.Errorf("Failed to configure the host path %s with error %v\n", hostPath, err)
}
}
// lets create a new PV
util.Infof("PersistentVolume name %s will be created on host path %s\n", nsPvcName, hostPath)
pv := api.PersistentVolume{
ObjectMeta: api.ObjectMeta{
Name: nsPvcName,
},
Spec: api.PersistentVolumeSpec{
Capacity: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("1Gi"),
},
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
PersistentVolumeSource: api.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{Path: hostPath},
},
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle,
},
}
_, err = pvs.Create(&pv)
if err != nil {
util.Errorf("Failed to create PersistentVolume %s at %s with error %v\n", nsPvcName, hostPath, err)
}
}
return Success, nil
}
示例8: deployFabric8SecurityContextConstraints
func deployFabric8SecurityContextConstraints(c *k8sclient.Client, f *cmdutil.Factory, ns string) (Result, error) {
name := Fabric8SCC
if ns != "default" {
name += "-" + ns
}
var priority int32 = 10
scc := kapi.SecurityContextConstraints{
ObjectMeta: kapi.ObjectMeta{
Name: name,
},
Priority: &priority,
AllowPrivilegedContainer: true,
AllowHostNetwork: true,
AllowHostPorts: true,
Volumes: []kapi.FSType{kapi.FSTypeAll},
SELinuxContext: kapi.SELinuxContextStrategyOptions{
Type: kapi.SELinuxStrategyRunAsAny,
},
RunAsUser: kapi.RunAsUserStrategyOptions{
Type: kapi.RunAsUserStrategyRunAsAny,
},
Users: []string{
"system:serviceaccount:openshift-infra:build-controller",
"system:serviceaccount:" + ns + ":default",
"system:serviceaccount:" + ns + ":fabric8",
"system:serviceaccount:" + ns + ":gerrit",
"system:serviceaccount:" + ns + ":jenkins",
"system:serviceaccount:" + ns + ":router",
"system:serviceaccount:" + ns + ":registry",
"system:serviceaccount:" + ns + ":gogs",
"system:serviceaccount:" + ns + ":fluentd",
},
Groups: []string{bootstrappolicy.ClusterAdminGroup, bootstrappolicy.NodesGroup},
}
_, err := c.SecurityContextConstraints().Get(name)
if err == nil {
err = c.SecurityContextConstraints().Delete(name)
if err != nil {
return Failure, err
}
}
_, err = c.SecurityContextConstraints().Create(&scc)
if err != nil {
util.Errorf("Cannot create SecurityContextConstraints: %v\n", err)
util.Errorf("Failed to create SecurityContextConstraints %v in namespace %s: %v\n", scc, ns, err)
return Failure, err
}
util.Infof("SecurityContextConstraints %s is setup correctly\n", name)
return Success, err
}
示例9: createPersistentVolume
func createPersistentVolume(cmd *cobra.Command, ns string, c *k8sclient.Client, fac *cmdutil.Factory) (Result, error) {
flags := cmd.Flags()
hostPath := flags.Lookup(hostPathFlag).Value.String()
name := flags.Lookup(nameFlag).Value.String()
pvs := c.PersistentVolumes()
rc, err := pvs.List(labels.Everything(), fields.Everything())
if err != nil {
util.Errorf("Failed to load PersistentVolumes with error %v", err)
return Failure, err
}
items := rc.Items
for _, volume := range items {
// TODO use the external load balancer as a way to know if we should create a route?
vname := volume.ObjectMeta.Name
if vname == name {
util.Infof("Already created PersistentVolumes for %s\n", name)
return Success, nil
}
}
if hostPath == "" {
return missingFlag(cmd, hostPathFlag)
}
if confirmAction(flags) == false {
return Failure, nil
}
// lets create a new PV
util.Infof("PersistentVolume name %s will be created on host path %s\n", name, hostPath)
pv := api.PersistentVolume{
ObjectMeta: api.ObjectMeta{
Name: name,
},
Spec: api.PersistentVolumeSpec{
Capacity: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("100G"),
},
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteMany},
PersistentVolumeSource: api.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{Path: hostPath},
},
},
}
_, err = pvs.Create(&pv)
if err != nil {
util.Errorf("Failed to create PersistentVolume %s at %s with error %v", name, hostPath, err)
return Failure, err
}
return Success, nil
}
示例10: install
func install(isMinishift bool) {
writeFileLocation := getFabric8BinLocation()
err := os.MkdirAll(writeFileLocation, 0700)
if err != nil {
util.Errorf("Unable to create directory to download files %s %v\n", writeFileLocation, err)
}
err = downloadDriver()
if err != nil {
util.Warnf("Unable to download driver %v\n", err)
}
d := getDownloadProperties(isMinishift)
err = downloadKubernetes(d)
if err != nil {
util.Warnf("Unable to download kubernetes distro %v\n", err)
}
err = downloadKubectlClient()
if err != nil {
util.Warnf("Unable to download client %v\n", err)
}
if d.isMiniShift {
err = downloadOpenShiftClient()
if err != nil {
util.Warnf("Unable to download client %v\n", err)
}
}
}
示例11: downloadClient
func downloadClient(isMinishift bool) (err error) {
os := runtime.GOOS
arch := runtime.GOARCH
_, err = exec.LookPath(kubectl)
if err != nil {
latestVersion, err := getLatestVersionFromGitHub(kubeDistroOrg, kubernetes)
if err != nil {
return fmt.Errorf("Unable to get latest version for %s/%s %v", kubeDistroOrg, kubernetes, err)
}
if isMinishift {
clientBinary = oc
return fmt.Errorf("Openshift client download not yet supported")
}
clientURL := fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/v%s/bin/%s/%s/%s", latestVersion, os, arch, kubectl)
util.Infof("Downloading %s...", clientURL)
err = downloadFile(writeFileLocation+clientBinary, clientURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", writeFileLocation+clientBinary, clientURL, err)
return err
}
util.Successf("Downloaded %s\n", clientBinary)
} else {
util.Successf("%s is already available on your PATH\n", clientBinary)
}
return nil
}
示例12: printSummary
func printSummary(typeOfMaster util.MasterType, externalNodeName string, ns string, domain string, c *k8sclient.Client) {
util.Info("\n")
util.Info("-------------------------\n")
util.Info("\n")
clientType := getClientTypeName(typeOfMaster)
if externalNodeName != "" {
util.Info("Deploying ingress controller on node ")
util.Successf("%s", externalNodeName)
util.Info(" use its external ip when configuring your wildcard DNS.\n")
util.Infof("To change node move the label: `%s label node %s %s- && %s label node $YOUR_NEW_NODE %s=true`\n", clientType, externalNodeName, externalIPLabel, clientType, externalIPLabel)
util.Info("\n")
}
util.Info("Default GOGS admin username/password = ")
util.Successf("%s/%s\n", gogsDefaultUsername, gogsDefaultPassword)
util.Info("\n")
found, _ := checkIfPVCsPending(c, ns)
if found {
util.Errorf("There are pending PersistentVolumeClaims\n")
util.Infof("If using a local cluster run `gofabric8 volumes` to create missing HostPath volumes\n")
util.Infof("If using a remote cloud then enable dynamic persistence with a StorageClass. For details see http://fabric8.io/guide/getStarted/persistence.html\n")
util.Info("\n")
}
util.Infof("Downloading images and waiting to open the fabric8 console...\n")
util.Info("\n")
util.Info("-------------------------\n")
}
示例13: addIngressInfraLabel
func addIngressInfraLabel(c *k8sclient.Client, ns string) string {
nodeClient := c.Nodes()
nodes, err := nodeClient.List(api.ListOptions{})
if err != nil {
util.Errorf("\nUnable to find any nodes: %s\n", err)
}
changed := false
hasExistingExposeIPLabel, externalNodeName := hasExistingLabel(nodes, externalIPLabel)
if externalNodeName != "" {
return externalNodeName
}
if !hasExistingExposeIPLabel && len(nodes.Items) > 0 {
for _, node := range nodes.Items {
if !node.Spec.Unschedulable {
changed = addLabelIfNotExist(&node.ObjectMeta, externalIPLabel, "true")
if changed {
_, err = nodeClient.Update(&node)
if err != nil {
printError("Failed to label node with ", err)
}
return node.Name
}
}
}
}
if !changed && !hasExistingExposeIPLabel {
util.Warnf("Unable to add label for ingress controller to run on a specific node, please add manually: kubectl label node [your node name] %s=true", externalIPLabel)
}
return ""
}
示例14: resolveBinaryLocation
// lets find the executable on the PATH or in the fabric8 directory
func resolveBinaryLocation(executable string) string {
path, err := exec.LookPath(executable)
if err != nil || fileNotExist(path) {
home := os.Getenv("HOME")
if home == "" {
util.Error("No $HOME environment variable found")
}
writeFileLocation := getFabric8BinLocation()
// lets try in the fabric8 folder
path = filepath.Join(writeFileLocation, executable)
if fileNotExist(path) {
path = executable
// lets try in the folder where we found the gofabric8 executable
folder, err := osext.ExecutableFolder()
if err != nil {
util.Errorf("Failed to find executable folder: %v\n", err)
} else {
path = filepath.Join(folder, executable)
if fileNotExist(path) {
util.Infof("Could not find executable at %v\n", path)
path = executable
}
}
}
}
util.Infof("using the executable %s\n", path)
return path
}
示例15: downloadKubectlClient
func downloadKubectlClient() (err error) {
os := runtime.GOOS
arch := runtime.GOARCH
kubectlBinary := kubectl
if runtime.GOOS == "windows" {
kubectlBinary += ".exe"
}
_, err = exec.LookPath(kubectlBinary)
if err != nil {
latestVersion, err := getLatestVersionFromGitHub(kubernetes, kubernetes)
if err != nil {
return fmt.Errorf("Unable to get latest version for %s/%s %v", kubernetes, kubernetes, err)
}
clientURL := fmt.Sprintf("https://storage.googleapis.com/kubernetes-release/release/v%s/bin/%s/%s/%s", latestVersion, os, arch, kubectlBinary)
util.Infof("Downloading %s...\n", clientURL)
fullPath := filepath.Join(getFabric8BinLocation(), kubectlBinary)
err = downloadFile(fullPath, clientURL)
if err != nil {
util.Errorf("Unable to download file %s/%s %v", fullPath, clientURL, err)
return err
}
util.Successf("Downloaded %s\n", fullPath)
} else {
util.Successf("%s is already available on your PATH\n", kubectlBinary)
}
return nil
}