Skip to content

Commit

Permalink
feat: support reference model for workloads (argoproj#676)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <[email protected]>
  • Loading branch information
alexmt committed Apr 9, 2021
1 parent 959a4a5 commit 14aee5e
Show file tree
Hide file tree
Showing 17 changed files with 863 additions and 137 deletions.
4 changes: 4 additions & 0 deletions cmd/rollouts-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic/dynamicinformer"
kubeinformers "k8s.io/client-go/informers"
Expand Down Expand Up @@ -97,6 +98,8 @@ func newCommand() *cobra.Command {
checkError(err)
dynamicClient, err := dynamic.NewForConfig(config)
checkError(err)
discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
checkError(err)
smiClient, err := smiclientset.NewForConfig(config)
resyncDuration := time.Duration(rolloutResyncPeriod) * time.Second
kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(
Expand Down Expand Up @@ -130,6 +133,7 @@ func newCommand() *cobra.Command {
rolloutClient,
dynamicClient,
smiClient,
discoveryClient,
kubeInformerFactory.Apps().V1().ReplicaSets(),
kubeInformerFactory.Core().V1().Services(),
kubeInformerFactory.Extensions().V1beta1().Ingresses(),
Expand Down
9 changes: 9 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/apimachinery/pkg/util/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
appsinformers "k8s.io/client-go/informers/apps/v1"
batchinformers "k8s.io/client-go/informers/batch/v1"
Expand Down Expand Up @@ -85,6 +86,8 @@ type Manager struct {
experimentWorkqueue workqueue.RateLimitingInterface
analysisRunWorkqueue workqueue.RateLimitingInterface

refResolver rollout.TemplateRefResolver

dynamicClientSet dynamic.Interface

namespace string
Expand All @@ -97,6 +100,7 @@ func NewManager(
argoprojclientset clientset.Interface,
dynamicclientset dynamic.Interface,
smiclientset smiclientset.Interface,
discoveryClient discovery.DiscoveryInterface,
replicaSetInformer appsinformers.ReplicaSetInformer,
servicesInformer coreinformers.ServiceInformer,
ingressesInformer extensionsinformers.IngressInformer,
Expand Down Expand Up @@ -141,11 +145,14 @@ func NewManager(
serviceWorkqueue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Services")
ingressWorkqueue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Ingresses")

refResolver := rollout.NewInformerBasedWorkloadRefResolver(namespace, dynamicclientset, discoveryClient, rolloutWorkqueue, rolloutsInformer.Informer())

rolloutController := rollout.NewController(rollout.ControllerConfig{
Namespace: namespace,
KubeClientSet: kubeclientset,
ArgoProjClientset: argoprojclientset,
DynamicClientSet: dynamicclientset,
RefResolver: refResolver,
SmiClientSet: smiclientset,
ExperimentInformer: experimentsInformer,
AnalysisRunInformer: analysisRunInformer,
Expand Down Expand Up @@ -238,6 +245,7 @@ func NewManager(
experimentController: experimentController,
analysisController: analysisController,
dynamicClientSet: dynamicclientset,
refResolver: refResolver,
namespace: namespace,
}

Expand All @@ -255,6 +263,7 @@ func (c *Manager) Run(rolloutThreadiness, serviceThreadiness, ingressThreadiness
defer c.rolloutWorkqueue.ShutDown()
defer c.experimentWorkqueue.ShutDown()
defer c.analysisRunWorkqueue.ShutDown()

// Wait for the caches to be synced before starting workers
log.Info("Waiting for controller's informer caches to sync")
if ok := cache.WaitForCacheSync(stopCh, c.serviceSynced, c.ingressSynced, c.jobSynced, c.rolloutSynced, c.experimentSynced, c.analysisRunSynced, c.analysisTemplateSynced, c.replicasSetSynced); !ok {
Expand Down
39 changes: 39 additions & 0 deletions examples/rollout-template-ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/instance: rollout-canary
name: rollout-ref-deployment
spec:
replicas: 0
selector:
matchLabels:
app: rollout-ref-deployment
template:
metadata:
labels:
app: rollout-ref-deployment
spec:
containers:
- name: rollouts-demo
image: argoproj/rollouts-demo:blue
imagePullPolicy: Always
ports:
- containerPort: 8080
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-ref-deployment
spec:
replicas: 5
revisionHistoryLimit: 2
templateRef:
apiVersion: apps/v1
kind: Deployment
name: rollout-ref-deployment
strategy:
canary:
steps:
- setWeight: 20
- pause: {duration: 10s}
Loading

0 comments on commit 14aee5e

Please sign in to comment.