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 }
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 }
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 }
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 }
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 }
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 }
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 }