-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
render: generate cloud config when infrastructure and configmap are p…
…rovided
- Loading branch information
Showing
3 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package kube_cloud_config | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/yaml" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
operatorclient "github.com/openshift/cluster-config-operator/pkg/operator/operatorclient" | ||
) | ||
|
||
// ValidateFile verifies a file exists, has content, and is a regular file | ||
func ValidateFile(path string) error { | ||
st, err := os.Stat(path) | ||
if err != nil { | ||
return err | ||
} | ||
if !st.Mode().IsRegular() { | ||
return fmt.Errorf("%s is not a regular file.", path) | ||
} | ||
if st.Size() <= 0 { | ||
return fmt.Errorf("%s is empty.", path) | ||
} | ||
return nil | ||
} | ||
|
||
func BootstrapTransformer(infrastructureFile string, cloudProviderFile string) ([]byte, error) { | ||
|
||
// Read, parse, and save the infrastructure object | ||
var clusterInfrastructure configv1.Infrastructure | ||
fileData, err := ioutil.ReadFile(infrastructureFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = yaml.Unmarshal(fileData, &clusterInfrastructure) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Read, parse, and save the user provided cloud configmap | ||
var cloudProviderConfigInput corev1.ConfigMap | ||
if len(cloudProviderFile) > 0 { | ||
fileData, err = ioutil.ReadFile(cloudProviderFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = yaml.Unmarshal(fileData, &cloudProviderConfigInput) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
// Determine the platform type | ||
var platformName configv1.PlatformType | ||
if pstatus := clusterInfrastructure.Status.PlatformStatus; pstatus != nil { | ||
platformName = pstatus.Type | ||
} | ||
if len(platformName) == 0 { | ||
platformName = clusterInfrastructure.Status.Platform | ||
} | ||
|
||
// Determine the platform specific transformer method to use | ||
cloudConfigTransformers := cloudConfigTransformers() | ||
cloudConfigTransformerFn, ok := cloudConfigTransformers[platformName] | ||
if !ok { | ||
cloudConfigTransformerFn = asIsTransformer | ||
} | ||
target, err := cloudConfigTransformerFn(&cloudProviderConfigInput, clusterInfrastructure.Spec.CloudConfig.Key, &clusterInfrastructure) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
target.Name = targetConfigName | ||
target.Namespace = operatorclient.GlobalMachineSpecifiedConfigNamespace | ||
/* ApplyConfigMap() */ | ||
|
||
targetCloudConfigMapData, err := yaml.Marshal(target) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return targetCloudConfigMapData, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters