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

issue-464:Added support for JvmOption customization #462

Merged
merged 9 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
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
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