Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update installplan status conflict #2838

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -1396,13 +1398,22 @@
return nil, err
}

res.Status = v1alpha1.InstallPlanStatus{
modifiedIP := res.DeepCopy()
modifiedIP.Status = v1alpha1.InstallPlanStatus{
Phase: phase,
Plan: steps,
CatalogSources: catalogSources,
BundleLookups: bundleLookups,
}
res, err = o.client.OperatorsV1alpha1().InstallPlans(namespace).UpdateStatus(context.TODO(), res, metav1.UpdateOptions{})

patchData, err := createInstallPlanPatchData(res, modifiedIP)
if err != nil {
return nil, err
}

res, err = o.client.OperatorsV1alpha1().InstallPlans(namespace).Patch(
context.TODO(), res.Name, types.MergePatchType, patchData, metav1.PatchOptions{}, "status",
)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2538,3 +2549,45 @@
logger.Info("couldn't find GVK in api discovery")
return metav1.APIResource{}, olmerrors.GroupVersionKindNotFoundError{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind}
}

const (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't seem to be used anywhere. Needed?

PrometheusRuleKind = "PrometheusRule"

Check failure on line 2554 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-minikube

other declaration of PrometheusRuleKind

Check failure on line 2554 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-kind

other declaration of PrometheusRuleKind

Check failure on line 2554 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (2)

other declaration of PrometheusRuleKind

Check failure on line 2554 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / flaky-e2e-tests

other declaration of PrometheusRuleKind

Check failure on line 2554 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (0)

other declaration of PrometheusRuleKind

Check failure on line 2554 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (3)

other declaration of PrometheusRuleKind

Check failure on line 2554 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (1)

other declaration of PrometheusRuleKind

Check failure on line 2554 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / unit

other declaration of PrometheusRuleKind
ServiceMonitorKind = "ServiceMonitor"

Check failure on line 2555 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-minikube

other declaration of ServiceMonitorKind

Check failure on line 2555 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-kind

other declaration of ServiceMonitorKind

Check failure on line 2555 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (2)

other declaration of ServiceMonitorKind

Check failure on line 2555 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / flaky-e2e-tests

other declaration of ServiceMonitorKind

Check failure on line 2555 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (0)

other declaration of ServiceMonitorKind

Check failure on line 2555 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (3)

other declaration of ServiceMonitorKind

Check failure on line 2555 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (1)

other declaration of ServiceMonitorKind

Check failure on line 2555 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / unit

other declaration of ServiceMonitorKind
PodDisruptionBudgetKind = "PodDisruptionBudget"

Check failure on line 2556 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-minikube

other declaration of PodDisruptionBudgetKind

Check failure on line 2556 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-kind

other declaration of PodDisruptionBudgetKind

Check failure on line 2556 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (2)

other declaration of PodDisruptionBudgetKind

Check failure on line 2556 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / flaky-e2e-tests

other declaration of PodDisruptionBudgetKind

Check failure on line 2556 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (0)

other declaration of PodDisruptionBudgetKind

Check failure on line 2556 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (3)

other declaration of PodDisruptionBudgetKind

Check failure on line 2556 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (1)

other declaration of PodDisruptionBudgetKind

Check failure on line 2556 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / unit

other declaration of PodDisruptionBudgetKind
PriorityClassKind = "PriorityClass"

Check failure on line 2557 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-minikube

other declaration of PriorityClassKind

Check failure on line 2557 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-kind

other declaration of PriorityClassKind

Check failure on line 2557 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (2)

other declaration of PriorityClassKind

Check failure on line 2557 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / flaky-e2e-tests

other declaration of PriorityClassKind

Check failure on line 2557 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (0)

other declaration of PriorityClassKind

Check failure on line 2557 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (3)

other declaration of PriorityClassKind

Check failure on line 2557 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (1)

other declaration of PriorityClassKind

Check failure on line 2557 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / unit

other declaration of PriorityClassKind
VerticalPodAutoscalerKind = "VerticalPodAutoscaler"

Check failure on line 2558 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-minikube

other declaration of VerticalPodAutoscalerKind

Check failure on line 2558 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e-kind

other declaration of VerticalPodAutoscalerKind

Check failure on line 2558 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (2)

other declaration of VerticalPodAutoscalerKind

Check failure on line 2558 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / flaky-e2e-tests

other declaration of VerticalPodAutoscalerKind

Check failure on line 2558 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (0)

other declaration of VerticalPodAutoscalerKind

Check failure on line 2558 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (3)

other declaration of VerticalPodAutoscalerKind

Check failure on line 2558 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / e2e (1)

other declaration of VerticalPodAutoscalerKind

Check failure on line 2558 in pkg/controller/operators/catalog/operator.go

View workflow job for this annotation

GitHub Actions / unit

other declaration of VerticalPodAutoscalerKind
ConsoleYAMLSampleKind = "ConsoleYAMLSample"
ConsoleQuickStartKind = "ConsoleQuickStart"
ConsoleCLIDownloadKind = "ConsoleCLIDownload"
ConsoleLinkKind = "ConsoleLink"
)

var supportedKinds = map[string]struct{}{
PrometheusRuleKind: {},
ServiceMonitorKind: {},
PodDisruptionBudgetKind: {},
PriorityClassKind: {},
VerticalPodAutoscalerKind: {},
ConsoleYAMLSampleKind: {},
ConsoleQuickStartKind: {},
ConsoleCLIDownloadKind: {},
ConsoleLinkKind: {},
}

// isSupported returns true if OLM supports this type of CustomResource.
func isSupported(kind string) bool {
_, ok := supportedKinds[kind]
return ok
}

func createInstallPlanPatchData(original, modified runtime.Object) ([]byte, error) {
originalData, err := json.Marshal(original)
if err != nil {
return nil, err
}
modifiedData, err := json.Marshal(modified)
if err != nil {
return nil, err
}
return strategicpatch.CreateTwoWayMergePatch(originalData, modifiedData, original)
}
Loading