Commit f9317f86 authored by Edmund Ochieng's avatar Edmund Ochieng

remove unstable v1alpha1 nginxingresscontroller api

parent f29f7ba8
package gitlab
import (
nginxv1alpha1 "github.com/nginxinc/nginx-ingress-operator/pkg/apis/k8s/v1alpha1"
gitlabv1beta1 "gitlab.com/gitlab-org/gl-openshift/gitlab-operator/api/v1beta1"
gitlabutils "gitlab.com/gitlab-org/gl-openshift/gitlab-operator/controllers/utils"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
......@@ -9,8 +8,8 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)
// IngressAnnotations generates annotation for ingresses
func IngressAnnotations(cr *gitlabv1beta1.GitLab, annotate bool) map[string]string {
// EndpointAnnotations generates annotation for ingresses
func EndpointAnnotations(cr *gitlabv1beta1.GitLab, annotate bool) map[string]string {
annotation := map[string]string{
"kubernetes.io/ingress.class": "nginx",
}
......@@ -22,35 +21,6 @@ func IngressAnnotations(cr *gitlabv1beta1.GitLab, annotate bool) map[string]stri
return annotation
}
// IngressController returns nginx ingress controller
func IngressController(cr *gitlabv1beta1.GitLab) *nginxv1alpha1.NginxIngressController {
labels := gitlabutils.Label(cr.Name, "ingress-controller", gitlabutils.GitlabType)
var replicas int32 = 1
return &nginxv1alpha1.NginxIngressController{
ObjectMeta: metav1.ObjectMeta{
Name: "gitlab-ingress-controller",
Namespace: cr.Namespace,
Labels: labels,
},
Spec: nginxv1alpha1.NginxIngressControllerSpec{
EnableCRDs: true,
Image: nginxv1alpha1.Image{
Repository: "docker.io/nginx/nginx-ingress",
Tag: "1.6.3-ubi",
PullPolicy: "Always",
},
// IngressClass: "gitlab",
// UseIngressClassOnly: true,
NginxPlus: false,
Replicas: &replicas,
ServiceType: "NodePort",
Type: "deployment",
},
}
}
// Ingress returns Ingress object used for GitLab
func Ingress(cr *gitlabv1beta1.GitLab) *extensionsv1beta1.Ingress {
labels := gitlabutils.Label(cr.Name, "ingress", gitlabutils.GitlabType)
......@@ -60,7 +30,7 @@ func Ingress(cr *gitlabv1beta1.GitLab) *extensionsv1beta1.Ingress {
Name: cr.Name + "-gitlab-ingress",
Namespace: cr.Namespace,
Labels: labels,
Annotations: IngressAnnotations(cr, RequiresCertManagerCertificate(cr).GitLab()),
Annotations: EndpointAnnotations(cr, RequiresCertManagerCertificate(cr).GitLab()),
},
Spec: extensionsv1beta1.IngressSpec{
Rules: []extensionsv1beta1.IngressRule{
......@@ -107,7 +77,7 @@ func RegistryIngress(cr *gitlabv1beta1.GitLab) *extensionsv1beta1.Ingress {
Name: cr.Name + "-registry-ingress",
Namespace: cr.Namespace,
Labels: labels,
Annotations: IngressAnnotations(cr, RequiresCertManagerCertificate(cr).Registry()),
Annotations: EndpointAnnotations(cr, RequiresCertManagerCertificate(cr).Registry()),
},
Spec: extensionsv1beta1.IngressSpec{
Rules: []extensionsv1beta1.IngressRule{
......
package gitlab
import (
"strings"
routev1 "github.com/openshift/api/route/v1"
gitlabv1beta1 "gitlab.com/gitlab-org/gl-openshift/gitlab-operator/api/v1beta1"
gitlabutils "gitlab.com/gitlab-org/gl-openshift/gitlab-operator/controllers/utils"
......@@ -8,76 +10,117 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)
func getGitlabRoute(cr *gitlabv1beta1.GitLab) *routev1.Route {
// MainRoute returns main GitLab application route
func MainRoute(cr *gitlabv1beta1.GitLab) *routev1.Route {
labels := gitlabutils.Label(cr.Name, "route", gitlabutils.GitlabType)
return &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-gitlab-route",
Namespace: cr.Namespace,
Labels: labels,
Name: cr.Name + "-gitlab",
Namespace: cr.Namespace,
Labels: labels,
Annotations: EndpointAnnotations(cr, RequiresCertManagerCertificate(cr).GitLab()),
},
Spec: routev1.RouteSpec{
Host: getGitlabURL(cr),
Path: "/",
To: routev1.RouteTargetReference{
Kind: "Service",
Name: cr.Name + "-gitlab",
Name: cr.Name + "-webservice",
},
Port: &routev1.RoutePort{
TargetPort: intstr.IntOrString{
IntVal: 8005,
IntVal: 8181,
},
},
TLS: getRouteTLSConfig(cr, labels["app.kubernetes.io/component:"]),
},
}
}
// Gitlab registry route
func getRegistryRoute(cr *gitlabv1beta1.GitLab) *routev1.Route {
// AdminRoute returns GitLab admin route
func AdminRoute(cr *gitlabv1beta1.GitLab) *routev1.Route {
labels := gitlabutils.Label(cr.Name, "route", gitlabutils.GitlabType)
return &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-registry-route",
Namespace: cr.Namespace,
Labels: labels,
Name: cr.Name + "-admin",
Namespace: cr.Namespace,
Labels: labels,
Annotations: EndpointAnnotations(cr, RequiresCertManagerCertificate(cr).GitLab()),
},
Spec: routev1.RouteSpec{
Path: "/",
Host: getGitlabURL(cr),
Path: "/admin/sidekiq",
To: routev1.RouteTargetReference{
Kind: "Service",
Name: cr.Name + "-gitlab",
Name: cr.Name + "-webservice",
},
Port: &routev1.RoutePort{
TargetPort: intstr.IntOrString{
IntVal: 8105,
IntVal: 8080,
},
},
},
}
}
// SSH route
func getSecureShellRoute(cr *gitlabv1beta1.GitLab) *routev1.Route {
// RegistryRoute returns GitLab registry route
func RegistryRoute(cr *gitlabv1beta1.GitLab) *routev1.Route {
labels := gitlabutils.Label(cr.Name, "route", gitlabutils.GitlabType)
return &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-ssh-route",
Namespace: cr.Namespace,
Labels: labels,
Name: cr.Name + "-registry",
Namespace: cr.Namespace,
Labels: labels,
Annotations: EndpointAnnotations(cr, RequiresCertManagerCertificate(cr).Registry()),
},
Spec: routev1.RouteSpec{
Host: getRegistryURL(cr),
Path: "/",
To: routev1.RouteTargetReference{
Kind: "Service",
Name: cr.Name + "-gitlab",
Name: cr.Name + "-registry",
},
Port: &routev1.RoutePort{
TargetPort: intstr.IntOrString{
IntVal: 22,
IntVal: 5000,
},
},
},
}
}
func getRouteTLSConfig(cr *gitlabv1beta1.GitLab, target string) *routev1.TLSConfig {
tlsSecretName := strings.Join([]string{cr.Name, target, "tls"}, "-")
var tlsCert, tlsKey, tlsCACert string
tlsData, err := gitlabutils.SecretData(tlsSecretName, cr.Namespace)
if err != nil {
return nil
}
if crt, ok := tlsData["tls.crt"]; ok {
tlsCert = crt
}
if key, ok := tlsData["tls.key"]; ok {
tlsKey = key
}
if cacrt, ok := tlsData["ca.crt"]; ok {
tlsCACert = cacrt
}
if tlsCert != "" && tlsKey != "" {
return &routev1.TLSConfig{
Termination: routev1.TLSTerminationEdge,
Certificate: tlsCert,
Key: tlsKey,
CACertificate: tlsCACert,
}
}
return nil
}
......@@ -36,7 +36,7 @@ import (
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
certmanagerv1beta1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1beta1"
nginxv1alpha1 "github.com/nginxinc/nginx-ingress-operator/pkg/apis/k8s/v1alpha1"
routev1 "github.com/openshift/api/route/v1"
gitlabv1beta1 "gitlab.com/gitlab-org/gl-openshift/gitlab-operator/api/v1beta1"
gitlabctl "gitlab.com/gitlab-org/gl-openshift/gitlab-operator/controllers/gitlab"
gitlabutils "gitlab.com/gitlab-org/gl-openshift/gitlab-operator/controllers/utils"
......@@ -125,8 +125,8 @@ func (r *GitLabReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return ctrl.Result{}, err
}
// Deploy ingress to expose GitLab
if err := r.reconcileIngress(gitlab); err != nil {
// Deploy route is on Openshift, Ingress otherwise
if err := r.exposeGitLabInstance(gitlab); err != nil {
return ctrl.Result{}, err
}
......@@ -159,7 +159,7 @@ func (r *GitLabReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&monitoringv1.ServiceMonitor{}).
Owns(&certmanagerv1beta1.Issuer{}).
Owns(&certmanagerv1beta1.Certificate{}).
Owns(&nginxv1alpha1.NginxIngressController{}).
// Owns(&nginxv1alpha1.NginxIngressController{}).
Complete(r)
}
......@@ -559,28 +559,39 @@ func (r *GitLabReconciler) reconcileTaskRunnerDeployment(cr *gitlabv1beta1.GitLa
return r.Create(context.TODO(), tasker)
}
// func (r *GitLabReconciler) reconcileRoute(cr *gitlabv1beta1.GitLab) error {
// workhorse := getGitlabRoute(cr)
func (r *GitLabReconciler) exposeGitLabInstance(cr *gitlabv1beta1.GitLab) error {
// if gitlabutils.IsOpenshift() {
// return r.reconcileRoute(cr)
// }
// if err := r.createKubernetesResource(workhorse, cr); err != nil {
// return err
// }
return r.reconcileIngress(cr)
}
// registry := getRegistryRoute(cr)
func (r *GitLabReconciler) reconcileRoute(cr *gitlabv1beta1.GitLab) error {
app := gitlabctl.MainRoute(cr)
// if err := r.createKubernetesResource(registry, cr); err != nil {
// return err
// }
admin := gitlabctl.AdminRoute(cr)
// return nil
// }
registry := gitlabctl.RegistryRoute(cr)
func (r *GitLabReconciler) reconcileIngress(cr *gitlabv1beta1.GitLab) error {
controller := gitlabctl.IngressController(cr)
if err := r.createKubernetesResource(controller, nil); err != nil {
return err
var routes []*routev1.Route
routes = append(routes,
app,
admin,
registry,
)
for _, route := range routes {
if err := r.createKubernetesResource(route, cr); err != nil {
return err
}
}
return nil
}
func (r *GitLabReconciler) reconcileIngress(cr *gitlabv1beta1.GitLab) error {
var ingresses []*extensionsv1beta1.Ingress
gitlab := gitlabctl.Ingress(cr)
......
......@@ -31,7 +31,7 @@ import (
certmanagerv1beta1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1beta1"
// miniov1 "github.com/minio/operator/pkg/apis/minio.min.io/v1"
nginxv1alpha1 "github.com/nginxinc/nginx-ingress-operator/pkg/apis/k8s/v1alpha1"
// nginxv1alpha1 "github.com/nginxinc/nginx-ingress-operator/pkg/apis/k8s/v1alpha1"
routev1 "github.com/openshift/api/route/v1"
appsv1beta1 "gitlab.com/gitlab-org/gl-openshift/gitlab-operator/api/v1beta1"
"gitlab.com/gitlab-org/gl-openshift/gitlab-operator/controllers"
......@@ -56,7 +56,7 @@ func init() {
// utilruntime.Must(miniov1.AddToScheme(scheme))
utilruntime.Must(nginxv1alpha1.SchemeBuilder.AddToScheme(scheme))
// utilruntime.Must(nginxv1alpha1.SchemeBuilder.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment