Skip to content

Commit

Permalink
OCM-9804 | fix: describe etcd KMS key when configure
Browse files Browse the repository at this point in the history
Signed-off-by: Maggie Chen <magchen@redhat.com>

fix lint

Signed-off-by: Maggie Chen <magchen@redhat.com>
  • Loading branch information
chenz4027 committed Aug 22, 2024
1 parent 14c6f5b commit decce85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 16 additions & 2 deletions cmd/describe/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,18 @@ func run(cmd *cobra.Command, argv []string) {
if isHypershift {
str = fmt.Sprintf("%s"+
"Audit Log Forwarding: %s\n", str, getAuditLogForwardingStatus(cluster))
str = fmt.Sprintf("%s"+
"External Authentication: %s\n", str, getExternalAuthConfigStatus(cluster))
if cluster.AWS().AuditLog().RoleArn() != "" {
str = fmt.Sprintf("%s"+
"Audit Log Role ARN: %s\n", str, cluster.AWS().AuditLog().RoleArn())
}
str = fmt.Sprintf("%s"+
"External Authentication: %s\n", str, getExternalAuthConfigStatus(cluster))
str = fmt.Sprintf("%s"+
"Etcd Encryption: %s\n", str, getEtcdStatus(cluster))
if cluster.AWS().EtcdEncryption().KMSKeyARN() != "" {
str = fmt.Sprintf("%s"+
"KMS key ARN: %s\n", str, cluster.AWS().EtcdEncryption().KMSKeyARN())
}
if len(cluster.AWS().AdditionalAllowedPrincipals()) > 0 {
// Omitted the 'Allowed' due to formatting
str = fmt.Sprintf("%s"+
Expand Down Expand Up @@ -839,6 +845,14 @@ func getExternalAuthConfigStatus(cluster *cmv1.Cluster) string {
return externalAuthConfigStatus
}

func getEtcdStatus(cluster *cmv1.Cluster) string {
etcdStatus := DisabledOutput
if cluster.EtcdEncryption() {
etcdStatus = EnabledOutput
}
return etcdStatus
}

func getRolePolicyBindings(roleARN string, rolePolicyDetails map[string][]aws.PolicyDetail,
prefix string) (string, error) {
roleName, err := aws.GetResourceIdFromARN(roleARN)
Expand Down
20 changes: 17 additions & 3 deletions cmd/describe/cluster/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var (
`{"displayName":"displayname","id":"bar","kind":"Cluster","name":"foo"}`)
expectClusterWithExternalAuthConfig = []byte(
`{"displayName":"displayname","external_auth_config":{"enabled":true},"kind":"Cluster"}`)
expectClusterWithEtcd = []byte(
`{"aws":{"etcd_encryption":{"kms_key_arn":"arn:aws:kms:us-west-2:125374464689:key/` +
`41fccc11-b089-test-aeff-test"}},"displayName":"displayname","etcd_encryption":true,"kind":"Cluster"}`)
expectClusterWithAap = []byte(
`{"aws":{"additional_allowed_principals":["foobar"]},"displayName":"displayname","kind":"Cluster"}`)
expectClusterWithNameAndValueAndUpgradeInformation = []byte(
Expand All @@ -34,9 +37,10 @@ var (
now.Format("2006-01-02 15:04 MST") + `","state":"` +
state + `","version":"` +
version + `"}}`)
clusterWithNameAndID, emptyCluster, clusterWithExternalAuthConfig, clusterWithAap *cmv1.Cluster
emptyUpgradePolicy, upgradePolicyWithVersionAndNextRun *cmv1.UpgradePolicy
emptyUpgradeState, upgradePolicyWithState *cmv1.UpgradePolicyState
clusterWithNameAndID, emptyCluster, clusterWithExternalAuthConfig, clusterWithAap, clusterWithKms *cmv1.Cluster
emptyUpgradePolicy, upgradePolicyWithVersionAndNextRun *cmv1.UpgradePolicy
//nolint
emptyUpgradeState, upgradePolicyWithState *cmv1.UpgradePolicyState

berr error
)
Expand All @@ -51,6 +55,11 @@ var _ = BeforeSuite(func() {
additionalAllowedPrincipals := cmv1.NewAWS().AdditionalAllowedPrincipals("foobar")
clusterWithAap, berr = cmv1.NewCluster().AWS(additionalAllowedPrincipals).Build()
Expect(berr).NotTo(HaveOccurred())
clusterWithKms, berr = cmv1.NewCluster().EtcdEncryption(true).AWS(cmv1.NewAWS().
EtcdEncryption(cmv1.NewAwsEtcdEncryption().KMSKeyARN(
"arn:aws:kms:us-west-2:125374464689:key/41fccc11-b089-test-aeff-test"))).
Build()
Expect(berr).NotTo(HaveOccurred())
emptyUpgradePolicy, berr = cmv1.NewUpgradePolicy().Build()
Expect(berr).NotTo(HaveOccurred())
emptyUpgradeState, berr = cmv1.NewUpgradePolicyState().Build()
Expand Down Expand Up @@ -118,6 +127,11 @@ var _ = Describe("Cluster description", Ordered, func() {
func() *cmv1.Cluster { return clusterWithAap },
func() *cmv1.UpgradePolicy { return emptyUpgradePolicy },
func() *cmv1.UpgradePolicyState { return nil }, expectClusterWithAap, nil),

Entry("Prints cluster information with KMS ARN",
func() *cmv1.Cluster { return clusterWithKms },
func() *cmv1.UpgradePolicy { return emptyUpgradePolicy },
func() *cmv1.UpgradePolicyState { return nil }, expectClusterWithEtcd, nil),
)
})
})
Expand Down

0 comments on commit decce85

Please sign in to comment.