1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00

inject ClusterInfo into AgentPullSecret asset

This commit is contained in:
Andrea Fasano
2024-02-08 11:09:59 -05:00
parent 20c9b51344
commit db1306ba7a
16 changed files with 114 additions and 63 deletions

View File

@@ -257,6 +257,13 @@ func (a *OptionalInstallConfig) ClusterName() string {
return "agent-cluster"
}
func (a *OptionalInstallConfig) ClusterNamespace() string {
if a.Config != nil && a.Config.ObjectMeta.Namespace != "" {
return a.Config.ObjectMeta.Namespace
}
return ""
}
// GetBaremetalHosts gets the hosts defined for a baremetal platform.
func (a *OptionalInstallConfig) GetBaremetalHosts() []*baremetal.Host {
if a.Config != nil && a.Config.Platform.Name() == baremetal.Name {

View File

@@ -20,6 +20,7 @@ type ClusterInfo struct {
ClusterID string
APIDNSName string
PullSecret string
Namespace string
}
var _ asset.WritableAsset = (*ClusterInfo)(nil)
@@ -68,6 +69,8 @@ func (ci *ClusterInfo) Generate(dependencies asset.Parents) error {
return err
}
ci.Namespace = "cluster0"
return nil
}

View File

@@ -167,7 +167,7 @@ func (a *AgentClusterInstall) Generate(dependencies asset.Parents) error {
agentClusterInstall := &hiveext.AgentClusterInstall{
ObjectMeta: metav1.ObjectMeta{
Name: getAgentClusterInstallName(installConfig),
Namespace: getObjectMetaNamespace(installConfig),
Namespace: installConfig.ClusterNamespace(),
},
Spec: hiveext.AgentClusterInstallSpec{
ImageSetRef: &hivev1.ClusterImageSetReference{

View File

@@ -14,6 +14,8 @@ import (
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/agent"
"github.com/openshift/installer/pkg/asset/agent/joiner"
"github.com/openshift/installer/pkg/asset/agent/workflow"
"github.com/openshift/installer/pkg/validate"
)
@@ -41,36 +43,54 @@ func (*AgentPullSecret) Name() string {
// the asset.
func (*AgentPullSecret) Dependencies() []asset.Asset {
return []asset.Asset{
&workflow.AgentWorkflow{},
&joiner.ClusterInfo{},
&agent.OptionalInstallConfig{},
}
}
// Generate generates the AgentPullSecret manifest.
func (a *AgentPullSecret) Generate(dependencies asset.Parents) error {
agentWorkflow := &workflow.AgentWorkflow{}
installConfig := &agent.OptionalInstallConfig{}
dependencies.Get(installConfig)
clusterInfo := &joiner.ClusterInfo{}
dependencies.Get(agentWorkflow, installConfig, clusterInfo)
if installConfig.Config != nil {
secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Secret",
},
ObjectMeta: metav1.ObjectMeta{
Name: getPullSecretName(installConfig),
Namespace: getObjectMetaNamespace(installConfig),
},
StringData: map[string]string{
pullSecretKey: installConfig.Config.PullSecret,
},
switch agentWorkflow.Workflow {
case workflow.AgentWorkflowTypeInstall:
if installConfig.Config != nil {
a.generateSecret(installConfig.ClusterName(), installConfig.ClusterNamespace(), installConfig.Config.PullSecret)
}
a.Config = secret
case workflow.AgentWorkflowTypeAddNodes:
a.generateSecret(clusterInfo.ClusterID, clusterInfo.Namespace, clusterInfo.PullSecret)
default:
return fmt.Errorf("AgentWorkflowType value not supported: %s", agentWorkflow.Workflow)
}
return a.finish()
}
func (a *AgentPullSecret) generateSecret(name, namespace, pullSecret string) {
secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Secret",
},
ObjectMeta: metav1.ObjectMeta{
Name: getPullSecretName(name),
Namespace: namespace,
},
StringData: map[string]string{
pullSecretKey: pullSecret,
},
}
a.Config = secret
}
// Files returns the files generated by the asset.
func (a *AgentPullSecret) Files() []*asset.File {
if a.File != nil {

View File

@@ -13,11 +13,12 @@ import (
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/agent"
"github.com/openshift/installer/pkg/asset/agent/joiner"
"github.com/openshift/installer/pkg/asset/agent/workflow"
"github.com/openshift/installer/pkg/asset/mock"
)
func TestAgentPullSecret_Generate(t *testing.T) {
cases := []struct {
name string
dependencies []asset.Asset
@@ -25,16 +26,15 @@ func TestAgentPullSecret_Generate(t *testing.T) {
expectedConfig *corev1.Secret
}{
{
name: "missing install config",
name: "retrieved from cluster",
dependencies: []asset.Asset{
&agent.OptionalInstallConfig{},
},
expectedError: "missing configuration or manifest file",
},
{
name: "valid configuration",
dependencies: []asset.Asset{
getValidOptionalInstallConfig(),
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeAddNodes},
&joiner.ClusterInfo{
ClusterID: "ostest",
Namespace: "cluster0",
PullSecret: "{\n \"auths\": {\n \"cloud.openshift.com\": {\n \"auth\": \"b3BlUTA=\",\n \"email\": \"test@redhat.com\"\n }\n }\n}",
},
},
expectedConfig: &corev1.Secret{
TypeMeta: v1.TypeMeta{
@@ -42,8 +42,34 @@ func TestAgentPullSecret_Generate(t *testing.T) {
APIVersion: "v1",
},
ObjectMeta: v1.ObjectMeta{
Name: getPullSecretName(getValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Name: "ostest-pull-secret",
Namespace: "cluster0",
},
StringData: map[string]string{
".dockerconfigjson": "{\n \"auths\": {\n \"cloud.openshift.com\": {\n \"auth\": \"b3BlUTA=\",\n \"email\": \"test@redhat.com\"\n }\n }\n}",
},
},
},
{
name: "missing install config",
dependencies: []asset.Asset{
&agent.OptionalInstallConfig{}, &workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall}, &joiner.ClusterInfo{},
},
expectedError: "missing configuration or manifest file",
},
{
name: "valid configuration",
dependencies: []asset.Asset{
getValidOptionalInstallConfig(), &workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall}, &joiner.ClusterInfo{},
},
expectedConfig: &corev1.Secret{
TypeMeta: v1.TypeMeta{
Kind: "Secret",
APIVersion: "v1",
},
ObjectMeta: v1.ObjectMeta{
Name: getPullSecretName(getValidOptionalInstallConfig().ClusterName()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
},
StringData: map[string]string{
".dockerconfigjson": "{\n \"auths\": {\n \"cloud.openshift.com\": {\n \"auth\": \"b3BlUTA=\",\n \"email\": \"test@redhat.com\"\n }\n }\n}",

View File

@@ -53,13 +53,13 @@ func (cd *ClusterDeployment) Generate(dependencies asset.Parents) error {
},
ObjectMeta: metav1.ObjectMeta{
Name: getClusterDeploymentName(installConfig),
Namespace: getObjectMetaNamespace(installConfig),
Namespace: installConfig.ClusterNamespace(),
},
Spec: hivev1.ClusterDeploymentSpec{
ClusterName: getClusterDeploymentName(installConfig),
BaseDomain: installConfig.Config.BaseDomain,
PullSecretRef: &corev1.LocalObjectReference{
Name: getPullSecretName(installConfig),
Name: getPullSecretName(installConfig.ClusterName()),
},
ClusterInstallRef: &hivev1.ClusterInstallLocalReference{
Group: "extensions.hive.openshift.io",

View File

@@ -45,13 +45,13 @@ func TestClusterDeployment_Generate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: getClusterDeploymentName(getValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
},
Spec: hivev1.ClusterDeploymentSpec{
ClusterName: getClusterDeploymentName(getValidOptionalInstallConfig()),
BaseDomain: "testing.com",
PullSecretRef: &corev1.LocalObjectReference{
Name: getPullSecretName(getValidOptionalInstallConfig()),
Name: getPullSecretName(getValidOptionalInstallConfig().ClusterName()),
},
ClusterInstallRef: &hivev1.ClusterInstallLocalReference{
Group: "extensions.hive.openshift.io",

View File

@@ -65,7 +65,7 @@ func (a *ClusterImageSet) Generate(dependencies asset.Parents) error {
}
if installConfig.Config != nil {
clusterImageSet.ObjectMeta.Namespace = getObjectMetaNamespace(installConfig)
clusterImageSet.ObjectMeta.Namespace = installConfig.ClusterNamespace()
}

View File

@@ -64,7 +64,7 @@ func TestClusterImageSet_Generate(t *testing.T) {
expectedConfig: &hivev1.ClusterImageSet{
ObjectMeta: metav1.ObjectMeta{
Name: "openshift-was not built correctly",
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
},
Spec: hivev1.ClusterImageSetSpec{
ReleaseImage: currentRelease,

View File

@@ -18,8 +18,8 @@ func getInfraEnvName(ic *agent.OptionalInstallConfig) string {
return ic.ClusterName()
}
func getPullSecretName(ic *agent.OptionalInstallConfig) string {
return ic.ClusterName() + "-pull-secret"
func getPullSecretName(clusterName string) string {
return clusterName + "-pull-secret"
}
func getProxy(ic *agent.OptionalInstallConfig) *aiv1beta1.Proxy {
@@ -30,13 +30,6 @@ func getProxy(ic *agent.OptionalInstallConfig) *aiv1beta1.Proxy {
}
}
func getObjectMetaNamespace(ic *agent.OptionalInstallConfig) string {
if ic.Config != nil {
return ic.Config.Namespace
}
return ""
}
func getNMStateConfigName(ic *agent.OptionalInstallConfig) string {
return ic.ClusterName()
}

View File

@@ -56,16 +56,16 @@ func (i *InfraEnv) Generate(dependencies asset.Parents) error {
infraEnv := &aiv1beta1.InfraEnv{
ObjectMeta: metav1.ObjectMeta{
Name: getInfraEnvName(installConfig),
Namespace: getObjectMetaNamespace(installConfig),
Namespace: installConfig.ClusterNamespace(),
},
Spec: aiv1beta1.InfraEnvSpec{
ClusterRef: &aiv1beta1.ClusterReference{
Name: getClusterDeploymentName(installConfig),
Namespace: getObjectMetaNamespace(installConfig),
Namespace: installConfig.ClusterNamespace(),
},
SSHAuthorizedKey: strings.Trim(installConfig.Config.SSHKey, "|\n\t"),
PullSecretRef: &corev1.LocalObjectReference{
Name: getPullSecretName(installConfig),
Name: getPullSecretName(installConfig.ClusterName()),
},
NMStateConfigLabelSelector: metav1.LabelSelector{
MatchLabels: getNMStateConfigLabels(installConfig),

View File

@@ -44,16 +44,16 @@ func TestInfraEnv_Generate(t *testing.T) {
expectedConfig: &aiv1beta1.InfraEnv{
ObjectMeta: metav1.ObjectMeta{
Name: getInfraEnvName(getValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
},
Spec: aiv1beta1.InfraEnvSpec{
ClusterRef: &aiv1beta1.ClusterReference{
Name: getClusterDeploymentName(getValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
},
SSHAuthorizedKey: strings.Trim(testSSHKey, "|\n\t"),
PullSecretRef: &corev1.LocalObjectReference{
Name: getPullSecretName(getValidOptionalInstallConfig()),
Name: getPullSecretName(getValidOptionalInstallConfig().ClusterName()),
},
NMStateConfigLabelSelector: metav1.LabelSelector{
MatchLabels: getNMStateConfigLabels(getValidOptionalInstallConfig()),
@@ -70,20 +70,20 @@ func TestInfraEnv_Generate(t *testing.T) {
expectedConfig: &aiv1beta1.InfraEnv{
ObjectMeta: metav1.ObjectMeta{
Name: getClusterDeploymentName(getProxyValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getProxyValidOptionalInstallConfig()),
Namespace: getProxyValidOptionalInstallConfig().ClusterNamespace(),
},
Spec: aiv1beta1.InfraEnvSpec{
Proxy: getProxy(getProxyValidOptionalInstallConfig()),
SSHAuthorizedKey: strings.Trim(testSSHKey, "|\n\t"),
PullSecretRef: &corev1.LocalObjectReference{
Name: getPullSecretName(getProxyValidOptionalInstallConfig()),
Name: getPullSecretName(getProxyValidOptionalInstallConfig().ClusterName()),
},
NMStateConfigLabelSelector: metav1.LabelSelector{
MatchLabels: getNMStateConfigLabels(getProxyValidOptionalInstallConfig()),
},
ClusterRef: &aiv1beta1.ClusterReference{
Name: getClusterDeploymentName(getProxyValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getProxyValidOptionalInstallConfig()),
Namespace: getProxyValidOptionalInstallConfig().ClusterNamespace(),
},
},
},
@@ -97,20 +97,20 @@ func TestInfraEnv_Generate(t *testing.T) {
expectedConfig: &aiv1beta1.InfraEnv{
ObjectMeta: metav1.ObjectMeta{
Name: getClusterDeploymentName(getProxyValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getProxyValidOptionalInstallConfig()),
Namespace: getProxyValidOptionalInstallConfig().ClusterNamespace(),
},
Spec: aiv1beta1.InfraEnvSpec{
Proxy: getProxy(getProxyValidOptionalInstallConfig()),
SSHAuthorizedKey: strings.Trim(testSSHKey, "|\n\t"),
PullSecretRef: &corev1.LocalObjectReference{
Name: getPullSecretName(getProxyValidOptionalInstallConfig()),
Name: getPullSecretName(getProxyValidOptionalInstallConfig().ClusterName()),
},
NMStateConfigLabelSelector: metav1.LabelSelector{
MatchLabels: getNMStateConfigLabels(getProxyValidOptionalInstallConfig()),
},
ClusterRef: &aiv1beta1.ClusterReference{
Name: getClusterDeploymentName(getProxyValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getProxyValidOptionalInstallConfig()),
Namespace: getProxyValidOptionalInstallConfig().ClusterNamespace(),
},
AdditionalNTPSources: getValidAgentConfigWithAdditionalNTPSources().Config.AdditionalNTPSources,
},
@@ -125,16 +125,16 @@ func TestInfraEnv_Generate(t *testing.T) {
expectedConfig: &aiv1beta1.InfraEnv{
ObjectMeta: metav1.ObjectMeta{
Name: getClusterDeploymentName(getProxyValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getProxyValidOptionalInstallConfig()),
Namespace: getProxyValidOptionalInstallConfig().ClusterNamespace(),
},
Spec: aiv1beta1.InfraEnvSpec{
ClusterRef: &aiv1beta1.ClusterReference{
Name: getClusterDeploymentName(getValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
},
SSHAuthorizedKey: strings.Trim(testSSHKey, "|\n\t"),
PullSecretRef: &corev1.LocalObjectReference{
Name: getPullSecretName(getValidOptionalInstallConfig()),
Name: getPullSecretName(getValidOptionalInstallConfig().ClusterName()),
},
NMStateConfigLabelSelector: metav1.LabelSelector{
MatchLabels: getNMStateConfigLabels(getValidOptionalInstallConfig()),

View File

@@ -98,7 +98,7 @@ func (n *NMStateConfig) Generate(dependencies asset.Parents) error {
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf(getNMStateConfigName(installConfig)+"-%d", i),
Namespace: getObjectMetaNamespace(installConfig),
Namespace: installConfig.ClusterNamespace(),
Labels: getNMStateConfigLabels(installConfig),
},
Spec: aiv1beta1.NMStateConfigSpec{

View File

@@ -51,7 +51,7 @@ func TestNMStateConfig_Generate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprint(getNMStateConfigName(getValidOptionalInstallConfig()), "-0"),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
Labels: getNMStateConfigLabels(getValidOptionalInstallConfig()),
},
Spec: aiv1beta1.NMStateConfigSpec{
@@ -84,7 +84,7 @@ func TestNMStateConfig_Generate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprint(getNMStateConfigName(getValidOptionalInstallConfig()), "-0"),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
Labels: getNMStateConfigLabels(getValidOptionalInstallConfig()),
},
Spec: aiv1beta1.NMStateConfigSpec{
@@ -110,7 +110,7 @@ func TestNMStateConfig_Generate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprint(getNMStateConfigName(getValidOptionalInstallConfig()), "-1"),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
Labels: getNMStateConfigLabels(getValidOptionalInstallConfig()),
},
Spec: aiv1beta1.NMStateConfigSpec{
@@ -132,7 +132,7 @@ func TestNMStateConfig_Generate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprint(getNMStateConfigName(getValidOptionalInstallConfig()), "-2"),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
Labels: getNMStateConfigLabels(getValidOptionalInstallConfig()),
},
Spec: aiv1beta1.NMStateConfigSpec{

View File

@@ -454,7 +454,7 @@ func getGoodACI() *hiveext.AgentClusterInstall {
goodACI := &hiveext.AgentClusterInstall{
ObjectMeta: metav1.ObjectMeta{
Name: getAgentClusterInstallName(getValidOptionalInstallConfig()),
Namespace: getObjectMetaNamespace(getValidOptionalInstallConfig()),
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
},
Spec: hiveext.AgentClusterInstallSpec{
ImageSetRef: &hivev1.ClusterImageSetReference{

View File

@@ -3,6 +3,7 @@ package nodejoiner
import (
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/agent/joiner"
"github.com/openshift/installer/pkg/asset/agent/manifests"
"github.com/openshift/installer/pkg/asset/agent/workflow"
"github.com/openshift/installer/pkg/asset/store"
)
@@ -22,6 +23,7 @@ func NewAddNodesCommand(directory string, kubeConfig string) error {
fetcher := store.NewAssetsFetcher(directory)
return fetcher.FetchAndPersist([]asset.WritableAsset{
&workflow.AgentWorkflowAddNodes{},
&manifests.AgentPullSecret{},
// To be completed
})
}