本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned.Interface.Extensions方法的典型用法代码示例。如果您正苦于以下问题:Golang Interface.Extensions方法的具体用法?Golang Interface.Extensions怎么用?Golang Interface.Extensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/client/unversioned.Interface
的用法示例。
在下文中一共展示了Interface.Extensions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteDaemonSet
// TODO(floreks): This should be transactional to make sure that DS will not be deleted without pods
// Deletes daemon set with given name in given namespace and related pods.
// Also deletes services related to daemon set if deleteServices is true.
func DeleteDaemonSet(client k8sClient.Interface, namespace, name string,
deleteServices bool) error {
log.Printf("Deleting %s daemon set from %s namespace", name, namespace)
if deleteServices {
if err := DeleteDaemonSetServices(client, namespace, name); err != nil {
return err
}
}
pods, err := getRawDaemonSetPods(client, namespace, name)
if err != nil {
return err
}
if err := client.Extensions().DaemonSets(namespace).Delete(name); err != nil {
return err
}
for _, pod := range pods.Items {
if err := client.Pods(namespace).Delete(pod.Name, &api.DeleteOptions{}); err != nil {
return err
}
}
log.Printf("Successfully deleted %s daemon set from %s namespace", name, namespace)
return nil
}
示例2: StatusViewerFor
func StatusViewerFor(kind unversioned.GroupKind, c client.Interface) (StatusViewer, error) {
switch kind {
case extensions.Kind("Deployment"):
return &DeploymentStatusViewer{c.Extensions()}, nil
}
return nil, fmt.Errorf("no status viewer has been implemented for %v", kind)
}
示例3: GetDeploymentDetail
// GetDeploymentDetail returns model object of deployment and error, if any.
func GetDeploymentDetail(client client.Interface, namespace string,
name string) (*DeploymentDetail, error) {
log.Printf("Getting details of %s deployment in %s namespace", name, namespace)
deployment, err := client.Extensions().Deployments(namespace).Get(name)
if err != nil {
return nil, err
}
selector, err := unversioned.LabelSelectorAsSelector(deployment.Spec.Selector)
if err != nil {
return nil, err
}
options := api.ListOptions{LabelSelector: selector}
channels := &common.ResourceChannels{
ReplicaSetList: common.GetReplicaSetListChannelWithOptions(client.Extensions(),
common.NewSameNamespaceQuery(namespace), options, 1),
PodList: common.GetPodListChannelWithOptions(client,
common.NewSameNamespaceQuery(namespace), options, 1),
EventList: common.GetEventListChannelWithOptions(client,
common.NewSameNamespaceQuery(namespace), options, 1),
}
rsList := <-channels.ReplicaSetList.List
if err := <-channels.ReplicaSetList.Error; err != nil {
return nil, err
}
podList := <-channels.PodList.List
if err := <-channels.PodList.Error; err != nil {
return nil, err
}
eventList := <-channels.EventList.List
if err := <-channels.EventList.Error; err != nil {
return nil, err
}
oldReplicaSets, _, err := deploymentutil.FindOldReplicaSets(deployment, rsList.Items, podList)
if err != nil {
return nil, err
}
newReplicaSet, err := deploymentutil.FindNewReplicaSet(deployment, rsList.Items)
if err != nil {
return nil, err
}
events, err := GetDeploymentEvents(eventList.Items, namespace, name)
if err != nil {
return nil, err
}
return getDeploymentDetail(deployment, oldReplicaSets, newReplicaSet,
podList.Items, events, eventList.Items), nil
}
示例4: ScalerFor
func ScalerFor(kind string, c client.Interface) (Scaler, error) {
switch kind {
case "ReplicationController":
return &ReplicationControllerScaler{c}, nil
case "Job":
return &JobScaler{c.Extensions()}, nil
case "Deployment":
return &DeploymentScaler{c.Extensions()}, nil
}
return nil, fmt.Errorf("no scaler has been implemented for %q", kind)
}
示例5: ScalerFor
func ScalerFor(kind unversioned.GroupKind, c client.Interface) (Scaler, error) {
switch kind {
case api.Kind("ReplicationController"):
return &ReplicationControllerScaler{c}, nil
case extensions.Kind("Job"):
return &JobScaler{c.Extensions()}, nil
case extensions.Kind("Deployment"):
return &DeploymentScaler{c.Extensions()}, nil
}
return nil, fmt.Errorf("no scaler has been implemented for %q", kind)
}
示例6: GetDeploymentOldReplicaSets
// GetDeploymentEvents returns model events for a deployment with the given name in the given
// namespace
func GetDeploymentOldReplicaSets(client client.Interface, dsQuery *dataselect.DataSelectQuery,
namespace string, deploymentName string) (*replicasetlist.ReplicaSetList, error) {
deployment, err := client.Extensions().Deployments(namespace).Get(deploymentName)
if err != nil {
return nil, err
}
selector, err := unversioned.LabelSelectorAsSelector(deployment.Spec.Selector)
if err != nil {
return nil, err
}
options := api.ListOptions{LabelSelector: selector}
channels := &common.ResourceChannels{
ReplicaSetList: common.GetReplicaSetListChannelWithOptions(client.Extensions(),
common.NewSameNamespaceQuery(namespace), options, 1),
PodList: common.GetPodListChannelWithOptions(client,
common.NewSameNamespaceQuery(namespace), options, 1),
EventList: common.GetEventListChannelWithOptions(client,
common.NewSameNamespaceQuery(namespace), options, 1),
}
rawRs := <-channels.ReplicaSetList.List
if err := <-channels.ReplicaSetList.Error; err != nil {
return nil, err
}
rawPods := <-channels.PodList.List
if err := <-channels.PodList.Error; err != nil {
return nil, err
}
rawEvents := <-channels.EventList.List
if err := <-channels.EventList.Error; err != nil {
return nil, err
}
rawRepSets := make([]*extensions.ReplicaSet, 0)
for i := range rawRs.Items {
rawRepSets = append(rawRepSets, &rawRs.Items[i])
}
oldRs, _, err := deploymentutil.FindOldReplicaSets(deployment, rawRepSets, rawPods)
if err != nil {
return nil, err
}
oldReplicaSets := make([]extensions.ReplicaSet, len(oldRs))
for i, replicaSet := range oldRs {
oldReplicaSets[i] = *replicaSet
}
oldReplicaSetList := replicasetlist.CreateReplicaSetList(oldReplicaSets, rawPods.Items, rawEvents.Items,
dsQuery, nil)
return oldReplicaSetList, nil
}
示例7: ScalerFor
func ScalerFor(kind unversioned.GroupKind, c client.Interface) (Scaler, error) {
switch kind {
case api.Kind("ReplicationController"):
return &ReplicationControllerScaler{c}, nil
case extensions.Kind("ReplicaSet"):
return &ReplicaSetScaler{c.Extensions()}, nil
case extensions.Kind("Job"):
return &JobScaler{c.Extensions()}, nil
// TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).
// case extensions.Kind("Deployment"):
// return &DeploymentScaler{c.Extensions()}, nil
}
return nil, fmt.Errorf("no scaler has been implemented for %q", kind)
}
示例8: ScalerFor
func ScalerFor(kind unversioned.GroupKind, c client.Interface) (Scaler, error) {
switch kind {
case api.Kind("ReplicationController"):
return &ReplicationControllerScaler{c}, nil
case extensions.Kind("ReplicaSet"):
return &ReplicaSetScaler{c.Extensions()}, nil
case extensions.Kind("Job"), batch.Kind("Job"):
return &JobScaler{c.Batch()}, nil // Either kind of job can be scaled with Batch interface.
case apps.Kind("PetSet"):
return &PetSetScaler{c.Apps()}, nil
case extensions.Kind("Deployment"):
return &DeploymentScaler{c.Extensions()}, nil
}
return nil, fmt.Errorf("no scaler has been implemented for %q", kind)
}
示例9: testPodNodeConstraintsObjectCreationWithPodTemplate
// testPodNodeConstraintsObjectCreationWithPodTemplate attemps to create different object types that contain pod templates
// using the passed in nodeName and nodeSelector. It will use the expectError flag to determine if an error should be returned or not
func testPodNodeConstraintsObjectCreationWithPodTemplate(t *testing.T, name string, kclient kclient.Interface, client client.Interface, nodeName string, nodeSelector map[string]string, expectError bool) {
checkForbiddenErr := func(objType string, err error) {
if err == nil && expectError {
t.Errorf("%s (%s): expected forbidden error but did not receive one", name, objType)
return
}
if err != nil && !expectError {
t.Errorf("%s (%s): got error but did not expect one: %v", name, objType, err)
return
}
if err != nil && expectError && !kapierrors.IsForbidden(err) {
t.Errorf("%s (%s): did not get an expected forbidden error: %v", name, objType, err)
return
}
}
// Pod
pod := testPodNodeConstraintsPod(nodeName, nodeSelector)
_, err := kclient.Pods(testutil.Namespace()).Create(pod)
checkForbiddenErr("pod", err)
// ReplicationController
rc := testPodNodeConstraintsReplicationController(nodeName, nodeSelector)
_, err = kclient.ReplicationControllers(testutil.Namespace()).Create(rc)
checkForbiddenErr("rc", err)
// TODO: Enable when the deployments endpoint is supported in Origin
// Deployment
// d := testPodNodeConstraintsDeployment(nodeName, nodeSelector)
// _, err = kclient.Extensions().Deployments(testutil.Namespace()).Create(d)
// checkForbiddenErr("deployment", err)
// ReplicaSet
rs := testPodNodeConstraintsReplicaSet(nodeName, nodeSelector)
_, err = kclient.Extensions().ReplicaSets(testutil.Namespace()).Create(rs)
checkForbiddenErr("replicaset", err)
// Job
job := testPodNodeConstraintsJob(nodeName, nodeSelector)
_, err = kclient.Extensions().Jobs(testutil.Namespace()).Create(job)
checkForbiddenErr("job", err)
// DeploymentConfig
dc := testPodNodeConstraintsDeploymentConfig(nodeName, nodeSelector)
_, err = client.DeploymentConfigs(testutil.Namespace()).Create(dc)
checkForbiddenErr("dc", err)
}
示例10: DeleteDaemonSetServices
// DeleteDaemonSetServices deletes services related to daemon set with given name in given namespace.
func DeleteDaemonSetServices(client k8sClient.Interface, namespace, name string) error {
log.Printf("Deleting services related to %s daemon set from %s namespace", name,
namespace)
daemonSet, err := client.Extensions().DaemonSets(namespace).Get(name)
if err != nil {
return err
}
labelSelector, err := unversioned.LabelSelectorAsSelector(daemonSet.Spec.Selector)
if err != nil {
return err
}
services, err := getServicesForDSDeletion(client, labelSelector, namespace)
if err != nil {
return err
}
for _, service := range services {
if err := client.Services(namespace).Delete(service.Name); err != nil {
return err
}
}
log.Printf("Successfully deleted services related to %s daemon set from %s namespace",
name, namespace)
return nil
}
示例11: GetReplicaSetDetail
// GetReplicaSetDetail gets replica set details.
func GetReplicaSetDetail(client k8sClient.Interface, heapsterClient client.HeapsterClient,
namespace, name string) (*ReplicaSetDetail, error) {
log.Printf("Getting details of %s service in %s namespace", name, namespace)
// TODO(floreks): Use channels.
replicaSetData, err := client.Extensions().ReplicaSets(namespace).Get(name)
if err != nil {
return nil, err
}
eventList, err := GetReplicaSetEvents(client, dataselect.DefaultDataSelect, replicaSetData.Namespace, replicaSetData.Name)
if err != nil {
return nil, err
}
podList, err := GetReplicaSetPods(client, heapsterClient, dataselect.DefaultDataSelectWithMetrics, name, namespace)
if err != nil {
return nil, err
}
podInfo, err := getReplicaSetPodInfo(client, replicaSetData)
if err != nil {
return nil, err
}
serviceList, err := GetReplicaSetServices(client, dataselect.DefaultDataSelect, namespace, name)
if err != nil {
return nil, err
}
replicaSet := ToReplicaSetDetail(replicaSetData, *eventList, *podList, *podInfo, *serviceList)
return &replicaSet, nil
}
示例12: GetDeploymentPods
// getJobPods returns list of pods targeting deployment.
func GetDeploymentPods(client client.Interface, heapsterClient heapster.HeapsterClient,
dsQuery *dataselect.DataSelectQuery, namespace string, deploymentName string) (*pod.PodList, error) {
deployment, err := client.Extensions().Deployments(namespace).Get(deploymentName)
if err != nil {
return nil, err
}
selector, err := unversioned.LabelSelectorAsSelector(deployment.Spec.Selector)
if err != nil {
return nil, err
}
options := api.ListOptions{LabelSelector: selector}
channels := &common.ResourceChannels{
PodList: common.GetPodListChannelWithOptions(client,
common.NewSameNamespaceQuery(namespace), options, 1),
}
rawPods := <-channels.PodList.List
if err := <-channels.PodList.Error; err != nil {
return nil, err
}
pods := common.FilterNamespacedPodsBySelector(rawPods.Items, deployment.ObjectMeta.Namespace,
deployment.Spec.Selector.MatchLabels)
podList := pod.CreatePodList(pods, dsQuery, heapsterClient)
return &podList, nil
}
示例13: getRawDaemonSetWithPods
// Returns structure containing DaemonSet and Pods for the given daemon set.
func getRawDaemonSetWithPods(client client.Interface, namespace, name string) (
*DaemonSetWithPods, error) {
daemonSet, err := client.Extensions().DaemonSets(namespace).Get(name)
if err != nil {
return nil, err
}
labelSelector, err := unversioned.LabelSelectorAsSelector(daemonSet.Spec.Selector)
if err != nil {
return nil, err
}
pods, err := client.Pods(namespace).List(
api.ListOptions{
LabelSelector: labelSelector,
FieldSelector: fields.Everything(),
})
if err != nil {
return nil, err
}
daemonSetAndPods := &DaemonSetWithPods{
DaemonSet: daemonSet,
Pods: pods,
}
return daemonSetAndPods, nil
}
示例14: GetJobDetail
// GetJobDetail gets job details.
func GetJobDetail(client k8sClient.Interface, heapsterClient client.HeapsterClient,
namespace, name string) (*JobDetail, error) {
log.Printf("Getting details of %s service in %s namespace", name, namespace)
// TODO(floreks): Use channels.
jobData, err := client.Extensions().Jobs(namespace).Get(name)
if err != nil {
return nil, err
}
channels := &common.ResourceChannels{
PodList: common.GetPodListChannel(client, common.NewSameNamespaceQuery(namespace), 1),
}
pods := <-channels.PodList.List
if err := <-channels.PodList.Error; err != nil {
return nil, err
}
events, err := GetJobEvents(client, jobData.Namespace, jobData.Name)
if err != nil {
return nil, err
}
job := getJobDetail(jobData, heapsterClient, events, pods.Items)
return &job, nil
}
示例15: GetJobDetail
// GetJobDetail gets job details.
func GetJobDetail(client k8sClient.Interface, heapsterClient client.HeapsterClient,
namespace, name string) (*JobDetail, error) {
// TODO(floreks): Use channels.
jobData, err := client.Extensions().Jobs(namespace).Get(name)
if err != nil {
return nil, err
}
podList, err := GetJobPods(client, heapsterClient, dataselect.DefaultDataSelectWithMetrics, namespace, name)
if err != nil {
return nil, err
}
podInfo, err := getJobPodInfo(client, jobData)
if err != nil {
return nil, err
}
eventList, err := GetJobEvents(client, dataselect.DefaultDataSelect, jobData.Namespace, jobData.Name)
if err != nil {
return nil, err
}
job := getJobDetail(jobData, heapsterClient, *eventList, *podList, *podInfo)
return &job, nil
}