diff --git a/cmd/update-conf.go b/cmd/update-conf.go new file mode 100644 index 0000000..2a6774d --- /dev/null +++ b/cmd/update-conf.go @@ -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") +} diff --git a/pkg/refresh-cmap-restart-asd.go b/pkg/refresh-cmap-restart-asd.go index a645596..a153d58 100644 --- a/pkg/refresh-cmap-restart-asd.go +++ b/pkg/refresh-cmap-restart-asd.go @@ -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") +}