Skip to content

Commit

Permalink
Cryostat Integration. Resolves infinispan#1831
Browse files Browse the repository at this point in the history
Co-authored-by: Dominika Vagnerova <[email protected]>
  • Loading branch information
ryanemerson and domiborges committed Jul 17, 2023
1 parent 7e06dc8 commit 8559b6e
Show file tree
Hide file tree
Showing 39 changed files with 5,694 additions and 25 deletions.
9 changes: 9 additions & 0 deletions api/v1/infinispan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ type ConfigListenerLoggingSpec struct {
Level ConfigListenerLogLevel `json:"level"`
}

type CryostatSpec struct {
// If true, a JMX endpoint is exposed on the admin service and a Cryostat CR is created to allow JFR recordings to be created via the UI
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Toggle Cryostat",xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
Enabled bool `json:"enabled,omitempty"`
}

// InfinispanSpec defines the desired state of Infinispan
type InfinispanSpec struct {
// The number of nodes in the Infinispan cluster.
Expand Down Expand Up @@ -437,6 +444,8 @@ type InfinispanSpec struct {
Upgrades *InfinispanUpgradesSpec `json:"upgrades,omitempty"`
// +optional
ConfigListener *ConfigListenerSpec `json:"configListener,omitempty"`
// +optional
Cryostat *CryostatSpec `json:"cryostat,omitempty"`
}

// InfinispanUpgradesSpec defines the Infinispan upgrade strategy
Expand Down
8 changes: 8 additions & 0 deletions api/v1/infinispan_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (i *Infinispan) Default() {
i.Spec.Service.Sites.Local.Discovery.LaunchGossipRouter = pointer.Bool(true)
}
}

if i.Spec.Cryostat == nil {
i.Spec.Cryostat = &CryostatSpec{}
}
}

// +kubebuilder:webhook:path=/validate-infinispan-org-v1-infinispan,mutating=false,failurePolicy=fail,sideEffects=None,groups=infinispan.org,resources=infinispans,verbs=create;update,versions=v1,name=vinfinispan.kb.io,admissionReviewVersions={v1,v1beta1}
Expand Down Expand Up @@ -184,6 +188,10 @@ func (i *Infinispan) ValidateUpdate(oldRuntimeObj runtime.Object) error {
}
}
}

if old.Spec.Cryostat != nil && old.Spec.Cryostat.Enabled != i.Spec.Cryostat.Enabled {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("cryostat"), "Cryostat configuration is immutable and cannot be updated after initial Infinispan creation"))
}
return errorListToError(i, allErrs)
}

Expand Down
20 changes: 20 additions & 0 deletions api/v1/infinispan_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var _ = Describe("Infinispan Webhooks", func() {
Expect(spec.Upgrades.Type).Should(Equal(UpgradeTypeShutdown))
Expect(spec.ConfigListener.Enabled).Should(BeTrue())
Expect(spec.ConfigListener.Logging.Level).Should(Equal(ConfigListenerLoggingInfo))
Expect(spec.Cryostat.Enabled).Should(Equal(false))
})

It("Should initiate DataGrid defaults", func() {
Expand Down Expand Up @@ -109,6 +110,7 @@ var _ = Describe("Infinispan Webhooks", func() {
Expect(spec.Upgrades.Type).Should(Equal(UpgradeTypeShutdown))
Expect(spec.ConfigListener.Enabled).Should(BeTrue())
Expect(spec.ConfigListener.Logging.Level).Should(Equal(ConfigListenerLoggingInfo))
Expect(spec.Cryostat.Enabled).Should(Equal(false))
})

It("Should calculate default Labels", func() {
Expand Down Expand Up @@ -574,6 +576,24 @@ var _ = Describe("Infinispan Webhooks", func() {
metav1.CauseTypeFieldValueInvalid, "spec.version", "should match",
})
})

It("Should prevent immutable fields being updated", func() {
ispn := &Infinispan{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
},
Spec: InfinispanSpec{
Replicas: 1,
},
}
Expect(k8sClient.Create(ctx, ispn)).Should(Succeed())
Expect(k8sClient.Get(ctx, key, ispn)).Should(Succeed())
ispn.Spec.Cryostat.Enabled = true
expectInvalidErrStatus(k8sClient.Update(ctx, ispn),
statusDetailCause{"FieldValueForbidden", "spec.cryostat", "Cryostat configuration is immutable and cannot be updated after initial Infinispan creation"},
)
})
})
})

Expand Down
8 changes: 8 additions & 0 deletions api/v1/types_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,3 +941,11 @@ func (ispn *Infinispan) LaunchGossipRouterEnabled() bool {
func (ispn *Infinispan) IsGossipRouterEnabled() bool {
return ispn.CrossSiteDiscoveryType() == GossipRouterType && ispn.LaunchGossipRouterEnabled()
}

func (ispn *Infinispan) IsCryostatEnabled() bool {
return ispn.Spec.Cryostat != nil && ispn.Spec.Cryostat.Enabled
}

func (ispn *Infinispan) GetCryostatName() string {
return fmt.Sprintf("%s-cs", ispn.Name)
}
20 changes: 20 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.

8 changes: 8 additions & 0 deletions config/crd/bases/infinispan.org_infinispans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,14 @@ spec:
routerExtraJvmOpts:
type: string
type: object
cryostat:
properties:
enabled:
description: If true, a JMX endpoint is exposed on the admin service
and a Cryostat CR is created to allow JFR recordings to be created
via the UI
type: boolean
type: object
dependencies:
description: External dependencies needed by the Infinispan cluster
properties:
Expand Down
Loading

0 comments on commit 8559b6e

Please sign in to comment.