Skip to content

Commit

Permalink
issue-464:Added support for JvmOption customization (#462)
Browse files Browse the repository at this point in the history
* added support for jvmOption customization

Signed-off-by: prabhaker24 <[email protected]>

* removed sleep

Signed-off-by: prabhaker24 <[email protected]>

* added timeout and made restart pod function modular as well

Signed-off-by: prabhaker24 <[email protected]>

* changed restart logic for controller pods

Signed-off-by: prabhaker24 <[email protected]>

* added reconcileconfigmap and validation

Signed-off-by: prabhaker24 <[email protected]>

* ut for compareConfigMap added

Signed-off-by: prabhaker24 <[email protected]>

* adding e2e for cm changes added

Signed-off-by: prabhaker24 <[email protected]>

* more validation added

Signed-off-by: prabhaker24 <[email protected]>

* fixed typo

Signed-off-by: prabhaker24 <[email protected]>

Co-authored-by: prabhaker24 <[email protected]>
  • Loading branch information
Prabhaker24 and prabhaker24 authored Oct 20, 2020
1 parent 569dfb3 commit 1c5f0ce
Show file tree
Hide file tree
Showing 10 changed files with 771 additions and 24 deletions.
156 changes: 148 additions & 8 deletions pkg/apis/pravega/v1beta1/pravegacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,13 +883,21 @@ func (p *PravegaCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (p *PravegaCluster) ValidateCreate() error {
log.Printf("validate create %s", p.Name)
return p.validatePravegaVersion()
return p.ValidatePravegaVersion("")
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (p *PravegaCluster) ValidateUpdate(old runtime.Object) error {
log.Printf("validate update %s", p.Name)
return p.validatePravegaVersion()
err := p.ValidatePravegaVersion("")
if err != nil {
return err
}
err = p.validateConfigMap()
if err != nil {
return err
}
return nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
Expand All @@ -899,9 +907,14 @@ func (p *PravegaCluster) ValidateDelete() error {
return nil
}

func getSupportedVersions() (map[string]string, error) {
func getSupportedVersions(filename string) (map[string]string, error) {
var supportedVersions = map[string]string{}
file, err := os.Open("/tmp/config/keys")
filepath := filename
if filename == "" {
filepath = "/tmp/config/keys"
}

file, err := os.Open(filepath)

if err != nil {
log.Fatalf("failed opening file: %v", err)
Expand All @@ -924,8 +937,8 @@ func getSupportedVersions() (map[string]string, error) {
return supportedVersions, nil
}

func (p *PravegaCluster) validatePravegaVersion() error {
supportedVersions, err := getSupportedVersions()
func (p *PravegaCluster) ValidatePravegaVersion(filename string) error {
supportedVersions, err := getSupportedVersions(filename)
if err != nil {
return fmt.Errorf("Error retrieving suported versions %v", err)
}
Expand Down Expand Up @@ -981,7 +994,7 @@ func (p *PravegaCluster) validatePravegaVersion() error {
return fmt.Errorf("found version is not in valid format, something bad happens: %v", err)
}

log.Printf("validatePravegaVersion:: normFoundVersion %s", normFoundVersion)
log.Printf("ValidatePravegaVersion:: normFoundVersion %s", normFoundVersion)
upgradeString, ok := supportedVersions[normFoundVersion]
if !ok {
// It should never happen
Expand All @@ -991,7 +1004,134 @@ func (p *PravegaCluster) validatePravegaVersion() error {
if !util.ContainsVersion(upgradeList, normRequestVersion) {
return fmt.Errorf("unsupported upgrade from version %s to %s", p.Status.CurrentVersion, requestVersion)
}
log.Print("validatePravegaVersion:: No error found...returning...")
log.Print("ValidatePravegaVersion:: No error found...returning...")
return nil
}

func (p *PravegaCluster) validateConfigMap() error {
configmap := &corev1.ConfigMap{}
err := Mgr.GetClient().Get(context.TODO(),
types.NamespacedName{Name: p.ConfigMapNameForController(), Namespace: p.Namespace}, configmap)
if err != nil {
if errors.IsNotFound(err) {
return nil
} else {
return fmt.Errorf("failed to get configmap (%s): %v", configmap.Name, err)
}
}
if val, ok := p.Spec.Pravega.Options["controller.containerCount"]; ok {
checkstring := fmt.Sprintf("-Dcontroller.containerCount=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("controller.containerCount should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["controller.container.count"]; ok {
checkstring := fmt.Sprintf("-Dcontroller.container.count=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("controller.container.count should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["pravegaservice.containerCount"]; ok {
checkstring := fmt.Sprintf("-Dpravegaservice.containerCount=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("pravegaservice.containerCount should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["pravegaservice.container.count"]; ok {
checkstring := fmt.Sprintf("-Dpravegaservice.container.count=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("pravegaservice.container.count should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["bookkeeper.bkLedgerPath"]; ok {
checkstring := fmt.Sprintf("-Dbookkeeper.bkLedgerPath=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("bookkeeper.bkLedgerPath should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["bookkeeper.ledger.path"]; ok {
checkstring := fmt.Sprintf("-Dbookkeeper.ledger.path=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("bookkeeper.ledger.path should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["controller.retention.bucketCount"]; ok {
checkstring := fmt.Sprintf("-Dcontroller.retention.bucketCount=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("controller.retention.bucketCount should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["controller.retention.bucket.count"]; ok {
checkstring := fmt.Sprintf("-Dcontroller.retention.bucket.count=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("controller.retention.bucket.count should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["controller.watermarking.bucketCount"]; ok {
checkstring := fmt.Sprintf("-Dcontroller.watermarking.bucketCount=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("controller.watermarking.bucketCount should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["controller.watermarking.bucket.count"]; ok {
checkstring := fmt.Sprintf("-Dcontroller.watermarking.bucket.count=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("controller.watermarking.bucket.count should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["pravegaservice.dataLogImplementation"]; ok {
checkstring := fmt.Sprintf("-Dpravegaservice.dataLogImplementation=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("pravegaservice.dataLogImplementation should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["pravegaservice.dataLog.impl.name"]; ok {
checkstring := fmt.Sprintf("-Dpravegaservice.dataLog.impl.name=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("pravegaservice.dataLog.impl.name should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["pravegaservice.storageImplementation"]; ok {
checkstring := fmt.Sprintf("-Dpravegaservice.storageImplementation=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("pravegaservice.storageImplementation should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["pravegaservice.storage.impl.name"]; ok {
checkstring := fmt.Sprintf("-Dpravegaservice.storage.impl.name=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("pravegaservice.storage.impl.name should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["storageextra.storageNoOpMode"]; ok {
checkstring := fmt.Sprintf("-Dstorageextra.storageNoOpMode=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("storageextra.storageNoOpMode should not be changed ")
}
}
if val, ok := p.Spec.Pravega.Options["storageextra.noOp.mode.enable"]; ok {
checkstring := fmt.Sprintf("-Dstorageextra.noOp.mode.enable=%v", val)
eq := strings.Contains(configmap.Data["JAVA_OPTS"], checkstring)
if !eq {
return fmt.Errorf("storageextra.noOp.mode.enable should not be changed ")
}
}
log.Print("validateConfigMap:: No error found...returning...")
return nil
}

Expand Down
Loading

0 comments on commit 1c5f0ce

Please sign in to comment.