Skip to content

Commit

Permalink
Removes duplicated code
Browse files Browse the repository at this point in the history
Updates versions in missing actions

Signed-off-by: Vicente Zepeda Mas <[email protected]>
  • Loading branch information
chentex committed Mar 4, 2024
1 parent dca8973 commit 6e5e424
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
- name: Autobuild
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.19
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Download Dependencies
run: go mod download
- name: Install ginkgo
Expand All @@ -24,7 +24,7 @@ jobs:
run: |
ginkgo -r --randomize-all --randomize-suites --fail-on-pending --cover --trace --v --coverprofile=coverage.out ./...
- name: Upload Coverage Report to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.out
Expand Down
87 changes: 39 additions & 48 deletions ocp-metadata/ocp-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ func (meta *Metadata) GetClusterMetadata() (ClusterMetadata, error) {
if err != nil {
return metadata, nil
}
version, err := meta.getVersionInfo()
if err != nil {
return metadata, err
}
metadata.OCPVersion, metadata.OCPMajorVersion, metadata.K8SVersion = version.ocpVersion, version.ocpMajorVersion, version.k8sVersion
if meta.getNodesInfo(&metadata) != nil {
return metadata, err
}
if infra != nil {
metadata.ClusterName, metadata.Platform, metadata.Region = infra.Status.InfrastructureName, infra.Status.Platform, infra.Status.PlatformStatus.Aws.Region
metadata.ClusterType = "self-managed"
Expand All @@ -73,34 +81,33 @@ func (meta *Metadata) GetClusterMetadata() (ClusterMetadata, error) {
if err != nil {
return metadata, err
}
}
version, err := meta.getVersionInfo()
if err != nil {
return metadata, err
}
metadata.OCPVersion, metadata.OCPMajorVersion, metadata.K8SVersion = version.ocpVersion, version.ocpMajorVersion, version.k8sVersion
if meta.getNodesInfo(&metadata) != nil {
return metadata, err
}
metadata.Fips, err = meta.getFips()
if err != nil {
return metadata, err
}
metadata.Publish, err = meta.getPublish()
if err != nil {
return metadata, err
}
metadata.WorkerArch, err = meta.getComputeWorkerArch()
if err != nil {
return metadata, err
}
metadata.ControlPlaneArch, err = meta.getControlPlaneArch()
if err != nil {
return metadata, err
}
metadata.Ipsec, metadata.IpsecMode, err = meta.getIPSec()
if err != nil {
return metadata, err

// Get InstallConfig to use in multiple methods
installConfig, err := meta.getClusterConfig()
if err != nil {
return metadata, err
}

metadata.Fips, err = meta.getFips(installConfig)
if err != nil {
return metadata, err
}
metadata.Publish, err = meta.getPublish(installConfig)
if err != nil {
return metadata, err
}
metadata.WorkerArch, err = meta.getComputeWorkerArch(installConfig)
if err != nil {
return metadata, err
}
metadata.ControlPlaneArch, err = meta.getControlPlaneArch(installConfig)
if err != nil {
return metadata, err
}
metadata.Ipsec, metadata.IpsecMode, err = meta.getIPSec()
if err != nil {
return metadata, err
}
}
return metadata, err
}
Expand Down Expand Up @@ -294,33 +301,21 @@ func (meta *Metadata) getSDNInfo() (string, error) {
return networkType, err
}

func (meta *Metadata) getPublish() (string, error) {
installConfig, err := meta.getClusterConfig()
if err != nil {
return "", err
}
func (meta *Metadata) getPublish(installConfig map[string]interface{}) (string, error) {
if val, ok := installConfig["publish"]; ok {
return val.(string), nil
}
return "", nil
}

func (meta *Metadata) getFips() (bool, error) {
installConfig, err := meta.getClusterConfig()
if err != nil {
return false, err
}
func (meta *Metadata) getFips(installConfig map[string]interface{}) (bool, error) {
if val, ok := installConfig["fips"]; ok {
return val.(bool), nil
}
return false, nil
}

func (meta *Metadata) getComputeWorkerArch() (string, error) {
installConfig, err := meta.getClusterConfig()
if err != nil {
return "", err
}
func (meta *Metadata) getComputeWorkerArch(installConfig map[string]interface{}) (string, error) {
if val, ok := installConfig["compute"]; ok {
for _, val := range val.([]interface{}) {
comConfig := val.(map[string]interface{})
Expand All @@ -334,11 +329,7 @@ func (meta *Metadata) getComputeWorkerArch() (string, error) {
return "", nil
}

func (meta *Metadata) getControlPlaneArch() (string, error) {
installConfig, err := meta.getClusterConfig()
if err != nil {
return "", err
}
func (meta *Metadata) getControlPlaneArch(installConfig map[string]interface{}) (string, error) {
if val, ok := installConfig["controlPlane"]; ok {
cpConfig := val.(map[string]interface{})
if v, ok := cpConfig["architecture"].(string); ok {
Expand Down

0 comments on commit 6e5e424

Please sign in to comment.