本文整理匯總了Golang中github.com/openshift/origin/pkg/client.Client.Projects方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Projects方法的具體用法?Golang Client.Projects怎麽用?Golang Client.Projects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/origin/pkg/client.Client
的用法示例。
在下文中一共展示了Client.Projects方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getProjects
func getProjects(oClient *client.Client) ([]api.Project, error) {
projects, err := oClient.Projects().List(kapi.ListOptions{})
if err != nil {
return nil, err
}
return projects.Items, nil
}
示例2: getProjects
func getProjects(oClient *client.Client) ([]api.Project, error) {
projects, err := oClient.Projects().List(labels.Everything(), fields.Everything())
if err != nil {
return nil, err
}
return projects.Items, nil
}
示例3: 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
}
示例4: confirmProjectAccess
func confirmProjectAccess(currentProject string, oClient *client.Client, kClient kclient.Interface) error {
_, projectErr := oClient.Projects().Get(currentProject)
if !kapierrors.IsNotFound(projectErr) {
return projectErr
}
// at this point we know the error is a not found, but we'll test namespaces just in case we're running on kube
if _, err := kClient.Namespaces().Get(currentProject); err == nil {
return nil
}
// otherwise return the openshift error default
return projectErr
}
示例5: getProjects
func getProjects(oClient *client.Client, kClient kclient.Interface) ([]api.Project, error) {
projects, err := oClient.Projects().List(kapi.ListOptions{})
if err == nil {
return projects.Items, nil
}
if err != nil && !kapierrors.IsNotFound(err) {
return nil, err
}
namespaces, err := kClient.Namespaces().List(kapi.ListOptions{})
if err != nil {
return nil, err
}
projects = projectutil.ConvertNamespaceList(namespaces)
return projects.Items, nil
}
示例6: retrieveLoggingProject
func retrieveLoggingProject(r types.DiagnosticResult, masterCfg *configapi.MasterConfig, osClient *client.Client) string {
r.Debug("AGL0010", fmt.Sprintf("masterConfig.AssetConfig.LoggingPublicURL: '%s'", masterCfg.AssetConfig.LoggingPublicURL))
projectName := ""
if len(masterCfg.AssetConfig.LoggingPublicURL) == 0 {
r.Debug("AGL0017", "masterConfig.AssetConfig.LoggingPublicURL is empty")
return projectName
}
loggingUrl, err := url.Parse(masterCfg.AssetConfig.LoggingPublicURL)
if err != nil {
r.Error("AGL0011", err, fmt.Sprintf("Unable to parse the loggingPublicURL from the masterConfig '%s'", masterCfg.AssetConfig.LoggingPublicURL))
return projectName
}
routeList, err := osClient.Routes(kapi.NamespaceAll).List(kapi.ListOptions{LabelSelector: loggingSelector.AsSelector()})
if err != nil {
r.Error("AGL0012", err, fmt.Sprintf("There was an error while trying to find the route associated with '%s' which is probably transient: %s", loggingUrl, err))
return projectName
}
for _, route := range routeList.Items {
r.Debug("AGL0013", fmt.Sprintf("Comparing URL to route.Spec.Host: %s", route.Spec.Host))
if loggingUrl.Host == route.Spec.Host {
if len(projectName) == 0 {
projectName = route.ObjectMeta.Namespace
r.Info("AGL0015", fmt.Sprintf("Found route '%s' matching logging URL '%s' in project: '%s'", route.ObjectMeta.Name, loggingUrl.Host, projectName))
} else {
r.Warn("AGL0019", nil, fmt.Sprintf("Found additional route '%s' matching logging URL '%s' in project: '%s'. This could mean you have multiple logging deployments.", route.ObjectMeta.Name, loggingUrl.Host, projectName))
}
}
}
if len(projectName) == 0 {
message := fmt.Sprintf("Unable to find a route matching the loggingPublicURL defined in the master config '%s'. Check that the URL is correct and aggregated logging is deployed.", loggingUrl)
r.Error("AGL0014", errors.New(message), message)
return ""
}
project, err := osClient.Projects().Get(projectName)
if err != nil {
r.Error("AGL0018", err, fmt.Sprintf("There was an error retrieving project '%s' which is most likely a transient error: %s", projectName, err))
return ""
}
nodeSelector, ok := project.ObjectMeta.Annotations["openshift.io/node-selector"]
if !ok || len(nodeSelector) != 0 {
r.Warn("AGL0030", nil, fmt.Sprintf(projectNodeSelectorWarning, projectName))
}
return projectName
}
示例7: getProjects
func getProjects(oClient *client.Client, kClient kclientset.Interface) ([]api.Project, error) {
projects, err := oClient.Projects().List(kapi.ListOptions{})
if err == nil {
return projects.Items, nil
}
// if this is kube with authorization enabled, this endpoint will be forbidden. OpenShift allows this for everyone.
if err != nil && !(kapierrors.IsNotFound(err) || kapierrors.IsForbidden(err)) {
return nil, err
}
namespaces, err := kClient.Core().Namespaces().List(kapi.ListOptions{})
if err != nil {
return nil, err
}
projects = projectutil.ConvertNamespaceList(namespaces)
return projects.Items, nil
}