Skip to content

Commit

Permalink
Initial init changes for dynamic config.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Nov 22, 2023
1 parent 6e0853d commit c0ae7ad
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cmd/update-conf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2023 The aerospike-operator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
goctx "context"

"github.com/spf13/cobra"

"github.com/aerospike/aerospike-kubernetes-init/pkg"
)

// confUpdate represents the update-conf command
var confUpdate = &cobra.Command{
Use: "update-conf",
Short: "update conf init functionality",
Long: `This command updates conf file of aerospike server and updating CR status.`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := goctx.TODO()

initParams, err := pkg.PopulateInitParams(ctx)
if err != nil {
return err
}
return initParams.UpdateConf(ctx, cmName, cmNamespace)
},
}

func init() {
rootCmd.AddCommand(confUpdate)
confUpdate.Flags().StringVar(&cmName, "cm-name", "", "configmap name")
confUpdate.Flags().StringVar(&cmNamespace, "cm-namespace", "", "configmap namespace")
}
26 changes: 26 additions & 0 deletions pkg/refresh-cmap-restart-asd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,29 @@ func (initp *InitParams) QuickRestart(ctx goctx.Context, cmName, cmNamespace str
// Update pod status in the k8s aerospike cluster object
return initp.manageVolumesAndUpdateStatus(ctx, "quickRestart")
}

func (initp *InitParams) UpdateConf(ctx goctx.Context, cmName, cmNamespace string) error {
if cmNamespace == "" {
return fmt.Errorf("kubernetes namespace required as an argument")
}

if cmName == "" {
return fmt.Errorf("aerospike configmap required as an argument")
}

if err := initp.ExportK8sConfigmap(ctx, cmNamespace, cmName, configMapDir); err != nil {
return err
}

// Create new Aerospike configuration
if err := initp.copyTemplates(configMapDir, configVolume); err != nil {
return err
}

if err := initp.createAerospikeConf(); err != nil {
return err
}

// Update pod status in the k8s aerospike cluster object
return initp.manageVolumesAndUpdateStatus(ctx, "noRestart")
}

0 comments on commit c0ae7ad

Please sign in to comment.