Skip to content

Commit

Permalink
Fixed upgrade_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: Omar Farag <[email protected]>
  • Loading branch information
o-farag committed Jul 28, 2023
1 parent 4da7d87 commit deddcf2
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 102 deletions.
44 changes: 1 addition & 43 deletions pkg/install/expectedArgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,12 @@ type expectedArg struct {
argument string
}

var (
expected = []expectedConfig{
{
objectName: util.HypershiftBucketSecretName,
objectType: corev1.Secret{},
objectArgs: []expectedArg{
{argument: "--oidc-storage-provider-s3-bucket-name={bucket}", shouldExist: true},
{argument: "--oidc-storage-provider-s3-region={region}", shouldExist: true},
{argument: "--oidc-storage-provider-s3-credentials=/etc/oidc-storage-provider-s3-creds/credentials", shouldExist: true},
},
NoObjectArgs: []expectedArg{
{argument: "--oidc-storage-provider-s3-bucket-name=", shouldExist: false},
{argument: "--oidc-storage-provider-s3-region=", shouldExist: false},
{argument: "--oidc-storage-provider-s3-credentials=/etc/oidc-storage-provider-s3-creds/credentials", shouldExist: false},
},
deploymentName: util.HypershiftOperatorName,
},
{
objectName: util.HypershiftPrivateLinkSecretName,
objectType: corev1.Secret{},
objectArgs: []expectedArg{
{argument: "--private-platform=AWS", shouldExist: true},
{argument: "--private-platform=None", shouldExist: false},
},
NoObjectArgs: []expectedArg{
{argument: "--private-platform=None", shouldExist: true},
{argument: "--private-platform=AWS", shouldExist: false},
},
deploymentName: util.HypershiftOperatorName,
},
{
objectName: util.HypershiftExternalDNSSecretName,
objectType: corev1.Secret{},
objectArgs: []expectedArg{
{argument: "--domain-filter={domain-filter}", shouldExist: true},
{argument: "--provider={provider}", shouldExist: true},
},
deploymentName: util.HypershiftOperatorExternalDNSName,
},
}
)

func (c *UpgradeController) getDeployment(operatorName string) (appsv1.Deployment, error) {
deployment := &appsv1.Deployment{}
nsn := types.NamespacedName{Namespace: util.HypershiftOperatorNamespace, Name: operatorName}
err := c.spokeUncachedClient.Get(c.ctx, nsn, deployment)
if err != nil {
c.log.Error(err, fmt.Sprintf("failed to get %s deployment: ", operatorName))
c.log.Info(fmt.Sprintf("failed to get %s deployment", operatorName))
return *deployment, err
}

Expand Down
17 changes: 0 additions & 17 deletions pkg/install/hypershift.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ func (c *UpgradeController) runHypershiftInstall(ctx context.Context, controller
return fmt.Errorf("hypershift-operator-oidc-provider-s3-credentials does not contain a bucket key")
}

// if err := c.createOrUpdateAwsSpokeSecret(ctx, se, true); err != nil {
// return err
// }
c.log.Info("oidc s3 bucket, region & credential arguments included")
awsArgs := []string{
"--oidc-storage-provider-s3-bucket-name", bucketName,
Expand All @@ -265,9 +262,6 @@ func (c *UpgradeController) runHypershiftInstall(ctx context.Context, controller
}

if privateLinkCreds { // if private link credentials is found, install hypershift with private secret options
// if err := c.createOrUpdateAwsSpokeSecret(ctx, spl, true); err != nil {
// return err
// }
c.log.Info("private link region & credential arguments included")
awsArgs := []string{
"--aws-private-secret", util.HypershiftPrivateLinkSecretName,
Expand All @@ -282,17 +276,6 @@ func (c *UpgradeController) runHypershiftInstall(ctx context.Context, controller
extDNSSecretKey := types.NamespacedName{Name: util.HypershiftExternalDNSSecretName, Namespace: c.clusterName}
sExtDNS := &corev1.Secret{}
if err := c.hubClient.Get(ctx, extDNSSecretKey, sExtDNS); err == nil {
// if awsPlatform {
// // For AWS DNS provider, users can specify either credentials or
// // aws-access-key-id and aws-secret-access-key
// if err := c.createOrUpdateAwsSpokeSecret(ctx, sExtDNS, false); err != nil {
// return err
// }
// } else {
// if err := c.createOrUpdateSpokeSecret(ctx, sExtDNS); err != nil {
// return err
// }
// }

c.log.Info("external dns provider & domain-filter arguments included")
awsArgs := []string{
Expand Down
53 changes: 50 additions & 3 deletions pkg/install/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *UpgradeController) Start() {
if err := c.syncHypershiftNS(); err != nil {
c.log.Error(err, "failed to sync secrets in hypershift namespace with secrets in local-cluster namespace")
}
c.populateExpectedArgs(&expected)

if c.startup || c.installfailed || c.installOptionsChanged() || c.upgradeImageCheck() {
c.reinstallNeeded = true
c.log.Info("hypershift operator re-installation is required")
Expand Down Expand Up @@ -107,9 +107,52 @@ func (c *UpgradeController) installOptionsChanged() bool {
// Create expected args based on secrets' existence and their values
// Compare the expected args to the actual args
// If they differ, reinstall
c.populateExpectedArgs(&expected)
expectedInstance := []expectedConfig{
{
objectName: util.HypershiftBucketSecretName,
objectType: corev1.Secret{},
objectArgs: []expectedArg{
{argument: "--oidc-storage-provider-s3-bucket-name={bucket}", shouldExist: true},
{argument: "--oidc-storage-provider-s3-region={region}", shouldExist: true},
{argument: "--oidc-storage-provider-s3-credentials=/etc/oidc-storage-provider-s3-creds/credentials", shouldExist: true},
},
NoObjectArgs: []expectedArg{
{argument: "--oidc-storage-provider-s3-bucket-name=", shouldExist: false},
{argument: "--oidc-storage-provider-s3-region=", shouldExist: false},
{argument: "--oidc-storage-provider-s3-credentials=/etc/oidc-storage-provider-s3-creds/credentials", shouldExist: false},
},
deploymentName: util.HypershiftOperatorName,
},
{
objectName: util.HypershiftPrivateLinkSecretName,
objectType: corev1.Secret{},
objectArgs: []expectedArg{
{argument: "--private-platform=AWS", shouldExist: true},
{argument: "--private-platform=None", shouldExist: false},
},
NoObjectArgs: []expectedArg{
{argument: "--private-platform=None", shouldExist: true},
{argument: "--private-platform=AWS", shouldExist: false},
},
deploymentName: util.HypershiftOperatorName,
},
{
objectName: util.HypershiftExternalDNSSecretName,
objectType: corev1.Secret{},
objectArgs: []expectedArg{
{argument: "--domain-filter={domain-filter}", shouldExist: true},
{argument: "--provider={provider}", shouldExist: true},
},
NoObjectArgs: []expectedArg{
{argument: "--domain-filter={domain-filter}", shouldExist: false},
{argument: "--provider={provider}", shouldExist: false},
},
deploymentName: util.HypershiftOperatorExternalDNSName,
},
}
c.populateExpectedArgs(&expectedInstance)

for _, o := range expected {
for _, o := range expectedInstance {
dep, err := c.getDeployment(o.deploymentName)
if err != nil {
continue
Expand All @@ -119,12 +162,16 @@ func (c *UpgradeController) installOptionsChanged() bool {

if err := c.hubClient.Get(context.TODO(), types.NamespacedName{Name: o.objectName, Namespace: c.clusterName}, &corev1.Secret{}); err == nil {
if argMismatch(o.objectArgs, deploymentArgs) {
fmt.Println(deploymentArgs)
c.log.Info(fmt.Sprintf("Mismatch between %s args and install options", o.objectName))
fmt.Println(o.objectArgs)
return true
}
} else {
if argMismatch(o.NoObjectArgs, deploymentArgs) {
fmt.Println(deploymentArgs)
c.log.Info(fmt.Sprintf("Mismatch between %s args and install options", o.objectName))
fmt.Println(o.objectArgs)
return true
}
}
Expand Down
Loading

0 comments on commit deddcf2

Please sign in to comment.