本文整理汇总了Golang中github.com/openshift/origin/pkg/client.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetScopedClientForUser
func GetScopedClientForUser(adminClient *client.Client, clientConfig restclient.Config, username string, scopes []string) (*client.Client, *kclient.Client, *restclient.Config, error) {
// make sure the user exists
if _, _, _, err := GetClientForUser(clientConfig, username); err != nil {
return nil, nil, nil, err
}
user, err := adminClient.Users().Get(username)
if err != nil {
return nil, nil, nil, err
}
token := &oauthapi.OAuthAccessToken{
ObjectMeta: kapi.ObjectMeta{Name: fmt.Sprintf("%s-token-plus-some-padding-here-to-make-the-limit-%d", username, rand.Int())},
ClientName: origin.OpenShiftCLIClientID,
ExpiresIn: 86400,
Scopes: scopes,
RedirectURI: "https://127.0.0.1:12000/oauth/token/implicit",
UserName: user.Name,
UserUID: string(user.UID),
}
if _, err := adminClient.OAuthAccessTokens().Create(token); err != nil {
return nil, nil, nil, err
}
scopedConfig := clientcmd.AnonymousClientConfig(&clientConfig)
scopedConfig.BearerToken = token.Name
kubeClient, err := kclient.New(&scopedConfig)
if err != nil {
return nil, nil, nil, err
}
osClient, err := client.New(&scopedConfig)
if err != nil {
return nil, nil, nil, err
}
return osClient, kubeClient, &scopedConfig, nil
}
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:35,代码来源:client.go
示例2: createProject
func createProject(osClient *osclient.Client, clientConfig *restclient.Config, name string) (*sdnapi.NetNamespace, error) {
_, err := testserver.CreateNewProject(osClient, *clientConfig, name, name)
if err != nil {
return nil, fmt.Errorf("error creating project %q: %v", name, err)
}
backoff := utilwait.Backoff{
Duration: 100 * time.Millisecond,
Factor: 2,
Steps: 5,
}
var netns *sdnapi.NetNamespace
err = utilwait.ExponentialBackoff(backoff, func() (bool, error) {
netns, err = osClient.NetNamespaces().Get(name)
if kapierrors.IsNotFound(err) {
return false, nil
} else if err != nil {
return false, err
}
return true, nil
})
if err != nil {
return nil, fmt.Errorf("could not get NetNamepsace %q: %v", name, err)
}
return netns, nil
}
开发者ID:rootfs,项目名称:origin,代码行数:26,代码来源:sdn_test.go
示例3: getTokenInfo
func getTokenInfo(token string, osClient *osclient.Client) (string, *osintypes.InfoResponseData, error) {
osResult := osClient.Get().AbsPath("oauth", "info").Param("code", token).Do()
if osResult.Error() != nil {
return "", nil, fmt.Errorf("Error making info request: %v", osResult.Error())
}
body, err := osResult.Raw()
if err != nil {
return "", nil, fmt.Errorf("Error reading info response: %v\n", err)
}
glog.V(1).Infof("Raw JSON: %v\n", string(body))
var accessData osintypes.InfoResponseData
err = json.Unmarshal(body, &accessData)
if err != nil {
return "", nil, fmt.Errorf("Error while unmarshalling info response: %v %v", err, string(body))
}
if accessData.Error == "invalid_request" {
return "", nil, fmt.Errorf("\"%v\" is not a valid token.\n", token)
}
if len(accessData.ErrorDescription) != 0 {
return "", nil, fmt.Errorf("%v\n", accessData.ErrorDescription)
}
return string(body), &accessData, nil
}
开发者ID:jhadvig,项目名称:origin,代码行数:26,代码来源:validate.go
示例4: getProjects
func getProjects(oClient *client.Client) ([]api.Project, error) {
projects, err := oClient.Projects().List(labels.Everything(), fields.Everything())
if err != nil {
return nil, err
}
return projects.Items, nil
}
开发者ID:hloganathan,项目名称:origin,代码行数:7,代码来源:project.go
示例5: validateAndGetNetworkPluginName
func validateAndGetNetworkPluginName(originClient *osclient.Client, pluginName string) (string, error) {
if sdnplugin.IsOpenShiftNetworkPlugin(pluginName) {
// Detect any plugin mismatches between node and master
clusterNetwork, err := originClient.ClusterNetwork().Get(sdnapi.ClusterNetworkDefault)
if kerrs.IsNotFound(err) {
return "", fmt.Errorf("master has not created a default cluster network, network plugin %q can not start", pluginName)
} else if err != nil {
return "", fmt.Errorf("cannot fetch %q cluster network: %v", sdnapi.ClusterNetworkDefault, err)
}
if clusterNetwork.PluginName != strings.ToLower(pluginName) {
if len(clusterNetwork.PluginName) != 0 {
return "", fmt.Errorf("detected network plugin mismatch between OpenShift node(%q) and master(%q)", pluginName, clusterNetwork.PluginName)
} else {
// Do not return error in this case
glog.Warningf(`either there is network plugin mismatch between OpenShift node(%q) and master or OpenShift master is running an older version where we did not persist plugin name`, pluginName)
}
}
} else if pluginName == "" {
// Auto detect network plugin configured by master
clusterNetwork, err := originClient.ClusterNetwork().Get(sdnapi.ClusterNetworkDefault)
if err == nil {
return clusterNetwork.PluginName, nil
}
}
return pluginName, nil
}
开发者ID:rhamilto,项目名称:origin,代码行数:28,代码来源:node_config.go
示例6: describerMap
func describerMap(c *client.Client, kclient kclient.Interface, host string) map[string]kctl.Describer {
m := map[string]kctl.Describer{
"Build": &BuildDescriber{c, kclient},
"BuildConfig": &BuildConfigDescriber{c, host},
"BuildLog": &BuildLogDescriber{c},
"DeploymentConfig": NewDeploymentConfigDescriber(c, kclient),
"Identity": &IdentityDescriber{c},
"Image": &ImageDescriber{c},
"ImageStream": &ImageStreamDescriber{c},
"ImageStreamTag": &ImageStreamTagDescriber{c},
"ImageStreamImage": &ImageStreamImageDescriber{c},
"Route": &RouteDescriber{c},
"Project": &ProjectDescriber{c, kclient},
"Template": &TemplateDescriber{c, meta.NewAccessor(), kapi.Scheme, nil},
"Policy": &PolicyDescriber{c},
"PolicyBinding": &PolicyBindingDescriber{c},
"RoleBinding": &RoleBindingDescriber{c},
"Role": &RoleDescriber{c},
"ClusterPolicy": &ClusterPolicyDescriber{c},
"ClusterPolicyBinding": &ClusterPolicyBindingDescriber{c},
"ClusterRoleBinding": &ClusterRoleBindingDescriber{c},
"ClusterRole": &ClusterRoleDescriber{c},
"User": &UserDescriber{c},
"Group": &GroupDescriber{c.Groups()},
"UserIdentityMapping": &UserIdentityMappingDescriber{c},
}
return m
}
开发者ID:dctse,项目名称:openshift-cucumber,代码行数:28,代码来源:describer.go
示例7: getProjects
func getProjects(oClient *client.Client) ([]api.Project, error) {
projects, err := oClient.Projects().List(kapi.ListOptions{})
if err != nil {
return nil, err
}
return projects.Items, nil
}
开发者ID:erinboyd,项目名称:origin,代码行数:7,代码来源:project.go
示例8: RunGarbageCollectorController
// RunGarbageCollectorController starts generic garbage collection for the cluster.
func (c *MasterConfig) RunGarbageCollectorController(client *osclient.Client, config *restclient.Config) {
if !c.ControllerManager.EnableGarbageCollector {
return
}
groupVersionResources, err := client.Discovery().ServerPreferredResources()
if err != nil {
glog.Fatalf("Failed to get supported resources from server: %v", err)
}
config = restclient.AddUserAgent(config, "generic-garbage-collector")
config.ContentConfig.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: metaonly.NewMetadataCodecFactory()}
// TODO: needs to take GVR
metaOnlyClientPool := dynamic.NewClientPool(config, dynamic.LegacyAPIPathResolverFunc)
config.ContentConfig.NegotiatedSerializer = nil
// TODO: needs to take GVR
clientPool := dynamic.NewClientPool(config, dynamic.LegacyAPIPathResolverFunc)
garbageCollector, err := garbagecollector.NewGarbageCollector(metaOnlyClientPool, clientPool, groupVersionResources)
if err != nil {
glog.Fatalf("Failed to start the garbage collector: %v", err)
}
workers := int(c.ControllerManager.ConcurrentGCSyncs)
go garbageCollector.Run(workers, utilwait.NeverStop)
}
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:26,代码来源:master.go
示例9: loadTemplateData
func loadTemplateData(ns string, templateName string, c *k8sclient.Client, oc *oclient.Client) ([]byte, string, error) {
typeOfMaster := util.TypeOfMaster(c)
if typeOfMaster == util.Kubernetes {
catalogName := "catalog-" + templateName
configMap, err := c.ConfigMaps(ns).Get(catalogName)
if err != nil {
return nil, "", err
}
for k, v := range configMap.Data {
if strings.LastIndex(k, ".json") >= 0 {
return []byte(v), "json", nil
}
if strings.LastIndex(k, ".yml") >= 0 || strings.LastIndex(k, ".yaml") >= 0 {
return []byte(v), "yaml", nil
}
}
return nil, "", fmt.Errorf("Could not find a key for the catalog %s which ends with `.json` or `.yml`", catalogName)
} else {
template, err := oc.Templates(ns).Get(templateName)
if err != nil {
return nil, "", err
}
data, err := json.Marshal(template)
return data, "json", err
}
return nil, "", nil
}
开发者ID:fabric8io,项目名称:gofabric8,代码行数:28,代码来源:deploy.go
示例10: createRoutesForDomain
func createRoutesForDomain(ns string, domain string, c *k8sclient.Client, oc *oclient.Client, fac *cmdutil.Factory) error {
rc, err := c.Services(ns).List(labels.Everything())
if err != nil {
util.Errorf("Failed to load services in namespace %s with error %v", ns, err)
return err
}
items := rc.Items
for _, service := range items {
// TODO use the external load balancer as a way to know if we should create a route?
name := service.ObjectMeta.Name
if name != "kubernetes" {
routes := oc.Routes(ns)
_, err = routes.Get(name)
if err != nil {
hostName := name + "." + domain
route := rapi.Route{
ObjectMeta: kapi.ObjectMeta{
Name: name,
},
Host: hostName,
ServiceName: name,
}
// lets create the route
_, err = routes.Create(&route)
if err != nil {
util.Errorf("Failed to create the route %s with error %v", name, err)
return err
}
}
}
}
return nil
}
开发者ID:Dumidu,项目名称:gofabric8,代码行数:33,代码来源:routes.go
示例11: assignVNID
// assignVNID, revokeVNID and updateVNID methods updates in-memory structs and persists etcd objects
func (vmap *masterVNIDMap) assignVNID(osClient *osclient.Client, nsName string) error {
vmap.lock.Lock()
defer vmap.lock.Unlock()
netid, exists, err := vmap.allocateNetID(nsName)
if err != nil {
return err
}
if !exists {
// Create NetNamespace Object and update vnid map
netns := &osapi.NetNamespace{
TypeMeta: unversioned.TypeMeta{Kind: "NetNamespace"},
ObjectMeta: kapi.ObjectMeta{Name: nsName},
NetName: nsName,
NetID: netid,
}
_, err := osClient.NetNamespaces().Create(netns)
if err != nil {
vmap.releaseNetID(nsName)
return err
}
}
return nil
}
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:26,代码来源:vnids_master.go
示例12: updateNetNamespace
func updateNetNamespace(osClient *osclient.Client, netns *sdnapi.NetNamespace, action sdnapi.PodNetworkAction, args string) (*sdnapi.NetNamespace, error) {
sdnapi.SetChangePodNetworkAnnotation(netns, action, args)
_, err := osClient.NetNamespaces().Update(netns)
if err != nil {
return nil, err
}
backoff := utilwait.Backoff{
Duration: 100 * time.Millisecond,
Factor: 2,
Steps: 5,
}
name := netns.Name
err = utilwait.ExponentialBackoff(backoff, func() (bool, error) {
netns, err = osClient.NetNamespaces().Get(name)
if err != nil {
return false, err
}
if _, _, err := sdnapi.GetChangePodNetworkAnnotation(netns); err == sdnapi.ErrorPodNetworkAnnotationNotFound {
return true, nil
} else {
return false, nil
}
})
if err != nil {
return nil, err
}
return netns, nil
}
开发者ID:rootfs,项目名称:origin,代码行数:30,代码来源:sdn_test.go
示例13: getTemplates
func getTemplates(c *oclient.Client, ns string) *tapi.TemplateList {
templates, err := c.Templates(ns).List(api.ListOptions{})
if err != nil {
util.Fatalf("No Templates found in namespace %s\n", ns)
}
return templates
}
开发者ID:fabric8io,项目名称:gofabric8,代码行数:7,代码来源:secrets.go
示例14: describerMap
func describerMap(c *client.Client, kclient kclient.Interface, host string) map[unversioned.GroupKind]kctl.Describer {
m := map[unversioned.GroupKind]kctl.Describer{
buildapi.Kind("Build"): &BuildDescriber{c, kclient},
buildapi.Kind("BuildConfig"): &BuildConfigDescriber{c, host},
deployapi.Kind("DeploymentConfig"): &DeploymentConfigDescriber{c, kclient, nil},
authorizationapi.Kind("Identity"): &IdentityDescriber{c},
imageapi.Kind("Image"): &ImageDescriber{c},
imageapi.Kind("ImageStream"): &ImageStreamDescriber{c},
imageapi.Kind("ImageStreamTag"): &ImageStreamTagDescriber{c},
imageapi.Kind("ImageStreamImage"): &ImageStreamImageDescriber{c},
routeapi.Kind("Route"): &RouteDescriber{c, kclient},
projectapi.Kind("Project"): &ProjectDescriber{c, kclient},
templateapi.Kind("Template"): &TemplateDescriber{c, meta.NewAccessor(), kapi.Scheme, nil},
authorizationapi.Kind("Policy"): &PolicyDescriber{c},
authorizationapi.Kind("PolicyBinding"): &PolicyBindingDescriber{c},
authorizationapi.Kind("RoleBinding"): &RoleBindingDescriber{c},
authorizationapi.Kind("Role"): &RoleDescriber{c},
authorizationapi.Kind("ClusterPolicy"): &ClusterPolicyDescriber{c},
authorizationapi.Kind("ClusterPolicyBinding"): &ClusterPolicyBindingDescriber{c},
authorizationapi.Kind("ClusterRoleBinding"): &ClusterRoleBindingDescriber{c},
authorizationapi.Kind("ClusterRole"): &ClusterRoleDescriber{c},
oauthapi.Kind("OAuthAccessToken"): &OAuthAccessTokenDescriber{c},
userapi.Kind("User"): &UserDescriber{c},
userapi.Kind("Group"): &GroupDescriber{c.Groups()},
userapi.Kind("UserIdentityMapping"): &UserIdentityMappingDescriber{c},
quotaapi.Kind("ClusterResourceQuota"): &ClusterQuotaDescriber{c},
quotaapi.Kind("AppliedClusterResourceQuota"): &AppliedClusterQuotaDescriber{c},
}
return m
}
开发者ID:rhamilto,项目名称:origin,代码行数:30,代码来源:describer.go
示例15: ensureNamespaceExists
func ensureNamespaceExists(c *k8sclient.Client, oc *oclient.Client, ns string) error {
typeOfMaster := util.TypeOfMaster(c)
if typeOfMaster == util.Kubernetes {
nss := c.Namespaces()
_, err := nss.Get(ns)
if err != nil {
// lets assume it doesn't exist!
util.Infof("Creating new Namespace: %s\n", ns)
entity := kapi.Namespace{
ObjectMeta: kapi.ObjectMeta{Name: ns},
}
_, err := nss.Create(&entity)
return err
}
} else {
_, err := oc.Projects().Get(ns)
if err != nil {
// lets assume it doesn't exist!
request := projectapi.ProjectRequest{
ObjectMeta: kapi.ObjectMeta{Name: ns},
}
util.Infof("Creating new Project: %s\n", ns)
_, err := oc.ProjectRequests().Create(&request)
return err
}
}
return nil
}
开发者ID:gashcrumb,项目名称:gofabric8,代码行数:28,代码来源:deploy.go
示例16: runTemplate
func runTemplate(c *k8sclient.Client, oc *oclient.Client, appToRun string, ns string, domain string, apiserver string, pv bool) {
util.Info("\n\nInstalling: ")
util.Successf("%s\n\n", appToRun)
typeOfMaster := util.TypeOfMaster(c)
if typeOfMaster == util.Kubernetes {
jsonData, format, err := loadTemplateData(ns, appToRun, c, oc)
if err != nil {
printError("Failed to load app "+appToRun, err)
}
createTemplate(jsonData, format, appToRun, ns, domain, apiserver, c, oc, pv)
} else {
tmpl, err := oc.Templates(ns).Get(appToRun)
if err != nil {
printError("Failed to load template "+appToRun, err)
}
util.Infof("Loaded template with %d objects", len(tmpl.Objects))
processTemplate(tmpl, ns, domain, apiserver)
objectCount := len(tmpl.Objects)
util.Infof("Creating "+appToRun+" template resources from %d objects\n", objectCount)
for _, o := range tmpl.Objects {
err = processItem(c, oc, &o, ns, pv)
}
}
}
开发者ID:fabric8io,项目名称:gofabric8,代码行数:26,代码来源:deploy.go
示例17: getTemplates
func getTemplates(c *oclient.Client, ns string) *tapi.TemplateList {
rc, err := c.Templates(ns).List(labels.Everything(), fields.Everything())
if err != nil {
util.Fatalf("No Templates found in namespace %s\n", ns)
}
return rc
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:8,代码来源:secrets.go
示例18: adminCan
func adminCan(client *osclient.Client, action authorizationapi.AuthorizationAttributes) (bool, error) {
if resp, err := client.SubjectAccessReviews().Create(&authorizationapi.SubjectAccessReview{Action: action}); err != nil {
return false, err
} else if resp.Allowed {
return true, nil
}
return false, nil
}
开发者ID:nitintutlani,项目名称:origin,代码行数:8,代码来源:util.go
示例19: getNetworkInfo
func getNetworkInfo(osClient *osclient.Client) (*NetworkInfo, error) {
cn, err := osClient.ClusterNetwork().Get(osapi.ClusterNetworkDefault)
if err != nil {
return nil, err
}
return parseNetworkInfo(cn.Network, cn.ServiceNetwork)
}
开发者ID:pweil-,项目名称:origin,代码行数:8,代码来源:common.go
示例20: checkKibana
//checkKibana verifies the various integration points between Kibana and logging
func checkKibana(r types.DiagnosticResult, osClient *client.Client, kClient *kclient.Client, project string) {
oauthclient, err := osClient.OAuthClients().Get(kibanaProxyOauthClientName)
if err != nil {
r.Error("AGL0115", err, fmt.Sprintf("Error retrieving the OauthClient '%s': %s. Unable to check Kibana", kibanaProxyOauthClientName, err))
return
}
checkKibanaSecret(r, osClient, kClient, project, oauthclient)
checkKibanaRoutesInOauthClient(r, osClient, project, oauthclient)
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:10,代码来源:kibana.go
注:本文中的github.com/openshift/origin/pkg/client.Client类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论