Skip to content

Commit

Permalink
Merge pull request #749 from alecmerdler/bugzilla-1654977
Browse files Browse the repository at this point in the history
Emit `InstallSucceeded` Event for CSV
  • Loading branch information
openshift-merge-robot authored Mar 12, 2019
2 parents 25a917e + 662248a commit 840d806
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 53 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/golang/mock v1.1.1
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f // indirect
github.com/grpc-ecosystem/grpc-gateway v1.7.0 // indirect
github.com/json-iterator/go v1.1.6 // indirect
github.com/maxbrunsfeld/counterfeiter v0.0.0-20181017030959-1aadac120687
github.com/openshift/api v3.9.1-0.20190129160438-bbc4289c54e0+incompatible
github.com/openshift/client-go v0.0.0-20190128154758-1540772775fa
Expand All @@ -41,5 +42,5 @@ require (
k8s.io/klog v0.2.0 // indirect
k8s.io/kube-aggregator v0.0.0-20190223015803-f706565beac0
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd
k8s.io/kubernetes v1.11.9-beta.0.0.20190305054513-b2539d50ae56
k8s.io/kubernetes v1.11.9-beta.0.0.20190311041124-ede55fd57298
)
55 changes: 51 additions & 4 deletions go.sum

Large diffs are not rendered by default.

34 changes: 15 additions & 19 deletions pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
case v1alpha1.CSVPhaseInstallReady:
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
if strategy == nil {
// parseStrategiesAndUpdateStatus sets CSV status
return
}

Expand All @@ -897,7 +896,6 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
case v1alpha1.CSVPhaseInstalling:
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
if strategy == nil {
// parseStrategiesAndUpdateStatus sets CSV status
return
}

Expand All @@ -907,7 +905,6 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
case v1alpha1.CSVPhaseSucceeded:
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
if strategy == nil {
// parseStrategiesAndUpdateStatus sets CSV status
return
}

Expand All @@ -921,30 +918,29 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
met, statuses, err := a.requirementAndPermissionStatus(out)
if err != nil {
logger.Info("invalid install strategy")
out.SetPhase(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonInvalidStrategy, fmt.Sprintf("install strategy invalid: %s", err.Error()), now)
out.SetPhaseWithEvent(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonInvalidStrategy, fmt.Sprintf("install strategy invalid: %s", err.Error()), now, a.recorder)
return
} else if !met {
out.SetRequirementStatus(statuses)
out.SetPhase(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonRequirementsNotMet, fmt.Sprintf("requirements no longer met"), now)
out.SetPhaseWithEvent(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonRequirementsNotMet, fmt.Sprintf("requirements no longer met"), now, a.recorder)
return
}

// Check if any generated resources are missing
if resErr := a.checkAPIServiceResources(out, certs.PEMSHA256); len(resErr) > 0 {
out.SetPhase(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonAPIServiceResourceIssue, resErr[0].Error(), now)
out.SetPhaseWithEvent(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonAPIServiceResourceIssue, resErr[0].Error(), now, a.recorder)
return
}

// Check if it's time to refresh owned APIService certs
if a.shouldRotateCerts(out) {
out.SetPhase(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonNeedsCertRotation, "owned APIServices need cert refresh", now)
out.SetPhaseWithEvent(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonNeedsCertRotation, "owned APIServices need cert refresh", now, a.recorder)
return
}

case v1alpha1.CSVPhaseFailed:
installer, strategy, _ := a.parseStrategiesAndUpdateStatus(out)
if strategy == nil {
// parseStrategiesAndUpdateStatus sets CSV status
return
}

Expand Down Expand Up @@ -985,26 +981,26 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
met, statuses, err := a.requirementAndPermissionStatus(out)
if err != nil {
logger.Warn("invalid install strategy")
out.SetPhase(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonInvalidStrategy, fmt.Sprintf("install strategy invalid: %s", err.Error()), now)
out.SetPhaseWithEvent(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonInvalidStrategy, fmt.Sprintf("install strategy invalid: %s", err.Error()), now, a.recorder)
return
} else if !met {
out.SetRequirementStatus(statuses)
out.SetPhase(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonRequirementsNotMet, fmt.Sprintf("requirements not met"), now)
out.SetPhaseWithEvent(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonRequirementsNotMet, fmt.Sprintf("requirements not met"), now, a.recorder)
return
}

// Check if any generated resources are missing
if resErr := a.checkAPIServiceResources(out, certs.PEMSHA256); len(resErr) > 0 {
// Check if API services are adoptable. If not, keep CSV as Failed state
if a.apiServiceResourceErrorsActionable(resErr) {
out.SetPhase(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonAPIServiceResourcesNeedReinstall, resErr[0].Error(), now)
out.SetPhaseWithEvent(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonAPIServiceResourcesNeedReinstall, resErr[0].Error(), now, a.recorder)
return
}
}

// Check if it's time to refresh owned APIService certs
if a.shouldRotateCerts(out) {
out.SetPhase(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonNeedsCertRotation, "owned APIServices need cert refresh", now)
out.SetPhaseWithEvent(v1alpha1.CSVPhasePending, v1alpha1.CSVReasonNeedsCertRotation, "owned APIServices need cert refresh", now, a.recorder)
return
}
case v1alpha1.CSVPhaseReplacing:
Expand Down Expand Up @@ -1104,7 +1100,7 @@ func (a *Operator) checkReplacementsAndUpdateStatus(csv *v1alpha1.ClusterService
if replacement := a.isBeingReplaced(csv, a.csvSet(csv.GetNamespace(), v1alpha1.CSVPhaseAny)); replacement != nil {
a.Log.Infof("newer ClusterServiceVersion replacing %s, no-op", csv.SelfLink)
msg := fmt.Sprintf("being replaced by csv: %s", replacement.SelfLink)
csv.SetPhase(v1alpha1.CSVPhaseReplacing, v1alpha1.CSVReasonBeingReplaced, msg, timeNow())
csv.SetPhaseWithEvent(v1alpha1.CSVPhaseReplacing, v1alpha1.CSVReasonBeingReplaced, msg, timeNow(), a.recorder)
metrics.CSVUpgradeCount.Inc()

return fmt.Errorf("replacing")
Expand All @@ -1120,24 +1116,24 @@ func (a *Operator) updateInstallStatus(csv *v1alpha1.ClusterServiceVersion, inst
if strategyInstalled && apiServicesInstalled {
// if there's no error, we're successfully running
if csv.Status.Phase != v1alpha1.CSVPhaseSucceeded {
csv.SetPhase(v1alpha1.CSVPhaseSucceeded, v1alpha1.CSVReasonInstallSuccessful, "install strategy completed with no errors", now)
csv.SetPhaseWithEvent(v1alpha1.CSVPhaseSucceeded, v1alpha1.CSVReasonInstallSuccessful, "install strategy completed with no errors", now, a.recorder)
}
return nil
}

// installcheck determined we can't progress (e.g. deployment failed to come up in time)
if install.IsErrorUnrecoverable(strategyErr) {
csv.SetPhase(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonInstallCheckFailed, fmt.Sprintf("install failed: %s", strategyErr), now)
csv.SetPhaseWithEvent(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonInstallCheckFailed, fmt.Sprintf("install failed: %s", strategyErr), now, a.recorder)
return strategyErr
}

if apiServiceErr != nil {
csv.SetPhase(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonAPIServiceInstallFailed, fmt.Sprintf("APIService install failed: %s", apiServiceErr), now)
csv.SetPhaseWithEvent(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonAPIServiceInstallFailed, fmt.Sprintf("APIService install failed: %s", apiServiceErr), now, a.recorder)
return apiServiceErr
}

if !apiServicesInstalled {
csv.SetPhase(requeuePhase, requeueConditionReason, fmt.Sprintf("APIServices not installed"), now)
csv.SetPhaseWithEvent(requeuePhase, requeueConditionReason, fmt.Sprintf("APIServices not installed"), now, a.recorder)
err := a.csvQueueSet.Requeue(csv.GetName(), csv.GetNamespace())
if err != nil {
a.Log.Warn(err.Error())
Expand All @@ -1147,7 +1143,7 @@ func (a *Operator) updateInstallStatus(csv *v1alpha1.ClusterServiceVersion, inst
}

if strategyErr != nil {
csv.SetPhase(requeuePhase, requeueConditionReason, fmt.Sprintf("installing: %s", strategyErr), now)
csv.SetPhaseWithEvent(requeuePhase, requeueConditionReason, fmt.Sprintf("installing: %s", strategyErr), now, a.recorder)
return strategyErr
}

Expand All @@ -1158,7 +1154,7 @@ func (a *Operator) updateInstallStatus(csv *v1alpha1.ClusterServiceVersion, inst
func (a *Operator) parseStrategiesAndUpdateStatus(csv *v1alpha1.ClusterServiceVersion) (install.StrategyInstaller, install.Strategy, install.Strategy) {
strategy, err := a.resolver.UnmarshalStrategy(csv.Spec.InstallStrategy)
if err != nil {
csv.SetPhase(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonInvalidStrategy, fmt.Sprintf("install strategy invalid: %s", err), timeNow())
csv.SetPhaseWithEvent(v1alpha1.CSVPhaseFailed, v1alpha1.CSVReasonInvalidStrategy, fmt.Sprintf("install strategy invalid: %s", err), timeNow(), a.recorder)
return nil, nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/csv_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1508,9 +1508,9 @@ func TestUpdateCSVWithOwnedAPIService(t *testing.T) {
require.NoError(t, err)
defer cleanupCSV()

fetched, err := fetchCSV(t, crc, csv.Name, testNamespace, csvFailedChecker)
fetched, err := fetchCSV(t, crc, csv.Name, testNamespace, buildCSVReasonChecker(v1alpha1.CSVReasonOwnerConflict))
require.NoError(t, err)
require.Equal(t, fetched.Status.Reason, v1alpha1.CSVReasonOwnerConflict)
require.Equal(t, string(v1alpha1.CSVPhaseFailed), string(fetched.Status.Phase))
}

func TestCreateSameCSVWithOwnedAPIServiceMultiNamespace(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions vendor/github.com/json-iterator/go/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/github.com/json-iterator/go/any.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 6 additions & 14 deletions vendor/github.com/json-iterator/go/iter_float.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions vendor/github.com/json-iterator/go/iter_skip_strict.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions vendor/github.com/json-iterator/go/reflect_map.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions vendor/github.com/json-iterator/go/reflect_marshaler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ github.com/hashicorp/golang-lru/simplelru
github.com/imdario/mergo
# github.com/inconshreveable/mousetrap v1.0.0
github.com/inconshreveable/mousetrap
# github.com/json-iterator/go v1.1.5
# github.com/json-iterator/go v1.1.6
github.com/json-iterator/go
# github.com/konsorten/go-windows-terminal-sequences v1.0.1
github.com/konsorten/go-windows-terminal-sequences
Expand Down Expand Up @@ -674,7 +674,7 @@ k8s.io/kube-openapi/pkg/generators/rules
k8s.io/kube-openapi/pkg/builder
k8s.io/kube-openapi/pkg/handler
k8s.io/kube-openapi/pkg/util/sets
# k8s.io/kubernetes v1.11.9-beta.0.0.20190305054513-b2539d50ae56
# k8s.io/kubernetes v1.11.9-beta.0.0.20190311041124-ede55fd57298
k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac
k8s.io/kubernetes/pkg/util/labels
k8s.io/kubernetes/pkg/apis/rbac/v1
Expand Down

0 comments on commit 840d806

Please sign in to comment.