本文整理匯總了Golang中github.com/fabric8io/gofabric8/util.Infof函數的典型用法代碼示例。如果您正苦於以下問題:Golang Infof函數的具體用法?Golang Infof怎麽用?Golang Infof使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Infof函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: ensureNamespaceExists
func ensureNamespaceExists(c *k8sclient.Client, oc *oclient.Client, ns string) error {
typeOfMaster := util.TypeOfMaster(c)
if typeOfMaster == util.Kubernetes {
nss := c.Namespaces()
_, err := nss.Get(ns)
if err != nil {
// lets assume it doesn't exist!
util.Infof("Creating new Namespace: %s\n", ns)
entity := kapi.Namespace{
ObjectMeta: kapi.ObjectMeta{Name: ns},
}
_, err := nss.Create(&entity)
return err
}
} else {
_, err := oc.Projects().Get(ns)
if err != nil {
// lets assume it doesn't exist!
request := projectapi.ProjectRequest{
ObjectMeta: kapi.ObjectMeta{Name: ns},
}
util.Infof("Creating new Project: %s\n", ns)
_, err := oc.ProjectRequests().Create(&request)
return err
}
}
return nil
}
示例3: createMissingPVs
func createMissingPVs(c *k8sclient.Client, ns string) {
found, pvcs, pendingClaimNames := findPendingPVs(c, ns)
if found {
sshCommand := ""
createPV(c, ns, pendingClaimNames, sshCommand)
items := pvcs.Items
for _, item := range items {
status := item.Status.Phase
if status == api.ClaimPending || status == api.ClaimLost {
err := c.PersistentVolumeClaims(ns).Delete(item.ObjectMeta.Name)
if err != nil {
util.Infof("Error deleting PVC %s\n", item.ObjectMeta.Name)
} else {
util.Infof("Recreating PVC %s\n", item.ObjectMeta.Name)
c.PersistentVolumeClaims(ns).Create(&api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{
Name: item.ObjectMeta.Name,
Namespace: ns,
},
Spec: api.PersistentVolumeClaimSpec{
VolumeName: ns + "-" + item.ObjectMeta.Name,
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("1Gi"),
},
},
},
})
}
}
}
}
}
示例4: 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")
}
示例5: 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)
}
}
}
示例6: NewCmdVolumes
func NewCmdVolumes(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "volumes",
Short: "Creates a persisent volume for any pending persistance volume claims",
Long: `Creates a persisent volume for any pending persistance volume claims`,
PreRun: func(cmd *cobra.Command, args []string) {
showBanner()
},
Run: func(cmd *cobra.Command, args []string) {
c, _ := client.NewClient(f)
ns, _, err := f.DefaultNamespace()
if err != nil {
util.Fatal("No default namespace")
} else {
found, pvcs, pendingClaimNames := findPendingPVs(c, ns)
if found {
sshCommand := cmd.Flags().Lookup(sshCommandFlag).Value.String()
createPV(c, ns, pendingClaimNames, sshCommand)
items := pvcs.Items
for _, item := range items {
name := item.ObjectMeta.Name
status := item.Status.Phase
if status == api.ClaimPending || status == api.ClaimLost {
err = c.PersistentVolumeClaims(ns).Delete(name)
if err != nil {
util.Infof("Error deleting PVC %s\n", name)
} else {
util.Infof("Recreating PVC %s\n", name)
c.PersistentVolumeClaims(ns).Create(&api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: ns,
},
Spec: api.PersistentVolumeClaimSpec{
VolumeName: ns + "-" + name,
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("1Gi"),
},
},
},
})
}
}
}
}
}
},
}
cmd.PersistentFlags().String(sshCommandFlag, "", "the ssh command to run commands inside the VM of the single node cluster")
return cmd
}
示例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: generateSshKeyPair
func generateSshKeyPair(logGeneratedKeys string) Keypair {
priv, err := rsa.GenerateKey(rand.Reader, 2014)
if err != nil {
util.Fatalf("Error generating key", err)
}
err = priv.Validate()
if err != nil {
util.Fatalf("Validation failed.", err)
}
// Get der format. priv_der []byte
priv_der := x509.MarshalPKCS1PrivateKey(priv)
// pem.Block
// blk pem.Block
priv_blk := pem.Block{
Type: "RSA PRIVATE KEY",
Headers: nil,
Bytes: priv_der,
}
// Resultant private key in PEM format.
// priv_pem string
priv_pem := string(pem.EncodeToMemory(&priv_blk))
if logGeneratedKeys == "true" {
util.Infof(priv_pem)
}
// Public Key generation
pub := priv.PublicKey
pub_der, err := x509.MarshalPKIXPublicKey(&pub)
if err != nil {
util.Fatalf("Failed to get der format for PublicKey.", err)
}
pub_blk := pem.Block{
Type: "PUBLIC KEY",
Headers: nil,
Bytes: pub_der,
}
pub_pem := string(pem.EncodeToMemory(&pub_blk))
if logGeneratedKeys == "true" {
util.Infof(pub_pem)
}
return Keypair{
pub: []byte(pub_pem),
priv: []byte(priv_pem),
}
}
示例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: 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
}
示例11: 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
}
示例12: waitForDeployment
func waitForDeployment(c *k8sclient.Client, ns string, name string, sleepMillis time.Duration) error {
util.Infof("Deployment %s waiting for it to be ready...\n", name)
for {
deployment, err := c.Extensions().Deployments(ns).Get(name)
if err != nil {
return err
}
available := deployment.Status.AvailableReplicas
unavailable := deployment.Status.UnavailableReplicas
if unavailable == 0 && available > 0 {
util.Infof("DeploymentConfig %s now has %d available replicas\n", name, available)
return nil
}
time.Sleep(sleepMillis)
}
}
示例13: copyEndpoints
func copyEndpoints(c *k8sclient.Client, fromNs string, toNs string, names []string) error {
var answer error
for _, name := range names {
item, err := c.Endpoints(fromNs).Get(name)
if err != nil {
util.Warnf("No endpoint called %s found in namespace %s", name, fromNs)
answer = err
}
name := item.Name
objectMeta := item.ObjectMeta
current, err := c.Endpoints(toNs).Get(name)
if current == nil || err != nil {
// lets create the endpoint
newEndpoints := &api.Endpoints{
ObjectMeta: api.ObjectMeta{
Name: name,
Labels: objectMeta.Labels,
Annotations: objectMeta.Annotations,
},
Subsets: item.Subsets,
}
_, err = c.Endpoints(toNs).Create(newEndpoints)
if err != nil {
return err
}
util.Infof("Created endpoint %s in namespace %s\n", name, toNs)
}
}
return answer
}
示例14: 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
}
示例15: processResource
func processResource(c *k8sclient.Client, b []byte, ns string, kind string) error {
util.Infof("Processing resource kind: %s in namespace %s\n", kind, ns)
req := c.Post().Body(b)
if kind == "Deployment" {
req.AbsPath("apis", "extensions/v1beta1", "namespaces", ns, strings.ToLower(kind+"s"))
} else if kind == "BuildConfig" || kind == "DeploymentConfig" || kind == "Template" || kind == "PolicyBinding" || kind == "Role" || kind == "RoleBinding" {
req.AbsPath("oapi", "v1", "namespaces", ns, strings.ToLower(kind+"s"))
} else if kind == "OAuthClient" || kind == "Project" || kind == "ProjectRequest" {
req.AbsPath("oapi", "v1", strings.ToLower(kind+"s"))
} else if kind == "Namespace" {
req.AbsPath("api", "v1", "namespaces")
} else {
req.Namespace(ns).Resource(strings.ToLower(kind + "s"))
}
res := req.Do()
if res.Error() != nil {
err := res.Error()
if err != nil {
util.Warnf("Failed to create %s: %v", kind, err)
return err
}
}
var statusCode int
res.StatusCode(&statusCode)
if statusCode != http.StatusCreated {
return fmt.Errorf("Failed to create %s: %d", kind, statusCode)
}
return nil
}