Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #209 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
Add info and move publicdomain to admin group
  • Loading branch information
ibuildthecloud authored May 17, 2019
2 parents d012941 + 32ad8df commit 18e676d
Show file tree
Hide file tree
Showing 63 changed files with 2,688 additions and 328 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/edit/raw_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func convertRuntime(t string) runtime.Object {
case types.ConfigType:
return &corev1.ConfigMap{}
case types.PublicDomainType:
return &riov1.PublicDomain{}
return &projectv1.PublicDomain{}
case types.RouterType:
return &riov1.Router{}
case types.FeatureType:
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/publicdomain/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/pkg/errors"
"github.com/rancher/rio/cli/pkg/clicontext"
"github.com/rancher/rio/cli/pkg/stack"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
name2 "github.com/rancher/rio/pkg/name"
)

Expand All @@ -20,8 +20,8 @@ func (a *Add) Run(ctx *clicontext.CLIContext) error {

namespace, name := stack.NamespaceAndName(ctx, target)

return ctx.Create(riov1.NewPublicDomain(namespace, name2.PublicDomain(domainName), riov1.PublicDomain{
Spec: riov1.PublicDomainSpec{
return ctx.Create(adminv1.NewPublicDomain(namespace, name2.PublicDomain(domainName), adminv1.PublicDomain{
Spec: adminv1.PublicDomainSpec{
DomainName: domainName,
TargetServiceName: name,
},
Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/rancher/axe/throwing"
"github.com/rancher/rio/cli/pkg/clicontext"
adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/types"
"github.com/rancher/wrangler/pkg/leader"
Expand Down Expand Up @@ -50,7 +51,7 @@ func register(ctx context.Context, rioContext *types.Context, h *handler) {
rioContext.Rio.Rio().V1().App().AddGenericHandler(ctx, "rio-app-tui", h.syncObject)
rioContext.Rio.Rio().V1().Service().AddGenericHandler(ctx, "rio-service-tui", h.syncObject)
rioContext.Rio.Rio().V1().Router().AddGenericHandler(ctx, "rio-router-tui", h.syncObject)
rioContext.Rio.Rio().V1().PublicDomain().AddGenericHandler(ctx, "rio-domain-tui", h.syncObject)
rioContext.Global.Admin().V1().PublicDomain().AddGenericHandler(ctx, "rio-domain-tui", h.syncObject)
rioContext.Rio.Rio().V1().ExternalService().AddGenericHandler(ctx, "rio-external-tui", h.syncObject)
}

Expand Down Expand Up @@ -80,7 +81,7 @@ func (h handler) syncObject(k string, object runtime.Object) (runtime.Object, er
go func() {
s <- struct{}{}
}()
case *riov1.PublicDomain:
case *adminv1.PublicDomain:
s := h.signals[publicdomainKind]
go func() {
s <- struct{}{}
Expand Down
31 changes: 14 additions & 17 deletions cli/pkg/clicontext/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ import (
"sync"
"time"

"k8s.io/apimachinery/pkg/api/errors"

multierror "github.com/hashicorp/go-multierror"

"github.com/rancher/wrangler/pkg/kv"

"github.com/docker/docker/pkg/namesgenerator"
"github.com/rancher/rio/cli/pkg/lookup"
"github.com/rancher/rio/cli/pkg/types"
clitypes "github.com/rancher/rio/cli/pkg/types"
projectv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/wrangler/pkg/kv"
"github.com/rancher/wrangler/pkg/merr"
"golang.org/x/sync/errgroup"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -88,7 +85,7 @@ func (c *CLIContext) getResource(r types.Resource) (ret types.Resource, err erro
case clitypes.ExternalServiceType:
r.Object, err = c.Rio.ExternalServices(r.Namespace).Get(r.Name, metav1.GetOptions{})
case clitypes.PublicDomainType:
r.Object, err = c.Rio.PublicDomains(r.Namespace).Get(r.Name, metav1.GetOptions{})
r.Object, err = c.Project.PublicDomains(r.Namespace).Get(r.Name, metav1.GetOptions{})
case clitypes.NamespaceType:
r.Object, err = c.Core.Namespaces().Get(r.Name, metav1.GetOptions{})
case clitypes.FeatureType:
Expand All @@ -115,23 +112,23 @@ func (c *CLIContext) DeleteResource(r types.Resource) (err error) {
case clitypes.ExternalServiceType:
err = c.Rio.ExternalServices(r.Namespace).Delete(r.Name, &metav1.DeleteOptions{})
case clitypes.PublicDomainType:
err = c.Rio.PublicDomains(r.Namespace).Delete(r.Name, &metav1.DeleteOptions{})
err = c.Project.PublicDomains(r.Namespace).Delete(r.Name, &metav1.DeleteOptions{})
case clitypes.BuildType:
err = c.Build.Builds(r.Namespace).Delete(r.Name, &metav1.DeleteOptions{})
case clitypes.AppType:
app := r.Object.(*riov1.App)
var errs multierror.Error
var errs []error
for _, rev := range app.Spec.Revisions {
newerr := c.Rio.Services(r.Namespace).Delete(rev.ServiceName, &metav1.DeleteOptions{})
if newerr != nil && !errors.IsNotFound(err) {
errs.Errors = append(errs.Errors, newerr)
errs = append(errs, newerr)
}
}
newerr := c.Rio.Apps(r.Namespace).Delete(r.Name, &metav1.DeleteOptions{})
if newerr != nil {
errs.Errors = append(errs.Errors, newerr)
errs = append(errs, newerr)
}
err = errs.ErrorOrNil()
err = merr.NewErrors(errs...)
default:
return fmt.Errorf("unknown delete type %s", r.Type)
}
Expand Down Expand Up @@ -160,8 +157,8 @@ func (c *CLIContext) Create(obj runtime.Object) (err error) {
_, err = c.Rio.Routers(o.Namespace).Create(o)
case *riov1.ExternalService:
_, err = c.Rio.ExternalServices(o.Namespace).Create(o)
case *riov1.PublicDomain:
_, err = c.Rio.PublicDomains(o.Namespace).Create(o)
case *projectv1.PublicDomain:
_, err = c.Project.PublicDomains(o.Namespace).Create(o)
default:
return fmt.Errorf("unknown delete type %v", reflect.TypeOf(obj))
}
Expand All @@ -182,8 +179,8 @@ func (c *CLIContext) UpdateObject(obj runtime.Object) (err error) {
_, err = c.Rio.ExternalServices(o.Namespace).Update(o)
case *projectv1.Feature:
_, err = c.Project.Features(o.Namespace).Update(o)
case *riov1.PublicDomain:
_, err = c.Rio.PublicDomains(o.Namespace).Update(o)
case *projectv1.PublicDomain:
_, err = c.Project.PublicDomains(o.Namespace).Update(o)
default:
return fmt.Errorf("unknown delete type %v", reflect.TypeOf(obj))
}
Expand Down Expand Up @@ -322,7 +319,7 @@ func (c *CLIContext) listNamespace(namespace, typeName string) (ret []runtime.Ob
}
return ret, err
case clitypes.PublicDomainType:
objs, err := c.Rio.PublicDomains(namespace).List(opts)
objs, err := c.Project.PublicDomains(namespace).List(opts)
for i := range objs.Items {
ret = append(ret, &objs.Items[i])
}
Expand Down
32 changes: 25 additions & 7 deletions modules/build/controllers/gitcommit/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (

func Register(ctx context.Context, rContext *types.Context) error {
h := Handler{
ctx: ctx,
appsCache: rContext.Rio.Rio().V1().App().Cache(),
services: rContext.Rio.Rio().V1().Service(),
ctx: ctx,
appsCache: rContext.Rio.Rio().V1().App().Cache(),
services: rContext.Rio.Rio().V1().Service(),
gitWatcherCache: rContext.Webhook.Gitwatcher().V1().GitWatcher().Cache(),
}

wupdator := webhookv1controller.UpdateGitCommitOnChange(rContext.Webhook.Gitwatcher().V1().GitCommit().Updater(), h.onChange)
Expand All @@ -29,9 +30,10 @@ func Register(ctx context.Context, rContext *types.Context) error {
}

type Handler struct {
ctx context.Context
appsCache riov1controller.AppCache
services riov1controller.ServiceController
ctx context.Context
appsCache riov1controller.AppCache
gitWatcherCache webhookv1controller.GitWatcherCache
services riov1controller.ServiceController
}

func (h Handler) updateBaseRevision(commit string, svc *riov1.Service) error {
Expand Down Expand Up @@ -69,13 +71,29 @@ func (h Handler) onChange(key string, obj *webhookv1.GitCommit) (*webhookv1.GitC
return nil, nil
}

service, err := h.services.Cache().Get(obj.Namespace, obj.Spec.GitWebHookReceiverName)
gitWatcher, err := h.gitWatcherCache.Get(obj.Namespace, obj.Spec.GitWatcherName)
if err != nil {
return nil, err
}

service, err := h.services.Cache().Get(obj.Namespace, obj.Spec.GitWatcherName)
if err != nil {
if errors.IsNotFound(err) {
return obj, nil
}
return obj, err
}

if obj.Spec.Commit == gitWatcher.Status.FirstCommit {
if service.Status.FirstRevision == "" && service.Status.FirstRevision != gitWatcher.Status.FirstCommit {
service = service.DeepCopy()
service.Status.FirstRevision = gitWatcher.Status.FirstCommit
_, err := h.services.Update(service)
return obj, err
}
return obj, nil
}

return obj, webhookv1.GitWebHookExecutionConditionHandled.Once(obj, func() (runtime.Object, error) {
appName, _ := services.AppAndVersion(service)
specCopy := service.Spec.DeepCopy()
Expand Down
13 changes: 8 additions & 5 deletions modules/build/controllers/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func (p *populator) populate(obj runtime.Object, ns *corev1.Namespace, os *objec
func populateBuild(service *riov1.Service, customRegistry, systemNamespace, domain string, os *objectset.ObjectSet) error {
// we only support setting imageBuild for primary container
rev := service.Spec.Build.Revision
if rev == "" {
rev = service.Status.FirstRevision
}
if rev == "" {
return nil
}
Expand Down Expand Up @@ -163,11 +166,11 @@ func populateBuild(service *riov1.Service, customRegistry, systemNamespace, doma
func populateWebhookAndSecrets(webhookService *riov1.Service, service *riov1.Service, os *objectset.ObjectSet) {
webhookReceiver := webhookv1.NewGitWatcher(service.Namespace, service.Name, webhookv1.GitWatcher{
Spec: webhookv1.GitWatcherSpec{
RepositoryURL: service.Spec.Build.Repo,
Enabled: true,
Push: true,
Tag: true,
Branch: service.Spec.Build.Branch,
RepositoryURL: service.Spec.Build.Repo,
Enabled: true,
Push: true,
Tag: true,
Branch: service.Spec.Build.Branch,
RepositoryCredentialSecretName: service.Spec.Build.Secret,
},
})
Expand Down
17 changes: 8 additions & 9 deletions modules/istio/controllers/istio/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
"github.com/rancher/rio/modules/istio/controllers/istio/populate"
"github.com/rancher/rio/modules/istio/pkg/istio/config"
adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
projectv1controller "github.com/rancher/rio/pkg/generated/controllers/admin.rio.cattle.io/v1"
adminv1controller "github.com/rancher/rio/pkg/generated/controllers/admin.rio.cattle.io/v1"
riov1controller "github.com/rancher/rio/pkg/generated/controllers/rio.cattle.io/v1"
"github.com/rancher/rio/types"
appsv1controller "github.com/rancher/wrangler-api/pkg/generated/controllers/apps/v1"
Expand Down Expand Up @@ -67,7 +66,7 @@ func Register(ctx context.Context, rContext *types.Context) error {
serviceApply: rContext.Apply.WithSetID(istioInjector).WithInjectorName(istioInjector),
apps: rContext.Rio.Rio().V1().App(),
services: rContext.Rio.Rio().V1().Service(),
publicDomainCache: rContext.Rio.Rio().V1().PublicDomain().Cache(),
publicDomainCache: rContext.Global.Admin().V1().PublicDomain().Cache(),
clusterDomain: rContext.Global.Admin().V1().ClusterDomain(),
secretCache: rContext.Core.Core().V1().Secret().Cache(),
nodeCache: rContext.Core.Core().V1().Node().Cache(),
Expand All @@ -85,7 +84,7 @@ func Register(ctx context.Context, rContext *types.Context) error {

relatedresource.Watch(ctx, "cluster-domain-service", s.resolve,
rContext.Global.Admin().V1().ClusterDomain(),
rContext.Rio.Rio().V1().PublicDomain())
rContext.Global.Admin().V1().PublicDomain())

relatedresource.Watch(ctx, "node-enpoint", s.resolveEndpoint,
rContext.Core.Core().V1().Endpoints(),
Expand Down Expand Up @@ -113,8 +112,8 @@ type istioDeployController struct {
serviceApply apply.Apply
apps riov1controller.AppController
services riov1controller.ServiceController
publicDomainCache riov1controller.PublicDomainCache
clusterDomain projectv1controller.ClusterDomainController
publicDomainCache adminv1controller.PublicDomainCache
clusterDomain adminv1controller.ClusterDomainController
secretCache corev1controller.SecretCache
nodeCache corev1controller.NodeCache
endpointCache corev1controller.EndpointsCache
Expand All @@ -140,7 +139,7 @@ func (i *istioDeployController) updateDaemonSets() error {
}

deepcopy := svc.DeepCopy()
deepcopy.Spec.SystemSpec.PodSpec.NodeSelector = map[string]string{
deepcopy.SystemSpec.PodSpec.NodeSelector = map[string]string{
nodeSelectorLabel: "true",
}
if _, err := i.services.Update(deepcopy); err != nil {
Expand Down Expand Up @@ -215,7 +214,7 @@ func (i *istioDeployController) resolve(namespace, name string, obj runtime.Obje
})
}
return keys, nil
case *riov1.PublicDomain:
case *adminv1.PublicDomain:
return []relatedresource.Key{
{
Name: constants.ClusterDomainName,
Expand Down Expand Up @@ -412,7 +411,7 @@ func setupConfigmapAndInjectors(ctx context.Context, rContext *types.Context) er
return nil
}

func ensureClusterDomain(ns string, clusterDomain projectv1controller.ClusterDomainClient) error {
func ensureClusterDomain(ns string, clusterDomain adminv1controller.ClusterDomainClient) error {
_, err := clusterDomain.Get(ns, constants.ClusterDomainName, metav1.GetOptions{})
if errors.IsNotFound(err) {
_, err := clusterDomain.Create(adminv1.NewClusterDomain(ns, constants.ClusterDomainName, adminv1.ClusterDomain{
Expand Down
5 changes: 3 additions & 2 deletions modules/istio/controllers/istio/populate/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"strconv"
"strings"

"github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"

"github.com/knative/pkg/apis/istio/v1alpha3"
"github.com/rancher/rio/modules/system/features/letsencrypt/pkg/issuers"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
"github.com/rancher/rio/pkg/constructors"
"github.com/rancher/wrangler/pkg/objectset"
Expand All @@ -22,7 +23,7 @@ var (
}
)

func Gateway(systemNamespace string, clusterDomain string, publicdomains []*riov1.PublicDomain, output *objectset.ObjectSet) {
func Gateway(systemNamespace string, clusterDomain string, publicdomains []*v1.PublicDomain, output *objectset.ObjectSet) {
// Istio Gateway
gws := v1alpha3.GatewaySpec{
Selector: map[string]string{
Expand Down
8 changes: 4 additions & 4 deletions modules/istio/controllers/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/constants"
projectv1controller "github.com/rancher/rio/pkg/generated/controllers/admin.rio.cattle.io/v1"
adminv1controller "github.com/rancher/rio/pkg/generated/controllers/admin.rio.cattle.io/v1"
riov1controller "github.com/rancher/rio/pkg/generated/controllers/rio.cattle.io/v1"
v1 "github.com/rancher/rio/pkg/generated/controllers/rio.cattle.io/v1"
services2 "github.com/rancher/rio/pkg/services"
Expand Down Expand Up @@ -40,7 +40,7 @@ func Register(ctx context.Context, rContext *types.Context) error {
secretCache: rContext.Core.Core().V1().Secret().Cache(),
externalServiceCache: rContext.Rio.Rio().V1().ExternalService().Cache(),
clusterDomainCache: rContext.Global.Admin().V1().ClusterDomain().Cache(),
publicDomainCache: rContext.Rio.Rio().V1().PublicDomain().Cache(),
publicDomainCache: rContext.Global.Admin().V1().PublicDomain().Cache(),
}

rContext.Rio.Rio().V1().Service().OnChange(ctx, serviceDomainUpdate, riov1controller.UpdateServiceOnChange(rContext.Rio.Rio().V1().Service().Updater(), sh.syncDomain))
Expand All @@ -56,8 +56,8 @@ type serviceHandler struct {
serviceCache v1.ServiceCache
secretCache corev1controller.SecretCache
externalServiceCache v1.ExternalServiceCache
clusterDomainCache projectv1controller.ClusterDomainCache
publicDomainCache riov1controller.PublicDomainCache
clusterDomainCache adminv1controller.ClusterDomainCache
publicDomainCache adminv1controller.PublicDomainCache
}

func (s *serviceHandler) populate(obj runtime.Object, namespace *corev1.Namespace, os *objectset.ObjectSet) error {
Expand Down
32 changes: 32 additions & 0 deletions modules/service/controllers/info/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package info

import (
"context"

adminv1 "github.com/rancher/rio/pkg/apis/admin.rio.cattle.io/v1"
"github.com/rancher/rio/pkg/version"
"github.com/rancher/rio/types"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Register(ctx context.Context, rContext *types.Context) error {
client := rContext.Global.Admin().V1().RioInfo()
newInfo := adminv1.NewRioInfo("", "rio", adminv1.RioInfo{
Status: adminv1.RioInfoStatus{
SystemNamespace: rContext.Namespace,
Version: version.Version,
GitCommit: version.GitCommit,
},
})

info, err := client.Get("rio", metav1.GetOptions{})
if errors.IsNotFound(err) {
_, err = client.Create(newInfo)
} else if err == nil {
info.Status = newInfo.Status
_, err = client.Update(info)
}

return err
}
Loading

0 comments on commit 18e676d

Please sign in to comment.