Skip to content

Commit

Permalink
deploy: merge deployment config controller and generic trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik committed Jun 27, 2017
1 parent 28777df commit 9f86a34
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 522 deletions.
12 changes: 0 additions & 12 deletions pkg/cmd/server/bootstrappolicy/controller_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ func init() {
rbac.NewRule("create", "get", "list", "watch", "update", "patch", "delete").Groups(kapiGroup).Resources("replicationcontrollers").RuleOrDie(),
rbac.NewRule("update").Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs/status").RuleOrDie(),
rbac.NewRule("get", "list", "watch").Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs").RuleOrDie(),
eventsRule(),
},
})

// deployment-trigger-controller
addControllerRole(rbac.ClusterRole{
ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + InfraDeploymentTriggerControllerServiceAccountName},
Rules: []rbac.PolicyRule{
rbac.NewRule("get", "list", "watch").Groups(kapiGroup).Resources("replicationcontrollers").RuleOrDie(),
rbac.NewRule("get", "list", "watch").Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs").RuleOrDie(),
rbac.NewRule("get", "list", "watch").Groups(imageGroup, legacyImageGroup).Resources("imagestreams").RuleOrDie(),

rbac.NewRule("create").Groups(deployGroup, legacyDeployGroup).Resources("deploymentconfigs/instantiate").RuleOrDie(),
eventsRule(),
},
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/server/bootstrappolicy/infra_sa_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const (
InfraBuildControllerServiceAccountName = "build-controller"
InfraBuildConfigChangeControllerServiceAccountName = "build-config-change-controller"
InfraDeploymentConfigControllerServiceAccountName = "deploymentconfig-controller"
InfraDeploymentTriggerControllerServiceAccountName = "deployment-trigger-controller"
InfraDeployerControllerServiceAccountName = "deployer-controller"
InfraImageTriggerControllerServiceAccountName = "image-trigger-controller"
InfraImageImportControllerServiceAccountName = "image-import-controller"
Expand Down
24 changes: 0 additions & 24 deletions pkg/cmd/server/origin/controller/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
deployercontroller "github.com/openshift/origin/pkg/deploy/controller/deployer"
deployconfigcontroller "github.com/openshift/origin/pkg/deploy/controller/deploymentconfig"
triggercontroller "github.com/openshift/origin/pkg/deploy/controller/generictrigger"
)

type DeployerControllerConfig struct {
Expand All @@ -21,10 +20,6 @@ type DeploymentConfigControllerConfig struct {
Codec runtime.Codec
}

type DeploymentTriggerControllerConfig struct {
Codec runtime.Codec
}

func (c *DeployerControllerConfig) RunController(ctx ControllerContext) (bool, error) {
kubeClient, err := ctx.ClientBuilder.Client(bootstrappolicy.InfraDeployerControllerServiceAccountName)
if err != nil {
Expand Down Expand Up @@ -66,22 +61,3 @@ func (c *DeploymentConfigControllerConfig) RunController(ctx ControllerContext)

return true, nil
}

func (c *DeploymentTriggerControllerConfig) RunController(ctx ControllerContext) (bool, error) {
saName := bootstrappolicy.InfraDeploymentTriggerControllerServiceAccountName

deprecatedOcTriggerClient, err := ctx.ClientBuilder.DeprecatedOpenshiftClient(saName)
if err != nil {
return true, err
}

go triggercontroller.NewDeploymentTriggerController(
ctx.AppInformers.Apps().InternalVersion().DeploymentConfigs().Informer(),
ctx.ExternalKubeInformers.Core().V1().ReplicationControllers().Informer(),
ctx.ImageInformers.Image().InternalVersion().ImageStreams().Informer(),
deprecatedOcTriggerClient,
c.Codec,
).Run(5, ctx.Stop)

return true, nil
}
6 changes: 2 additions & 4 deletions pkg/cmd/server/origin/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ type OpenshiftControllerConfig struct {

BuildControllerConfig BuildControllerConfig

DeployerControllerConfig DeployerControllerConfig
DeploymentConfigControllerConfig DeploymentConfigControllerConfig
DeploymentTriggerControllerConfig DeploymentTriggerControllerConfig
DeployerControllerConfig DeployerControllerConfig
DeploymentConfigControllerConfig DeploymentConfigControllerConfig

ImageTriggerControllerConfig ImageTriggerControllerConfig
ImageImportControllerConfig ImageImportControllerConfig
Expand Down Expand Up @@ -44,7 +43,6 @@ func (c *OpenshiftControllerConfig) GetControllerInitializers() (map[string]Init

ret["openshift.io/deployer"] = c.DeployerControllerConfig.RunController
ret["openshift.io/deploymentconfig"] = c.DeploymentConfigControllerConfig.RunController
ret["openshift.io/deploymenttrigger"] = c.DeploymentTriggerControllerConfig.RunController

ret["openshift.io/image-trigger"] = c.ImageTriggerControllerConfig.RunController
ret["openshift.io/image-import"] = c.ImageImportControllerConfig.RunController
Expand Down
3 changes: 0 additions & 3 deletions pkg/cmd/server/origin/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,6 @@ func BuildOpenshiftControllerConfig(options configapi.MasterConfig, informers In
ret.DeploymentConfigControllerConfig = origincontrollers.DeploymentConfigControllerConfig{
Codec: annotationCodec,
}
ret.DeploymentTriggerControllerConfig = origincontrollers.DeploymentTriggerControllerConfig{
Codec: annotationCodec,
}

ret.ImageTriggerControllerConfig = origincontrollers.ImageTriggerControllerConfig{
HasBuilderEnabled: options.DisabledFeatures.Has(configapi.FeatureBuilder),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type DeploymentConfigController struct {
func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig) error {
glog.V(5).Infof("Reconciling %s/%s", config.Namespace, config.Name)
// There's nothing to reconcile until the version is nonzero.
if config.Status.LatestVersion == 0 {
if config.Status.LatestVersion == 0 && !deployutil.HasChangeTrigger(config) {
return c.updateStatus(config, []*v1.ReplicationController{})
}

Expand Down Expand Up @@ -181,6 +181,30 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig)
c.recorder.Eventf(config, v1.EventTypeNormal, "DeploymentAwaitingCancellation", "Deployment of version %d awaiting cancellation of older running deployments", config.Status.LatestVersion)
return fmt.Errorf("found previous inflight deployment for %s - requeuing", deployutil.LabelForDeploymentConfig(config))
}
// If we already have latest deployment running but the config template does not match
// the latest deployment assume this is a config change and trigger a new deployment if
// the config change trigger is enabled.
if deployutil.HasChangeTrigger(config) && !config.Spec.Paused {
needRollout := false
if config.Status.LatestVersion == 0 {
glog.V(4).Infof("Rolling out initial deployment for %s/%s", config.Namespace, config.Name)
needRollout = true
} else if latestIsDeployed {
if ok, changes, err := deployutil.HasLatestPodTemplate(config, latestDeployment); !ok || err != nil {
if err != nil {
glog.Errorf("Error while checking for latest pod template in replication controller: %v", err)
} else {
glog.V(4).Infof("Rolling out #%d deployment for %s/%s caused by config change, diff: %s", config.Status.LatestVersion+1, config.Namespace, config.Name, changes)
needRollout = true
}
}
}
if needRollout {
deployutil.RecordConfigChangeCause(config)
config.Status.LatestVersion++
return c.updateStatus(config, existingDeployments)
}
}
// If the latest deployment already exists, reconcile existing deployments
// and return early.
if latestIsDeployed {
Expand Down
1 change: 0 additions & 1 deletion pkg/deploy/controller/deploymentconfig/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func (c *DeploymentConfigController) updateDeploymentConfig(old, cur interface{}
if newDc.ResourceVersion == oldDc.ResourceVersion {
return
}

glog.V(4).Infof("Updating deployment config %q", newDc.Name)
c.enqueueDeploymentConfig(newDc)
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9f86a34

Please sign in to comment.