// AllServices returns all services matching the criteria; that is, in // the namespace (or any namespace if that argument is empty), and not // in the `ignore` set given. func (c *Cluster) AllServices(namespace string, ignore flux.ServiceIDSet) (res []platform.Service, err error) { namespaces := []string{} if namespace == "" { list, err := c.client.Namespaces().List(api.ListOptions{}) if err != nil { return nil, errors.Wrap(err, "getting namespaces") } for _, ns := range list.Items { namespaces = append(namespaces, ns.Name) } } else { namespaces = []string{namespace} } for _, ns := range namespaces { controllers, err := c.podControllersInNamespace(ns) if err != nil { return nil, errors.Wrapf(err, "getting pod controllers for namespace %s", ns) } list, err := c.client.Services(ns).List(api.ListOptions{}) if err != nil { return nil, errors.Wrapf(err, "getting services for namespace %s", ns) } for _, service := range list.Items { if !ignore.Contains(flux.MakeServiceID(ns, service.Name)) { res = append(res, c.makeService(ns, &service, controllers)) } } } return res, nil }
func TestUpdateOK(t *testing.T) { db := newDB(t) inst := flux.InstanceID("floaty-womble-abc123") service := flux.MakeServiceID("namespace", "service") services := map[flux.ServiceID]instance.ServiceConfig{} services[service] = instance.ServiceConfig{ Automated: true, Locked: true, } c := instance.Config{ Services: services, } err := db.UpdateConfig(inst, func(_ instance.Config) (instance.Config, error) { return c, nil }) if err != nil { t.Fatal(err) } c1, err := db.GetConfig(inst) if err != nil { t.Fatal(err) } if _, found := c1.Services[service]; !found { t.Fatalf("did not find instance config after setting") } if !c1.Services[service].Automated { t.Fatalf("expected service config %#v, got %#v", c.Services[service], c1.Services[service]) } if !c1.Services[service].Locked { t.Fatalf("expected service config %#v, got %#v", c.Services[service], c1.Services[service]) } }
func (c *Cluster) makeService(ns string, service *api.Service, controllers []podController) platform.Service { id := flux.MakeServiceID(ns, service.Name) status, _ := c.status.getRegradeProgress(id) return platform.Service{ ID: id, IP: service.Spec.ClusterIP, Metadata: metadataForService(service), Containers: containersOrExcuse(service, controllers), Status: status, } }