Skip to content

Commit

Permalink
Emit event and log warning if service is Cache. Fixes #2042
Browse files Browse the repository at this point in the history
  • Loading branch information
rigazilla authored and ryanemerson committed Apr 11, 2024
1 parent 8c788ae commit 8f01dc2
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 1 deletion.
10 changes: 10 additions & 0 deletions api/v1/infinispan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ type InfinispanStatus struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Operand Status"
Operand OperandStatus `json:"operand,omitempty"`
// The Operator status
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Operator Status"
Operator Operator `json:"operator,omitempty"`
}

type OperandPhase string
Expand Down Expand Up @@ -631,6 +635,12 @@ const (
HotRodRollingStageCleanup HotRodRollingUpgradeStage = "HotRodRollingStageCleanup"
)

type Operator struct {
// The name of the pod reconciling this resource
// +optional
Pod string `json:"pod,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +operator-sdk:csv:customresourcedefinitions:displayName="Infinispan Cluster"
Expand Down
7 changes: 7 additions & 0 deletions api/v1/infinispan_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ func (i *Infinispan) ValidateUpdate(oldRuntimeObj runtime.Object) error {
if old.Spec.Jmx != nil && old.Spec.Jmx.Enabled != i.Spec.Jmx.Enabled {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("jmx"), "JMX configuration is immutable and cannot be updated after initial Infinispan creation"))
}

if old.IsDataGrid() && i.IsCache() {
errMsg := "ServiceType Cache configured is deprecated and will be removed in future releases. ServiceType DataGrid is recomended."
eventRec.Event(i, corev1.EventTypeWarning, "DeprecatedCacheService", errMsg)
log.Info(errMsg, "Request.Namespace", i.Namespace, "Request.Name", i.Name)
}

return errorListToError(i, allErrs)
}

Expand Down
16 changes: 16 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions config/crd/bases/infinispan.org_infinispans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,13 @@ spec:
description: The Operand version to be reconciled
type: string
type: object
operator:
description: The Operator status
properties:
pod:
description: The name of the pod reconciling this resource
type: string
type: object
podStatus:
description: The Pod's currently in the cluster
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ spec:
- description: The Operand status
displayName: Operand Status
path: operand
- description: The Operator status
displayName: Operator Status
path: operator
- description: The Pod's currently in the cluster
displayName: Pod Status
path: podStatus
Expand Down
6 changes: 5 additions & 1 deletion pkg/kubernetes/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func GetPod(ctx context.Context, client crclient.Client, ns string) (*corev1.Pod
if isRunModeLocal() {
return nil, ErrRunLocal
}
podName := os.Getenv(PodNameEnvVar)
podName := GetOperatorPodName()
if podName == "" {
return nil, fmt.Errorf("required env %s not set, please configure downward API", PodNameEnvVar)
}
Expand All @@ -132,6 +132,10 @@ func GetPod(ctx context.Context, client crclient.Client, ns string) (*corev1.Pod
return pod, nil
}

func GetOperatorPodName() string {
return os.Getenv(PodNameEnvVar)
}

func isRunModeLocal() bool {
return os.Getenv(ForceRunModeEnv) == string(LocalRunMode)
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/reconcile/pipeline/infinispan/handler/manage/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ func PreliminaryChecks(i *ispnv1.Infinispan, ctx pipeline.Context) {
}
}

func OperatorStatusChecks(i *ispnv1.Infinispan, ctx pipeline.Context) {
operatorPod := kube.GetOperatorPodName()
// Pod name is changed, means operator restarted
if i.Status.Operator.Pod != operatorPod {
if i.IsCache() {
errMsg := "ServiceType Cache configured is deprecated and will be removed in future releases. ServiceType DataGrid is recomended."
ctx.EventRecorder().Event(i, corev1.EventTypeWarning, "DeprecatedCacheService", errMsg)
ctx.Log().Info(errMsg)
}
ctx.Requeue(
ctx.UpdateInfinispan(func() {
i.Status.Operator.Pod = operatorPod
}),
)
}

}

func PodStatus(i *ispnv1.Infinispan, ctx pipeline.Context) {
ss := &appsv1.StatefulSet{}
if err := ctx.Resources().Load(i.GetStatefulSetName(), ss, pipeline.RetryOnErr); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/reconcile/pipeline/infinispan/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ func (b *builder) Build() pipeline.Pipeline {
handlers: make([]pipeline.HandlerFunc, 0),
}

// Do operator status checks
handlers.Add(manage.OperatorStatusChecks)
// Apply default meta before doing anything else
handlers.Add(manage.InitialiseOperandVersion)
handlers.Add(manage.PreliminaryChecks)
Expand Down

0 comments on commit 8f01dc2

Please sign in to comment.