本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned.Client.ReplicationControllers方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.ReplicationControllers方法的具体用法?Golang Client.ReplicationControllers怎么用?Golang Client.ReplicationControllers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/client/unversioned.Client
的用法示例。
在下文中一共展示了Client.ReplicationControllers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: validateRouter
func validateRouter(c *k8sclient.Client, f *cmdutil.Factory) (Result, error) {
ns, _, err := f.DefaultNamespace()
if err != nil {
return Failure, err
}
requirement, err := labels.NewRequirement("router", labels.EqualsOperator, sets.NewString("router"))
if err != nil {
return Failure, err
}
label := labels.NewSelector().Add(*requirement)
rc, err := c.ReplicationControllers(ns).List(api.ListOptions{LabelSelector: label})
if err != nil {
util.Fatalf("Failed to get PersistentVolumeClaims, %s in namespace %s\n", err, ns)
}
if rc != nil {
items := rc.Items
if len(items) > 0 {
return Success, err
}
}
//util.Fatalf("No router running in namespace %s\n", ns)
// TODO lets create a router
return Failure, err
}
示例2: verifyExpectedRcsExistAndGetExpectedPods
func verifyExpectedRcsExistAndGetExpectedPods(c *client.Client) ([]string, error) {
expectedPods := []string{}
// Iterate over the labels that identify the replication controllers that we
// want to check. The rcLabels contains the value values for the k8s-app key
// that identify the replication controllers that we want to check. Using a label
// rather than an explicit name is preferred because the names will typically have
// a version suffix e.g. heapster-monitoring-v1 and this will change after a rolling
// update e.g. to heapster-monitoring-v2. By using a label query we can check for the
// situation when a heapster-monitoring-v1 and heapster-monitoring-v2 replication controller
// is running (which would be an error except during a rolling update).
for _, rcLabel := range rcLabels {
rcList, err := c.ReplicationControllers(api.NamespaceSystem).List(labels.Set{"k8s-app": rcLabel}.AsSelector(), fields.Everything())
if err != nil {
return nil, err
}
if len(rcList.Items) != 1 {
return nil, fmt.Errorf("expected to find one replica for RC with label %s but got %d",
rcLabel, len(rcList.Items))
}
for _, rc := range rcList.Items {
podList, err := c.Pods(api.NamespaceSystem).List(labels.Set(rc.Spec.Selector).AsSelector(), fields.Everything())
if err != nil {
return nil, err
}
for _, pod := range podList.Items {
if pod.DeletionTimestamp != nil {
continue
}
expectedPods = append(expectedPods, string(pod.UID))
}
}
}
return expectedPods, nil
}
示例3: CreateNewControllerFromCurrentController
func CreateNewControllerFromCurrentController(c *client.Client, namespace, oldName, newName, image, deploymentKey string) (*api.ReplicationController, error) {
// load the old RC into the "new" RC
newRc, err := c.ReplicationControllers(namespace).Get(oldName)
if err != nil {
return nil, err
}
if len(newRc.Spec.Template.Spec.Containers) > 1 {
// TODO: support multi-container image update.
return nil, goerrors.New("Image update is not supported for multi-container pods")
}
if len(newRc.Spec.Template.Spec.Containers) == 0 {
return nil, goerrors.New(fmt.Sprintf("Pod has no containers! (%v)", newRc))
}
newRc.Spec.Template.Spec.Containers[0].Image = image
newHash, err := api.HashObject(newRc, c.Codec)
if err != nil {
return nil, err
}
if len(newName) == 0 {
newName = fmt.Sprintf("%s-%s", newRc.Name, newHash)
}
newRc.Name = newName
newRc.Spec.Selector[deploymentKey] = newHash
newRc.Spec.Template.Labels[deploymentKey] = newHash
// Clear resource version after hashing so that identical updates get different hashes.
newRc.ResourceVersion = ""
return newRc, nil
}
示例4: createRC
func createRC(c *client.Client, nsID, rcID, podNum int) {
var args []string
if podMarkerSize != 0 {
args = []string{string(garbage)}
}
rc := &api.ReplicationController{
ObjectMeta: api.ObjectMeta{
Name: makeRCName(rcID),
},
Spec: api.ReplicationControllerSpec{
Replicas: int32(podNum),
Selector: makeLabel(nsID, rcID),
Template: &api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: makeLabel(nsID, rcID),
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "none",
Image: "none",
Args: args,
},
},
},
},
},
}
if _, err := c.ReplicationControllers(makeNS(nsID)).Create(rc); err != nil {
ExitError("create rc (%s/%s), failed: %v", makeNS(nsID), makeRCName(rcID), err)
}
fmt.Printf("created rc (%s'%s)\n", makeNS(nsID), makeRCName(rcID))
}
示例5: StartPods
// StartPods check for numPods in TestNS. If they exist, it no-ops, otherwise it starts up
// a temp rc, scales it to match numPods, then deletes the rc leaving behind the pods.
func StartPods(numPods int, host string, restClient *client.Client) error {
start := time.Now()
defer func() {
glog.Infof("StartPods took %v with numPods %d", time.Since(start), numPods)
}()
hostField := fields.OneTermEqualSelector(client.PodHost, host)
pods, err := restClient.Pods(TestNS).List(labels.Everything(), hostField)
if err != nil || len(pods.Items) == numPods {
return err
}
glog.Infof("Found %d pods that match host %v, require %d", len(pods.Items), hostField, numPods)
// For the sake of simplicity, assume all pods in TestNS have selectors matching TestRCManifest.
controller := RCFromManifest(TestRCManifest)
// Make the rc unique to the given host.
controller.Spec.Replicas = numPods
controller.Spec.Template.Spec.NodeName = host
controller.Name = controller.Name + host
controller.Spec.Selector["host"] = host
controller.Spec.Template.Labels["host"] = host
if rc, err := StartRC(controller, restClient); err != nil {
return err
} else {
// Delete the rc, otherwise when we restart master components for the next benchmark
// the rc controller will race with the pods controller in the rc manager.
return restClient.ReplicationControllers(TestNS).Delete(rc.Name)
}
}
示例6: getRC
func getRC(kubeClient *client.Client) (*api.ReplicationController, error) {
rcClient := kubeClient.ReplicationControllers(namespace)
rc, err := rcClient.Get("deis-router")
if err != nil {
return nil, err
}
return rc, nil
}
示例7: resizeRC
func resizeRC(c *client.Client, ns, name string, replicas int) error {
rc, err := c.ReplicationControllers(ns).Get(name)
if err != nil {
return err
}
rc.Spec.Replicas = replicas
_, err = c.ReplicationControllers(rc.Namespace).Update(rc)
return err
}
示例8: LoadExistingNextReplicationController
func LoadExistingNextReplicationController(c *client.Client, namespace, newName string) (*api.ReplicationController, error) {
if len(newName) == 0 {
return nil, nil
}
newRc, err := c.ReplicationControllers(namespace).Get(newName)
if err != nil && errors.IsNotFound(err) {
return nil, nil
}
return newRc, err
}
示例9: validateConsoleDeployment
func validateConsoleDeployment(c *k8sclient.Client, f *cmdutil.Factory) (Result, error) {
ns, _, err := f.DefaultNamespace()
if err != nil {
return Failure, err
}
rc, err := c.ReplicationControllers(ns).Get("fabric8")
if rc != nil {
return Success, err
}
return Failure, err
}
示例10: StartRC
// StartRC creates given rc if it doesn't already exist, then updates it via kubectl's scaler.
func StartRC(controller *api.ReplicationController, restClient *client.Client) (*api.ReplicationController, error) {
created, err := restClient.ReplicationControllers(controller.Namespace).Get(controller.Name)
if err != nil {
glog.Infof("Rc %v doesn't exist, creating", controller.Name)
created, err = restClient.ReplicationControllers(controller.Namespace).Create(controller)
if err != nil {
return nil, err
}
}
// If we just created an rc, wait till it creates its replicas.
return ScaleRC(created.Name, created.Namespace, controller.Spec.Replicas, restClient)
}
示例11: deleteReplicationControllers
func deleteReplicationControllers(c *k8sclient.Client, ns string, selector labels.Selector) error {
rcs, err := c.ReplicationControllers(ns).List(api.ListOptions{LabelSelector: selector})
if err != nil {
return err
}
for _, rc := range rcs.Items {
err := c.ReplicationControllers(ns).Delete(rc.Name)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to delete ReplicationController %s", rc.Name))
}
}
return nil
}
示例12: GetMicroserviceList
// Returns a list of all microservices in the cluster.
func GetMicroserviceList(client *client.Client) (*MicroserviceList, error) {
list, err := client.ReplicationControllers(api.NamespaceAll).
List(labels.Everything(), fields.Everything())
if err != nil {
return nil, err
}
microserviceList := &MicroserviceList{}
for _, element := range list.Items {
var containerImages []string
for _, container := range element.Spec.Template.Spec.Containers {
containerImages = append(containerImages, container.Image)
}
microserviceList.Microservices = append(microserviceList.Microservices, Microservice{
Name: element.ObjectMeta.Name,
ReplicaSet: ReplicaSet{
ContainerImages: containerImages,
PodsRunning: element.Status.Replicas,
PodsDesired: element.Spec.Replicas,
},
})
}
return microserviceList, nil
}
示例13: GetReplicationControllerPodsEvents
// Gets events associated to pods in replication controller.
func GetReplicationControllerPodsEvents(client *client.Client, namespace, replicationControllerName string) ([]api.Event,
error) {
replicationController, err := client.ReplicationControllers(namespace).Get(replicationControllerName)
if err != nil {
return nil, err
}
pods, err := client.Pods(namespace).List(api.ListOptions{
LabelSelector: labels.SelectorFromSet(replicationController.Spec.Selector),
FieldSelector: fields.Everything(),
})
if err != nil {
return nil, err
}
events, err := GetPodsEvents(client, pods)
if err != nil {
return nil, err
}
return events, nil
}
示例14: GetReplicaSetList
// Returns a list of all Replica Sets in the cluster.
func GetReplicaSetList(client *client.Client) (*ReplicaSetList, error) {
list, err := client.ReplicationControllers(api.NamespaceAll).
List(labels.Everything(), fields.Everything())
if err != nil {
return nil, err
}
replicaSetList := &ReplicaSetList{}
for _, replicaSet := range list.Items {
var containerImages []string
for _, container := range replicaSet.Spec.Template.Spec.Containers {
containerImages = append(containerImages, container.Image)
}
replicaSetList.ReplicaSets = append(replicaSetList.ReplicaSets, ReplicaSet{
Name: replicaSet.ObjectMeta.Name,
ContainerImages: containerImages,
PodsRunning: replicaSet.Status.Replicas,
PodsDesired: replicaSet.Spec.Replicas,
})
}
return replicaSetList, nil
}
示例15: ScaleRC
// ScaleRC scales the given rc to the given replicas.
func ScaleRC(name, ns string, replicas int, restClient *client.Client) (*api.ReplicationController, error) {
scaler, err := kubectl.ScalerFor("ReplicationController", kubectl.NewScalerClient(restClient))
if err != nil {
return nil, err
}
retry := &kubectl.RetryParams{Interval: 50 * time.Millisecond, Timeout: DefaultTimeout}
waitForReplicas := &kubectl.RetryParams{Interval: 50 * time.Millisecond, Timeout: DefaultTimeout}
err = scaler.Scale(ns, name, uint(replicas), nil, retry, waitForReplicas)
if err != nil {
return nil, err
}
scaled, err := restClient.ReplicationControllers(ns).Get(name)
if err != nil {
return nil, err
}
return scaled, nil
}