Skip to content

Commit

Permalink
Issue fabric8-services#143 Improving handling of OpenShift events
Browse files Browse the repository at this point in the history
  • Loading branch information
hferentschik committed Mar 2, 2018
1 parent 7bd6cd9 commit ccfec3f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
4 changes: 2 additions & 2 deletions internal/idler/user_idler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ func (idler *UserIdler) Run(wg *sync.WaitGroup, ctx context.Context, cancel cont
cancel()
return
case idler.user = <-idler.userChan:
idler.logger.WithField("data", idler.user.String()).Debug("Received user data.")
idler.logger.WithField("state", idler.user.String()).Debug("Received user data.")

err := idler.checkIdle()
if err != nil {
idler.logger.WithField("error", err.Error()).Warn("Error during idle check.")
}
case <-ticker:
idler.logger.Info("Time based idle check.")
idler.logger.WithField("state", idler.user.String()).Info("Time based idle check.")
idler.resetCounters()
err := idler.checkIdle()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/model/openshift_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s DCStatus) GetByType(t string) (Condition, error) {
}
}

return Condition{}, fmt.Errorf("Could not find condition '%s'", t)
return Condition{}, fmt.Errorf("could not find condition '%s'", t)
}

var Phases = map[string]int{
Expand Down
7 changes: 0 additions & 7 deletions internal/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ type User struct {
ID string
ActiveBuild Build
DoneBuild Build
JenkinsStateList []JenkinsState
JenkinsLastUpdate time.Time
}

type JenkinsState struct {
Running bool
Time time.Time
Message string
}

func NewUser(id string, name string) User {
return User{
ID: id,
Expand Down
4 changes: 2 additions & 2 deletions internal/openshift/client/openshift_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (o OpenShift) WatchBuilds(namespace string, buildType string, callback func
logger.WithField("namespace", o.Object.Metadata.Namespace).Debugf("Skipping build %s (type: %s)", o.Object.Metadata.Name, o.Object.Spec.Strategy.Type)
continue
}
logger.WithField("namespace", o.Object.Metadata.Namespace).Debug("Handling Build change event")
logger.WithFields(log.Fields{"namespace": o.Object.Metadata.Namespace, "data": o}).Debug("Handling Build change event")
err = callback(o)
if err != nil {
logger.Errorf("Error from callback: %s", err)
Expand Down Expand Up @@ -402,7 +402,7 @@ func (o OpenShift) WatchDeploymentConfigs(namespace string, nsSuffix string, cal
continue
}

logger.WithField("namespace", o.Object.Metadata.Namespace).Debug("Handling DC change event")
logger.WithFields(log.Fields{"namespace": o.Object.Metadata.Namespace, "data": o}).Debug("Handling DC change event")
err = callback(o)
if err != nil {
logger.Errorf("Error from DC callback: %s", err)
Expand Down
6 changes: 1 addition & 5 deletions internal/openshift/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ func (oc *OpenShiftController) GetUser(ns string) model.User {
// just does couple comparisons and returns
func (oc *OpenShiftController) HandleBuild(o model.Object) error {
ns := o.Object.Metadata.Namespace
logger.WithField("ns", ns).Infof("Processing build event '%s'", o.Object.Metadata.Name)

err := oc.createIfNotExist(o.Object.Metadata.Namespace)
err := oc.createIfNotExist(ns)
if err != nil {
return err
}
Expand Down Expand Up @@ -112,8 +110,6 @@ func (oc *OpenShiftController) HandleBuild(o model.Object) error {
// of ConfigChange or manual intervention.
func (oc *OpenShiftController) HandleDeploymentConfig(dc model.DCObject) error {
ns := dc.Object.Metadata.Namespace[:len(dc.Object.Metadata.Namespace)-len(jenkinsNamespaceSuffix)]
logger.WithField("ns", ns).Infof("Processing deployment config change event '%s'", dc.Object.Metadata.Name)

err := oc.createIfNotExist(ns)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions scripts/setupLocalIdler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ setTokens() {
# None
###############################################################################
login() {
[ -z "${DSAAS_PREVIEW_TOKEN}" ] && echo "DSAAS_PREVIEW_TOKEN needs to be exported." && printHelp && exit 1
[ -z "${DSAAS_PREVIEW_TOKEN}" ] && echo "DSAAS_PREVIEW_TOKEN needs to be exported." && exit 1

loc login https://api.rh-idev.openshift.com -n dsaas-preview --token=${DSAAS_PREVIEW_TOKEN} >/dev/null
}
Expand All @@ -202,7 +202,7 @@ login() {
# None
###############################################################################
start() {
[ -z "${DSAAS_PREVIEW_TOKEN}" ] && echo "DSAAS_PREVIEW_TOKEN needs to be exported." && printHelp && exit 1
[ -z "${DSAAS_PREVIEW_TOKEN}" ] && echo "DSAAS_PREVIEW_TOKEN needs to be exported." && exit 1

login
forwardProxyService &
Expand All @@ -220,8 +220,8 @@ start() {
# None
###############################################################################
env() {
[ -z "${DSAAS_PREVIEW_TOKEN}" ] && echo "DSAAS_PREVIEW_TOKEN needs to be exported." && printHelp && exit 1
[ -z "${JC_FIXED_UUIDS}" ] && echo "JC_FIXED_UUID needs to be exported." && printHelp && exit 1
[ -z "${DSAAS_PREVIEW_TOKEN}" ] && echo "DSAAS_PREVIEW_TOKEN needs to be exported." && exit 1
[ -z "${JC_FIXED_UUIDS}" ] && echo "JC_FIXED_UUIDS needs to be exported." && exit 1

login
setTokens
Expand Down

0 comments on commit ccfec3f

Please sign in to comment.