本文整理匯總了Golang中github.com/openshift/origin/pkg/api/graph.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDCRCSpecNode
func TestDCRCSpecNode(t *testing.T) {
g := osgraph.New()
dc := &deployapi.DeploymentConfig{}
dc.Namespace = "ns"
dc.Name = "foo"
dcNode := EnsureDeploymentConfigNode(g, dc)
if len(g.NodeList()) != 2 {
t.Errorf("expected 2 nodes, got %v", g.NodeList())
}
if len(g.EdgeList()) != 1 {
t.Errorf("expected 2 edge, got %v", g.EdgeList())
}
edge := g.EdgeList()[0]
if !g.EdgeKinds(edge).Has(osgraph.ContainsEdgeKind) {
t.Errorf("expected %v, got %v", osgraph.ContainsEdgeKind, g.EdgeKinds(edge))
}
if edge.Head().ID() != dcNode.ID() {
t.Errorf("expected %v, got %v", dcNode.ID(), edge.Head())
}
}
示例2: TestPodSpecNode
func TestPodSpecNode(t *testing.T) {
g := osgraph.New()
pod := &kapi.Pod{}
pod.Namespace = "ns"
pod.Name = "foo"
pod.Spec.NodeName = "any-host"
podNode := EnsurePodNode(g, pod)
if len(g.Nodes()) != 2 {
t.Errorf("expected 2 nodes, got %v", g.Nodes())
}
if len(g.Edges()) != 1 {
t.Errorf("expected 1 edge, got %v", g.Edges())
}
edge := g.Edges()[0]
if !g.EdgeKinds(edge).Has(osgraph.ContainsEdgeKind) {
t.Errorf("expected %v, got %v", osgraph.ContainsEdgeKind, g.EdgeKinds(edge))
}
if edge.From().ID() != podNode.ID() {
t.Errorf("expected %v, got %v", podNode.ID(), edge.From())
}
}
示例3: MakeGraph
// MakeGraph will create the graph of all build configurations and the image streams
// they point to via image change triggers in the provided namespace(s)
func (d *ChainDescriber) MakeGraph() (osgraph.Graph, error) {
g := osgraph.New()
loaders := []GraphLoader{}
for namespace := range d.namespaces {
glog.V(4).Infof("Loading build configurations from %q", namespace)
loaders = append(loaders, &bcLoader{namespace: namespace, lister: d.c})
}
loadingFuncs := []func() error{}
for _, loader := range loaders {
loadingFuncs = append(loadingFuncs, loader.Load)
}
if errs := parallel.Run(loadingFuncs...); len(errs) > 0 {
return g, utilerrors.NewAggregate(errs)
}
for _, loader := range loaders {
loader.AddToGraph(g)
}
buildedges.AddAllInputOutputEdges(g)
return g, nil
}
示例4: TestHPADCEdges
func TestHPADCEdges(t *testing.T) {
hpa := &autoscaling.HorizontalPodAutoscaler{}
hpa.Namespace = "test-ns"
hpa.Name = "test-hpa"
hpa.Spec = autoscaling.HorizontalPodAutoscalerSpec{
ScaleTargetRef: autoscaling.CrossVersionObjectReference{
Name: "test-dc",
Kind: "DeploymentConfig",
},
}
dc := &deployapi.DeploymentConfig{}
dc.Name = "test-dc"
dc.Namespace = "test-ns"
g := osgraph.New()
hpaNode := kubegraph.EnsureHorizontalPodAutoscalerNode(g, hpa)
dcNode := deploygraph.EnsureDeploymentConfigNode(g, dc)
AddHPAScaleRefEdges(g)
if edge := g.Edge(hpaNode, dcNode); edge == nil {
t.Fatalf("edge between HPA and DC missing")
} else {
if !g.EdgeKinds(edge).Has(ScalingEdgeKind) {
t.Errorf("expected edge to have kind %v, got %v", ScalingEdgeKind, edge)
}
}
}
示例5: NewImageRegistryPruner
/*
NewImageRegistryPruner creates a new ImageRegistryPruner.
Images younger than keepYoungerThan and images referenced by image streams
and/or pods younger than keepYoungerThan are preserved. All other images are
candidates for pruning. For example, if keepYoungerThan is 60m, and an
ImageStream is only 59 minutes old, none of the images it references are
eligible for pruning.
keepTagRevisions is the number of revisions per tag in an image stream's
status.tags that are preserved and ineligible for pruning. Any revision older
than keepTagRevisions is eligible for pruning.
images, streams, pods, rcs, bcs, builds, and dcs are the resources used to run
the pruning algorithm. These should be the full list for each type from the
cluster; otherwise, the pruning algorithm might result in incorrect
calculations and premature pruning.
The ImagePruner performs the following logic: remove any image containing the
annotation openshift.io/image.managed=true that was created at least *n*
minutes ago and is *not* currently referenced by:
- any pod created less than *n* minutes ago
- any image stream created less than *n* minutes ago
- any running pods
- any pending pods
- any replication controllers
- any deployment configs
- any build configs
- any builds
- the n most recent tag revisions in an image stream's status.tags
When removing an image, remove all references to the image from all
ImageStreams having a reference to the image in `status.tags`.
Also automatically remove any image layer that is no longer referenced by any
images.
*/
func NewImageRegistryPruner(options ImageRegistryPrunerOptions) ImageRegistryPruner {
g := graph.New()
glog.V(1).Infof("Creating image pruner with keepYoungerThan=%v, keepTagRevisions=%d", options.KeepYoungerThan, options.KeepTagRevisions)
algorithm := pruneAlgorithm{
keepYoungerThan: options.KeepYoungerThan,
keepTagRevisions: options.KeepTagRevisions,
}
addImagesToGraph(g, options.Images, algorithm)
addImageStreamsToGraph(g, options.Streams, algorithm)
addPodsToGraph(g, options.Pods, algorithm)
addReplicationControllersToGraph(g, options.RCs)
addBuildConfigsToGraph(g, options.BCs)
addBuildsToGraph(g, options.Builds)
addDeploymentConfigsToGraph(g, options.DCs)
var rp registryPinger
if options.DryRun {
rp = &dryRunRegistryPinger{}
} else {
rp = &defaultRegistryPinger{options.RegistryClient}
}
return &imageRegistryPruner{
g: g,
algorithm: algorithm,
registryPinger: rp,
registryClient: options.RegistryClient,
registryURL: options.RegistryURL,
}
}
示例6: imagesTop
// imagesTop generates Image information from a graph and returns this as a list
// of imageInfo array.
func (o TopImagesOptions) imagesTop() []Info {
g := graph.New()
addImagesToGraph(g, o.Images)
addImageStreamsToGraph(g, o.Streams)
addPodsToGraph(g, o.Pods)
markParentsInGraph(g)
infos := []Info{}
imageNodes := getImageNodes(g.Nodes())
for _, in := range imageNodes {
image := in.Image
istags := getImageStreamTags(g, in)
parents := getImageParents(g, in)
usage := getImageUsage(g, in)
metadata := len(image.DockerImageManifest) != 0 && len(image.DockerImageLayers) != 0
storage := getStorage(image)
infos = append(infos, imageInfo{
Image: image.Name,
ImageStreamTags: istags,
Parents: parents,
Usage: usage,
Metadata: metadata,
Storage: storage,
})
}
return infos
}
示例7: TestHPARCEdges
func TestHPARCEdges(t *testing.T) {
hpa := &autoscaling.HorizontalPodAutoscaler{}
hpa.Namespace = "test-ns"
hpa.Name = "test-hpa"
hpa.Spec = autoscaling.HorizontalPodAutoscalerSpec{
ScaleTargetRef: autoscaling.CrossVersionObjectReference{
Name: "test-rc",
Kind: "ReplicationController",
},
}
rc := &kapi.ReplicationController{}
rc.Name = "test-rc"
rc.Namespace = "test-ns"
g := osgraph.New()
hpaNode := kubegraph.EnsureHorizontalPodAutoscalerNode(g, hpa)
rcNode := kubegraph.EnsureReplicationControllerNode(g, rc)
AddHPAScaleRefEdges(g)
if edge := g.Edge(hpaNode, rcNode); edge == nil {
t.Fatalf("edge between HPA and RC missing")
} else {
if !g.EdgeKinds(edge).Has(ScalingEdgeKind) {
t.Errorf("expected edge to have kind %v, got %v", ScalingEdgeKind, edge)
}
}
}
示例8: MakeGraph
func (d *ProjectStatusDescriber) MakeGraph(namespace string) (osgraph.Graph, sets.String, error) {
g := osgraph.New()
loaders := []GraphLoader{
&serviceLoader{namespace: namespace, lister: d.K},
&serviceAccountLoader{namespace: namespace, lister: d.K},
&secretLoader{namespace: namespace, lister: d.K},
&rcLoader{namespace: namespace, lister: d.K},
&podLoader{namespace: namespace, lister: d.K},
// TODO check swagger for feature enablement and selectively add bcLoader and buildLoader
// then remove errors.TolerateNotFoundError method.
&bcLoader{namespace: namespace, lister: d.C},
&buildLoader{namespace: namespace, lister: d.C},
&isLoader{namespace: namespace, lister: d.C},
&dcLoader{namespace: namespace, lister: d.C},
&routeLoader{namespace: namespace, lister: d.C},
}
loadingFuncs := []func() error{}
for _, loader := range loaders {
loadingFuncs = append(loadingFuncs, loader.Load)
}
forbiddenResources := sets.String{}
if errs := parallel.Run(loadingFuncs...); len(errs) > 0 {
actualErrors := []error{}
for _, err := range errs {
if kapierrors.IsForbidden(err) {
forbiddenErr := err.(*kapierrors.StatusError)
if (forbiddenErr.Status().Details != nil) && (len(forbiddenErr.Status().Details.Kind) > 0) {
forbiddenResources.Insert(forbiddenErr.Status().Details.Kind)
}
continue
}
actualErrors = append(actualErrors, err)
}
if len(actualErrors) > 0 {
return g, forbiddenResources, utilerrors.NewAggregate(actualErrors)
}
}
for _, loader := range loaders {
loader.AddToGraph(g)
}
kubeedges.AddAllExposedPodTemplateSpecEdges(g)
kubeedges.AddAllExposedPodEdges(g)
kubeedges.AddAllManagedByRCPodEdges(g)
kubeedges.AddAllRequestedServiceAccountEdges(g)
kubeedges.AddAllMountableSecretEdges(g)
kubeedges.AddAllMountedSecretEdges(g)
buildedges.AddAllInputOutputEdges(g)
buildedges.AddAllBuildEdges(g)
deployedges.AddAllTriggerEdges(g)
deployedges.AddAllDeploymentEdges(g)
imageedges.AddAllImageStreamRefEdges(g)
routeedges.AddAllRouteEdges(g)
return g, forbiddenResources, nil
}
示例9: MakeGraph
func (d *ProjectStatusDescriber) MakeGraph(namespace string) (osgraph.Graph, error) {
g := osgraph.New()
svcs, err := d.K.Services(namespace).List(labels.Everything())
if err != nil {
return g, err
}
iss, err := d.C.ImageStreams(namespace).List(labels.Everything(), fields.Everything())
if err != nil {
return g, err
}
bcs, err := d.C.BuildConfigs(namespace).List(labels.Everything(), fields.Everything())
if err != nil {
return g, err
}
dcs, err := d.C.DeploymentConfigs(namespace).List(labels.Everything(), fields.Everything())
if err != nil {
return g, err
}
builds := &buildapi.BuildList{}
if len(bcs.Items) > 0 {
if b, err := d.C.Builds(namespace).List(labels.Everything(), fields.Everything()); err == nil {
builds = b
}
}
rcs, err := d.K.ReplicationControllers(namespace).List(labels.Everything())
if err != nil {
rcs = &kapi.ReplicationControllerList{}
}
for i := range iss.Items {
imagegraph.EnsureImageStreamNode(g, &iss.Items[i])
imagegraph.EnsureAllImageStreamTagNodes(g, &iss.Items[i])
}
for i := range bcs.Items {
build := buildgraph.EnsureBuildConfigNode(g, &bcs.Items[i])
buildedges.AddInputOutputEdges(g, build)
buildedges.JoinBuilds(build, builds.Items)
}
for i := range dcs.Items {
deploy := deploygraph.EnsureDeploymentConfigNode(g, &dcs.Items[i])
deployedges.AddTriggerEdges(g, deploy)
deployedges.JoinDeployments(deploy, rcs.Items)
}
for i := range svcs.Items {
service := kubegraph.EnsureServiceNode(g, &svcs.Items[i])
kubeedges.AddExposedPodTemplateSpecEdges(g, service)
}
imageedges.AddAllImageStreamRefEdges(g)
return g, nil
}
示例10: TestReplicationControllerSpecNode
func TestReplicationControllerSpecNode(t *testing.T) {
g := osgraph.New()
rc := &kapi.ReplicationController{}
rc.Namespace = "ns"
rc.Name = "foo"
rc.Spec.Template = &kapi.PodTemplateSpec{}
rcNode := EnsureReplicationControllerNode(g, rc)
if len(g.Nodes()) != 4 {
t.Errorf("expected 4 nodes, got %v", g.Nodes())
}
if len(g.Edges()) != 3 {
t.Errorf("expected 3 edge, got %v", g.Edges())
}
rcEdges := g.OutboundEdges(rcNode)
if len(rcEdges) != 1 {
t.Fatalf("expected 1 edge, got %v for \n%v", rcEdges, g)
}
if !g.EdgeKinds(rcEdges[0]).Has(osgraph.ContainsEdgeKind) {
t.Errorf("expected %v, got %v", osgraph.ContainsEdgeKind, rcEdges[0])
}
uncastRCSpec := rcEdges[0].To()
rcSpec, ok := uncastRCSpec.(*ReplicationControllerSpecNode)
if !ok {
t.Fatalf("expected rcSpec, got %v", uncastRCSpec)
}
rcSpecEdges := g.OutboundEdges(rcSpec)
if len(rcSpecEdges) != 1 {
t.Fatalf("expected 1 edge, got %v", rcSpecEdges)
}
if !g.EdgeKinds(rcSpecEdges[0]).Has(osgraph.ContainsEdgeKind) {
t.Errorf("expected %v, got %v", osgraph.ContainsEdgeKind, rcSpecEdges[0])
}
uncastPTSpec := rcSpecEdges[0].To()
ptSpec, ok := uncastPTSpec.(*PodTemplateSpecNode)
if !ok {
t.Fatalf("expected ptspec, got %v", uncastPTSpec)
}
ptSpecEdges := g.OutboundEdges(ptSpec)
if len(ptSpecEdges) != 1 {
t.Fatalf("expected 1 edge, got %v", ptSpecEdges)
}
if !g.EdgeKinds(ptSpecEdges[0]).Has(osgraph.ContainsEdgeKind) {
t.Errorf("expected %v, got %v", osgraph.ContainsEdgeKind, ptSpecEdges[0])
}
}
示例11: TestNamespaceEdgeMatching
func TestNamespaceEdgeMatching(t *testing.T) {
g := osgraph.New()
fn := func(namespace string, g osgraph.Interface) {
pod := &kapi.Pod{}
pod.Namespace = namespace
pod.Name = "the-pod"
pod.Labels = map[string]string{"a": "1"}
kubegraph.EnsurePodNode(g, pod)
rc := &kapi.ReplicationController{}
rc.Namespace = namespace
rc.Name = "the-rc"
rc.Spec.Selector = map[string]string{"a": "1"}
kubegraph.EnsureReplicationControllerNode(g, rc)
p := &kapps.PetSet{}
p.Namespace = namespace
p.Name = "the-petset"
p.Spec.Selector = &unversioned.LabelSelector{
MatchLabels: map[string]string{"a": "1"},
}
kubegraph.EnsurePetSetNode(g, p)
svc := &kapi.Service{}
svc.Namespace = namespace
svc.Name = "the-svc"
svc.Spec.Selector = map[string]string{"a": "1"}
kubegraph.EnsureServiceNode(g, svc)
}
fn("ns", g)
fn("other", g)
AddAllExposedPodEdges(g)
AddAllExposedPodTemplateSpecEdges(g)
AddAllManagedByControllerPodEdges(g)
for _, edge := range g.Edges() {
nsTo, err := namespaceFor(edge.To())
if err != nil {
t.Fatal(err)
}
nsFrom, err := namespaceFor(edge.From())
if err != nil {
t.Fatal(err)
}
if nsFrom != nsTo {
t.Errorf("edge %#v crosses namespace: %s %s", edge, nsFrom, nsTo)
}
}
}
示例12: TestDCPodTemplateSpecNode
func TestDCPodTemplateSpecNode(t *testing.T) {
g := osgraph.New()
dc := &deployapi.DeploymentConfig{}
dc.Namespace = "ns"
dc.Name = "foo"
dc.Spec.Template = test.OkPodTemplate()
_ = EnsureDeploymentConfigNode(g, dc)
edges := g.Edges()
if len(edges) != 2 {
t.Errorf("expected 2 edges, got %d", len(edges))
return
}
for i := range edges {
if !g.EdgeKinds(edges[i]).Has(osgraph.ContainsEdgeKind) {
t.Errorf("expected %v, got %v", osgraph.ContainsEdgeKind, g.EdgeKinds(edges[i]))
return
}
}
nodes := g.Nodes()
if len(nodes) != 3 {
t.Errorf("expected 3 nodes, got %d", len(nodes))
return
}
sorted, err := topo.Sort(g)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
}
// Just to be sure
if len(sorted) != 3 {
t.Errorf("expected 3 nodes, got %d", len(sorted))
return
}
if _, ok := sorted[0].(*DeploymentConfigNode); !ok {
t.Errorf("expected first node to be a DeploymentConfigNode")
return
}
if _, ok := sorted[1].(*kubetypes.PodTemplateSpecNode); !ok {
t.Errorf("expected second node to be a PodTemplateSpecNode")
return
}
if _, ok := sorted[2].(*kubetypes.PodSpecNode); !ok {
t.Errorf("expected third node to be a PodSpecNode")
}
}
示例13: Describe
// Describe returns the description of the latest deployments for a config
func (d *LatestDeploymentsDescriber) Describe(namespace, name string) (string, error) {
var f formatter
config, err := d.client.getDeploymentConfig(namespace, name)
if err != nil {
return "", err
}
var deployments []kapi.ReplicationController
if d.count == -1 || d.count > 1 {
list, err := d.client.listDeployments(namespace, labels.Everything())
if err != nil && !kerrors.IsNotFound(err) {
return "", err
}
deployments = list.Items
} else {
deploymentName := deployutil.LatestDeploymentNameForConfig(config)
deployment, err := d.client.getDeployment(config.Namespace, deploymentName)
if err != nil && !kerrors.IsNotFound(err) {
return "", err
}
if deployment != nil {
deployments = []kapi.ReplicationController{*deployment}
}
}
g := graph.New()
dcNode := deploygraph.EnsureDeploymentConfigNode(g, config)
for i := range deployments {
kubegraph.EnsureReplicationControllerNode(g, &deployments[i])
}
deployedges.AddTriggerEdges(g, dcNode)
deployedges.AddDeploymentEdges(g, dcNode)
activeDeployment, inactiveDeployments := deployedges.RelevantDeployments(g, dcNode)
return tabbedString(func(out *tabwriter.Writer) error {
descriptions := describeDeployments(f, dcNode, activeDeployment, inactiveDeployments, d.count)
for i, description := range descriptions {
descriptions[i] = fmt.Sprintf("%v %v", name, description)
}
printLines(out, "", 0, descriptions...)
return nil
})
}
示例14: TestSecretEdges
func TestSecretEdges(t *testing.T) {
sa := &kapi.ServiceAccount{}
sa.Namespace = "ns"
sa.Name = "shultz"
sa.Secrets = []kapi.ObjectReference{{Name: "i-know-nothing"}, {Name: "missing"}}
secret1 := &kapi.Secret{}
secret1.Namespace = "ns"
secret1.Name = "i-know-nothing"
pod := &kapi.Pod{}
pod.Namespace = "ns"
pod.Name = "the-pod"
pod.Spec.Volumes = []kapi.Volume{{Name: "rose", VolumeSource: kapi.VolumeSource{Secret: &kapi.SecretVolumeSource{SecretName: "i-know-nothing"}}}}
g := osgraph.New()
saNode := kubegraph.EnsureServiceAccountNode(g, sa)
secretNode := kubegraph.EnsureSecretNode(g, secret1)
podNode := kubegraph.EnsurePodNode(g, pod)
AddAllMountableSecretEdges(g)
AddAllMountedSecretEdges(g)
if edge := g.Edge(saNode, secretNode); edge == nil {
t.Errorf("edge missing")
} else {
if !g.EdgeKinds(edge).Has(MountableSecretEdgeKind) {
t.Errorf("expected %v, got %v", MountableSecretEdgeKind, edge)
}
}
podSpecNodes := g.SuccessorNodesByNodeAndEdgeKind(podNode, kubegraph.PodSpecNodeKind, osgraph.ContainsEdgeKind)
if len(podSpecNodes) != 1 {
t.Fatalf("wrong number of podspecs: %v", podSpecNodes)
}
if edge := g.Edge(podSpecNodes[0], secretNode); edge == nil {
t.Errorf("edge missing")
} else {
if !g.EdgeKinds(edge).Has(MountedSecretEdgeKind) {
t.Errorf("expected %v, got %v", MountedSecretEdgeKind, edge)
}
}
}
示例15: imageStreamsTop
// imageStreamsTop generates ImageStream information from a graph and
// returns this as a list of imageStreamInfo array.
func (o TopImageStreamsOptions) imageStreamsTop() []Info {
g := graph.New()
addImagesToGraph(g, o.Images)
addImageStreamsToGraph(g, o.Streams)
infos := []Info{}
streamNodes := getImageStreamNodes(g.Nodes())
for _, sn := range streamNodes {
storage, images, layers := getImageStreamSize(g, sn)
infos = append(infos, imageStreamInfo{
ImageStream: fmt.Sprintf("%s/%s", sn.ImageStream.Namespace, sn.ImageStream.Name),
Storage: storage,
Images: images,
Layers: layers,
})
}
return infos
}