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

Add two feature gates : Image based deployment and additional runtimeClasses #394

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions controllers/credentials_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/go-logr/logr"
v1 "github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential/v1"
Expand Down Expand Up @@ -293,7 +294,8 @@ func (kh *KataConfigHandler) getCredentialsRequest() (*v1.CredentialsRequest, er
}

fileName := fmt.Sprintf(peerpodsCredentialsRequestFileFormat, provider)
yamlData, err := readCredentialsRequestYAML(fileName)
credentialsRequestsYamlFile := filepath.Join(peerpodsCredentialsRequestsPathLocation, fileName)
yamlData, err := readYamlFile(credentialsRequestsYamlFile)
if os.IsNotExist(err) {
kh.reconciler.Log.Info("no CredentialsRequestYAML for provider", "err", err, "provider", provider)
return nil, nil
Expand Down Expand Up @@ -324,7 +326,8 @@ func (kh *KataConfigHandler) skipCredentialRequests() bool {
// check if CredentialsRequest implementation exists for the cloud provider
if provider, err := getCloudProviderFromInfra(kh.reconciler.Client); err == nil {
fileName := fmt.Sprintf(peerpodsCredentialsRequestFileFormat, provider)
if _, err := readCredentialsRequestYAML(fileName); os.IsNotExist(err) {
credentialsRequestsYamlFile := filepath.Join(peerpodsCredentialsRequestsPathLocation, fileName)
if _, err := readYamlFile(credentialsRequestsYamlFile); os.IsNotExist(err) {
kh.reconciler.Log.Info("no CredentialsRequest yaml file for provider, skipping", "provider", provider, "filename", fileName)
return true
}
Expand Down
8 changes: 6 additions & 2 deletions controllers/image_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -242,7 +243,9 @@ func newImageGenerator(client client.Client) (*ImageGenerator, error) {
func (r *ImageGenerator) createJobFromFile(jobFileName string) (*batchv1.Job, error) {
igLogger.Info("Create Job out of YAML file", "jobFileName", jobFileName)

yamlData, err := readJobYAML(jobFileName)
jobYamlFile := filepath.Join(peerpodsImageJobsPathLocation, jobFileName)

yamlData, err := readYamlFile(jobYamlFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm confused but I don't see how this is related to feature gating. (?)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -630,7 +633,8 @@ func (r *ImageGenerator) createImageConfigMapFromFile() error {
}

filename := r.provider + "-podvm-image-cm.yaml"
yamlData, err := readConfigMapYAML(filename)
configMapYamlFile := filepath.Join(peerpodsImageJobsPathLocation, filename)
yamlData, err := readYamlFile(configMapYamlFile)
if err != nil {
return err
}
Expand Down
17 changes: 11 additions & 6 deletions controllers/openshift_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"reflect"
"time"

Expand Down Expand Up @@ -2081,14 +2082,16 @@ func (r *KataConfigOpenShiftReconciler) createAuthJsonSecret() error {
func (r *KataConfigOpenShiftReconciler) enablePeerPodsMc() error {

//Create MachineConfig for kata-remote hyp CRIO config
err := r.createMcFromFile(peerpodsCrioMachineConfigYaml)
crioMachineConfigFilePath := filepath.Join(peerpodsMachineConfigPathLocation, peerpodsCrioMachineConfigYaml)
err := r.createMcFromFile(crioMachineConfigFilePath)
if err != nil {
r.Log.Info("Error in creating CRIO MachineConfig", "err", err)
return err
}

//Create MachineConfig for kata-remote hyp config toml
err = r.createMcFromFile(peerpodsKataRemoteMachineConfigYaml)
kataConfigMachineConfigFilePath := filepath.Join(peerpodsMachineConfigPathLocation, peerpodsKataRemoteMachineConfigYaml)
err = r.createMcFromFile(kataConfigMachineConfigFilePath)
if err != nil {
r.Log.Info("Error in creating kata remote configuration.toml MachineConfig", "err", err)
return err
Expand Down Expand Up @@ -2235,18 +2238,20 @@ func (r *KataConfigOpenShiftReconciler) disablePeerPods() error {
return nil
}

func (r *KataConfigOpenShiftReconciler) createMcFromFile(mcFileName string) error {
yamlData, err := readMachineConfigYAML(mcFileName)
// Create the MachineConfigs from file
// Full path of the file should be provided
func (r *KataConfigOpenShiftReconciler) createMcFromFile(machineConfigYamlFile string) error {
yamlData, err := readYamlFile(machineConfigYamlFile)
if err != nil {
r.Log.Info("Error in reading MachineConfigYaml", "mcFileName", mcFileName, "err", err)
r.Log.Info("Error in reading MachineConfigYaml", "mcFile", machineConfigYamlFile, "err", err)
return err
}

r.Log.Info("machineConfig yaml dump ", "yamlData", yamlData)

machineConfig, err := parseMachineConfigYAML(yamlData)
if err != nil {
r.Log.Info("Error in parsing MachineConfigYaml", "mcFileName", mcFileName, "err", err)
r.Log.Info("Error in parsing MachineConfigYaml", "mcFile", machineConfigYamlFile, "err", err)
return err
}

Expand Down
38 changes: 5 additions & 33 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -73,9 +72,11 @@ func parseJobYAML(yamlData []byte) (*batchv1.Job, error) {
return job, nil
}

func readJobYAML(jobFileName string) ([]byte, error) {
jobFilePath := filepath.Join(peerpodsImageJobsPathLocation, jobFileName)
yamlData, err := os.ReadFile(jobFilePath)
// Method to read yaml file.
// The full path of the job yaml file is passed as an argument
// Returns the yaml data and an error
func readYamlFile(yamlFile string) ([]byte, error) {
yamlData, err := os.ReadFile(yamlFile)
if err != nil {
return nil, err
}
Expand All @@ -91,15 +92,6 @@ func parseMachineConfigYAML(yamlData []byte) (*mcfgv1.MachineConfig, error) {
return machineConfig, nil
}

func readMachineConfigYAML(mcFileName string) ([]byte, error) {
machineConfigFilePath := filepath.Join(peerpodsMachineConfigPathLocation, mcFileName)
yamlData, err := os.ReadFile(machineConfigFilePath)
if err != nil {
return nil, err
}
return yamlData, nil
}

func parseCredentialsRequestYAML(yamlData []byte) (*ccov1.CredentialsRequest, error) {
credentialsRequest := &ccov1.CredentialsRequest{}
err := yaml.Unmarshal(yamlData, credentialsRequest)
Expand All @@ -109,26 +101,6 @@ func parseCredentialsRequestYAML(yamlData []byte) (*ccov1.CredentialsRequest, er
return credentialsRequest, nil
}

func readCredentialsRequestYAML(crFileName string) ([]byte, error) {
credentialsRequestsFilePath := filepath.Join(peerpodsCredentialsRequestsPathLocation, crFileName)
yamlData, err := os.ReadFile(credentialsRequestsFilePath)
if err != nil {
return nil, err
}
return yamlData, nil
}

// Method to read config map yaml

func readConfigMapYAML(cmFileName string) ([]byte, error) {
configMapFilePath := filepath.Join(peerpodsImageJobsPathLocation, cmFileName)
yamlData, err := os.ReadFile(configMapFilePath)
if err != nil {
return nil, err
}
return yamlData, nil
}

// Method to parse config map yaml
// Returns a pointer to a ConfigMap object and an error

Expand Down