2023-05-05 16:43:21 +00:00
|
|
|
/*
|
|
|
|
Copyright © 2022 SUSE LLC
|
|
|
|
|
|
|
|
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 action
|
|
|
|
|
|
|
|
import (
|
2023-07-25 13:21:34 +00:00
|
|
|
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
|
2023-07-10 12:39:48 +00:00
|
|
|
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
|
2023-05-05 16:43:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Hook is RunStage wrapper that only adds logic to ignore errors
|
2023-07-25 09:08:27 +00:00
|
|
|
// in case v1.Config.Strict is set to false
|
2023-07-25 13:21:34 +00:00
|
|
|
func Hook(config *config.Config, hook string) error {
|
2023-05-05 16:43:21 +00:00
|
|
|
config.Logger.Infof("Running %s hook", hook)
|
2023-07-25 09:08:27 +00:00
|
|
|
err := utils.RunStage(config, hook)
|
|
|
|
if !config.Strict {
|
2023-05-05 16:43:21 +00:00
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ChrootHook executes Hook inside a chroot environment
|
2023-07-25 13:21:34 +00:00
|
|
|
func ChrootHook(config *config.Config, hook string, chrootDir string, bindMounts map[string]string) (err error) {
|
2023-05-05 16:43:21 +00:00
|
|
|
callback := func() error {
|
2023-07-25 09:08:27 +00:00
|
|
|
return Hook(config, hook)
|
2023-05-05 16:43:21 +00:00
|
|
|
}
|
|
|
|
return utils.ChrootedCallback(config, chrootDir, bindMounts, callback)
|
|
|
|
}
|