本文整理汇总了Java中io.fabric8.kubernetes.client.dsl.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于io.fabric8.kubernetes.client.dsl包,在下文中一共展示了Resource类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServicesByLabel
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
private static ServiceList getServicesByLabel(Map<String, String> labels, KubernetesClient client)
throws KubernetesClientException {
Objects.requireNonNull(client, "no client available");
final MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>>
services = client.services();
final FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>>
listable = createLabelFilterQuery(labels, services);
return listable.list();
}
示例2: createLabelFilterQuery
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
private static FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>>
createLabelFilterQuery(
Map<String, String> labels,
MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>>
services) {
FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>> listable =
null;
for (Entry<String, String> entry : labels.entrySet()) {
listable =
listable == null
? services.withLabel(entry.getKey(), entry.getValue())
: listable.withLabel(entry.getKey(), entry.getValue());
}
return listable;
}
示例3: testOpenShiftProjectCreationWhenProjectDoesNotExist
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
@Test
public void testOpenShiftProjectCreationWhenProjectDoesNotExist() throws Exception {
// given
MetadataNested projectMetadata = prepareProjectRequest();
Resource resource = prepareProjectResource(PROJECT_NAME);
doThrow(new KubernetesClientException("error", 403, null)).when(resource).get();
// when
OpenShiftProject openShiftProject =
new OpenShiftProject(clientFactory, PROJECT_NAME, WORKSPACE_ID);
// then
verify(projectMetadata).withName(PROJECT_NAME);
}
示例4: prepareProjectResource
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
private Resource prepareProjectResource(String projectName) {
Resource projectResource = mock(Resource.class);
NonNamespaceOperation projectOperation = mock(NonNamespaceOperation.class);
doReturn(projectResource).when(projectOperation).withName(projectName);
doReturn(projectOperation).when(openShiftClient).projects();
openShiftClient.projects().withName(projectName).get();
return projectResource;
}
示例5: addServiceAccountRole
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
private void addServiceAccountRole(String prjName, String name, String role) {
Resource<PolicyBinding, DoneablePolicyBinding> bindingResource =
delegate.policyBindings().inNamespace(prjName).withName(":default");
DoneablePolicyBinding binding;
if (bindingResource.get() == null) {
binding = bindingResource.createNew();
} else {
binding = bindingResource.edit();
}
binding.editOrNewMetadata()
.withName(":default")
.endMetadata()
.editOrNewPolicyRef()
.withName("default")
.endPolicyRef()
.addNewRoleBinding()
.withName(role)
.editOrNewRoleBinding()
.editOrNewMetadata()
.withName(role)
.withNamespace(prjName)
.endMetadata()
.addToUserNames("system:serviceaccount:" + prjName + ":" + name)
.addNewSubject()
.withName("default")
.withNamespace(prjName)
.withKind("ServiceAccount")
.endSubject()
.withNewRoleRef()
.withName(role)
.endRoleRef()
.endRoleBinding()
.endRoleBinding()
.done();
}
示例6: addSystemGroupRole
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
private void addSystemGroupRole(String prjName, String name, String role) {
Resource<PolicyBinding, DoneablePolicyBinding> bindingResource =
delegate.policyBindings().inNamespace(prjName).withName(":default");
DoneablePolicyBinding binding;
if (bindingResource.get() == null) {
binding = bindingResource.createNew();
} else {
binding = bindingResource.edit();
}
binding.editOrNewMetadata()
.withName(":default")
.endMetadata()
.editOrNewPolicyRef()
.withName("default")
.endPolicyRef()
.addNewRoleBinding()
.withName(role)
.editOrNewRoleBinding()
.editOrNewMetadata()
.withName(role)
.withNamespace(prjName)
.endMetadata()
.addToGroupNames("system:serviceaccounts:" + prjName)
.addNewSubject()
.withName("default")
.withNamespace(prjName)
.withKind("SystemGroup")
.endSubject()
.withNewRoleRef()
.withName(role)
.endRoleRef()
.endRoleBinding()
.endRoleBinding()
.done();
}
示例7: mockComponentStatus
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
private void mockComponentStatus(ComponentStatus result) {
@SuppressWarnings("unchecked")
Resource<ComponentStatus, DoneableComponentStatus> componentStatusResource = Mockito.mock(Resource.class);
when(componentStatusResource.get()).thenReturn(result);
when(this.mixedOperationMock.withName("controller-manager")).thenReturn(componentStatusResource);
}
示例8: testLogger
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
@Test
public void testLogger() {
String ns = "myspace";
String component = "me";
Clock clock = Clock.fixed(Instant.ofEpochSecond(10), ZoneId.of("UTC"));
String message = "it crashed";
KubernetesClient mockClient = mock(KubernetesClient.class);
MixedOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>> eventOperation = mock(MixedOperation.class);
Resource<Event, DoneableEvent> eventResource = mock(Resource.class);
when(mockClient.events()).thenReturn(eventOperation);
when(eventOperation.inNamespace(any())).thenReturn(eventOperation);
when(eventOperation.withName(startsWith("me."))).thenReturn(eventResource);
when(eventResource.get()).thenReturn(null);
EventLogger logger = new KubeEventLogger(mockClient, ns, clock, component);
logger.log(TestReason.NONE, "it crashed", Warning, TestKind.KIND, "myqueue");
ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventResource).create(eventArgumentCaptor.capture());
Event newEvent = eventArgumentCaptor.getValue();
assertNotNull(newEvent);
assertThat(newEvent.getMessage(), is(message));
assertThat(newEvent.getReason(), is(TestReason.NONE.name()));
assertThat(newEvent.getType(), is(Warning.name()));
assertThat(newEvent.getFirstTimestamp(), is(clock.instant().toString()));
assertThat(newEvent.getLastTimestamp(), is(clock.instant().toString()));
assertThat(newEvent.getCount(), is(1));
assertThat(newEvent.getInvolvedObject().getName(), is("myqueue"));
assertThat(newEvent.getInvolvedObject().getKind(), is(TestKind.KIND.name()));
newEvent.setFirstTimestamp(Instant.ofEpochSecond(5).toString());
when(eventResource.get()).thenReturn(newEvent);
logger.log(TestReason.NONE, "it crashed", Warning, TestKind.KIND, "myqueue");
eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventResource).create(eventArgumentCaptor.capture());
newEvent = eventArgumentCaptor.getValue();
assertNotNull(newEvent);
assertThat(newEvent.getMessage(), is(message));
assertThat(newEvent.getReason(), is(TestReason.NONE.name()));
assertThat(newEvent.getType(), is(Warning.name()));
assertThat(newEvent.getFirstTimestamp(), is(Instant.ofEpochSecond(5).toString()));
assertThat(newEvent.getLastTimestamp(), is(clock.instant().toString()));
assertThat(newEvent.getCount(), is(2));
}
示例9: prepareProject
import io.fabric8.kubernetes.client.dsl.Resource; //导入依赖的package包/类
private void prepareProject(String projectName) {
Project project = mock(Project.class);
Resource projectResource = prepareProjectResource(projectName);
doReturn(project).when(projectResource).get();
}