Ejemplo n.º 1
0
func addVersionsToScheme(externalVersions ...unversioned.GroupVersion) {
	// add the internal version to Scheme
	api.AddToScheme(kapi.Scheme)
	// add the enabled external versions to Scheme
	for _, v := range externalVersions {
		if !registered.IsEnabledVersion(v) {
			glog.Errorf("Version %s is not enabled, so it will not be added to the Scheme.", v)
			continue
		}
		switch v {
		case v1.SchemeGroupVersion:
			v1.AddToScheme(kapi.Scheme)

		default:
			glog.Errorf("Version %s is not known, so it will not be added to the Scheme.", v)
			continue
		}
	}
}
Ejemplo n.º 2
0
func createRoutesForDomain(ns string, domain string, c *k8sclient.Client, oc *oclient.Client, fac *cmdutil.Factory) error {
	rapi.AddToScheme(kapi.Scheme)
	rapiv1.AddToScheme(kapi.Scheme)

	rc, err := c.Services(ns).List(kapi.ListOptions{})
	if err != nil {
		util.Errorf("Failed to load services in namespace %s with error %v", ns, err)
		return err
	}
	var labels = make(map[string]string)
	labels["provider"] = "fabric8"

	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{
						Labels: labels,
						Name:   name,
					},
					Spec: rapi.RouteSpec{
						Host: hostName,
						To:   kapi.ObjectReference{Name: 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
}
Ejemplo n.º 3
0
func createIngressForDomain(ns string, domain string, c *k8sclient.Client, fac *cmdutil.Factory) error {
	rapi.AddToScheme(kapi.Scheme)
	rapiv1.AddToScheme(kapi.Scheme)

	ingressClient := c.Extensions().Ingress(ns)
	ingresses, err := ingressClient.List(kapi.ListOptions{})
	if err != nil {
		util.Errorf("Failed to load ingresses in namespace %s with error %v", ns, err)
		return err
	}
	rc, err := c.Services(ns).List(kapi.ListOptions{})
	if err != nil {
		util.Errorf("Failed to load services in namespace %s with error %v", ns, err)
		return err
	}
	var labels = make(map[string]string)
	labels["provider"] = "fabric8"

	items := rc.Items
	for _, service := range items {
		name := service.ObjectMeta.Name
		serviceSpec := service.Spec
		found := false

		// TODO we should probably add an annotation to disable ingress creation
		if name != "jenkinshift" {
			for _, ingress := range ingresses.Items {
				if ingress.GetName() == name {
					found = true
					break
				}
				// TODO look for other ingresses with different names?
				for _, rule := range ingress.Spec.Rules {
					http := rule.HTTP
					if http != nil {
						for _, path := range http.Paths {
							ruleService := path.Backend.ServiceName
							if ruleService == name {
								found = true
								break
							}
						}
					}
				}
			}
			if !found {
				ports := serviceSpec.Ports
				hostName := name + "." + ns + "." + domain
				if len(ports) > 0 {
					rules := []extensions.IngressRule{}
					for _, port := range ports {
						rule := extensions.IngressRule{
							Host: hostName,
							IngressRuleValue: extensions.IngressRuleValue{
								HTTP: &extensions.HTTPIngressRuleValue{
									Paths: []extensions.HTTPIngressPath{
										{
											Backend: extensions.IngressBackend{
												ServiceName: name,
												// we need to use target port until https://github.com/nginxinc/kubernetes-ingress/issues/41 is fixed
												//ServicePort: intstr.FromInt(port.Port),
												ServicePort: port.TargetPort,
											},
										},
									},
								},
							},
						}
						rules = append(rules, rule)
					}
					ingress := extensions.Ingress{
						ObjectMeta: kapi.ObjectMeta{
							Labels: labels,
							Name:   name,
						},
						Spec: extensions.IngressSpec{
							Rules: rules,
						},
					}
					// lets create the ingress
					_, err = ingressClient.Create(&ingress)
					if err != nil {
						util.Errorf("Failed to create the ingress %s with error %v", name, err)
						return err
					}
				}
			}
		}
	}
	return nil
}