Skip to content

Commit

Permalink
rebase + fixes + addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jhadvig committed Jun 15, 2020
1 parent 3038253 commit 4a95909
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 238 deletions.
5 changes: 1 addition & 4 deletions manifests/07-downloads-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,11 @@ spec:
os.mkdir(arch)
for operating_system in ['linux', 'mac', 'windows']:
os.mkdir(os.path.join(arch, operating_system))
target_path = os.path.join(arch, operating_system, 'LICENSE')
os.symlink('/usr/share/openshift/LICENSE', target_path)
for arch in ['arm64', 'ppc64le', 's390x']:
os.mkdir(arch)
for operating_system in ['linux']:
os.mkdir(os.path.join(arch, operating_system))
target_path = os.path.join(arch, operating_system, 'LICENSE')
os.symlink('/usr/share/openshift/LICENSE', target_path)
os.symlink('/usr/share/openshift/LICENSE', 'oc-license')
for arch, operating_system, path in [
('amd64', 'linux', '/usr/share/openshift/linux_amd64/oc'),
Expand Down
53 changes: 26 additions & 27 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,32 @@ const (

// consts to maintain existing names of various sub-resources
const (
ClusterOperatorName = "console"
OpenShiftConsoleName = "console"
OpenShiftConsoleNamespace = TargetNamespace
OpenShiftConsoleOperatorNamespace = "openshift-console-operator"
OpenShiftConsoleOperator = "console-operator"
OpenShiftConsoleConfigMapName = "console-config"
OpenShiftConsolePublicConfigMapName = "console-public"
ServiceCAConfigMapName = "service-ca"
DefaultIngressCertConfigMapName = "default-ingress-cert"
OpenShiftConsoleDeploymentName = OpenShiftConsoleName
OpenShiftConsoleServiceName = OpenShiftConsoleName
OpenshiftConsoleRedirectServiceName = "console-redirect"
OpenShiftConsoleRouteName = OpenShiftConsoleName
OpenshiftConsoleCustomRouteName = "console-custom"
OpenShiftConsoleDownloadsRouteName = "downloads"
OAuthClientName = OpenShiftConsoleName
OpenShiftConfigManagedNamespace = "openshift-config-managed"
OpenShiftConfigNamespace = "openshift-config"
OpenShiftMonitoringConfigMapName = "monitoring-shared-config"
OpenShiftCustomLogoConfigMapName = "custom-logo"
TrustedCAConfigMapName = "trusted-ca-bundle"
TrustedCABundleKey = "ca-bundle.crt"
TrustedCABundleMountDir = "/etc/pki/ca-trust/extracted/pem"
TrustedCABundleMountFile = "tls-ca-bundle.pem"
OCCLIDownloadsCustomResourceName = "oc-cli-downloads"
OCCLIDownloadsLicenseCustomResourceName = OCCLIDownloadsCustomResourceName + "-license"
ODOCLIDownloadsCustomResourceName = "odo-cli-downloads"
ClusterOperatorName = "console"
OpenShiftConsoleName = "console"
OpenShiftConsoleNamespace = TargetNamespace
OpenShiftConsoleOperatorNamespace = "openshift-console-operator"
OpenShiftConsoleOperator = "console-operator"
OpenShiftConsoleConfigMapName = "console-config"
OpenShiftConsolePublicConfigMapName = "console-public"
ServiceCAConfigMapName = "service-ca"
DefaultIngressCertConfigMapName = "default-ingress-cert"
OpenShiftConsoleDeploymentName = OpenShiftConsoleName
OpenShiftConsoleServiceName = OpenShiftConsoleName
OpenshiftConsoleRedirectServiceName = "console-redirect"
OpenShiftConsoleRouteName = OpenShiftConsoleName
OpenshiftConsoleCustomRouteName = "console-custom"
OpenShiftConsoleDownloadsRouteName = "downloads"
OAuthClientName = OpenShiftConsoleName
OpenShiftConfigManagedNamespace = "openshift-config-managed"
OpenShiftConfigNamespace = "openshift-config"
OpenShiftMonitoringConfigMapName = "monitoring-shared-config"
OpenShiftCustomLogoConfigMapName = "custom-logo"
TrustedCAConfigMapName = "trusted-ca-bundle"
TrustedCABundleKey = "ca-bundle.crt"
TrustedCABundleMountDir = "/etc/pki/ca-trust/extracted/pem"
TrustedCABundleMountFile = "tls-ca-bundle.pem"
OCCLIDownloadsCustomResourceName = "oc-cli-downloads"
ODOCLIDownloadsCustomResourceName = "odo-cli-downloads"

ConsoleContainerPortName = "https"
ConsoleContainerPort = 443
Expand Down
47 changes: 5 additions & 42 deletions pkg/console/controllers/clidownloads/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ func (c *CLIDownloadsSyncController) sync() error {
return statusHandler.FlushAndReturn(ocCLIDownloadsErr)
}

ocLicenseCLIDownloads := LicenseDownloads(host, api.OCCLIDownloadsLicenseCustomResourceName)
_, ocLicenseCLIDownloadsErrReason, ocLicenseCLIDownloadsErr := ApplyCLIDownloads(c.consoleCliDownloadsClient, ocLicenseCLIDownloads)
statusHandler.AddCondition(status.HandleDegraded("OCLicenceDownloadsSync", ocLicenseCLIDownloadsErrReason, ocLicenseCLIDownloadsErr))
if ocLicenseCLIDownloadsErr != nil {
return statusHandler.FlushAndReturn(ocLicenseCLIDownloadsErr)
}

_, odoCLIDownloadsErrReason, odoCLIDownloadsErr := ApplyCLIDownloads(c.consoleCliDownloadsClient, ODOConsoleCLIDownloads(), c.ctx)
statusHandler.AddCondition(status.HandleDegraded("ODODownloadsSync", odoCLIDownloadsErrReason, odoCLIDownloadsErr))
if odoCLIDownloadsErr != nil {
Expand Down Expand Up @@ -193,6 +186,11 @@ func PlatformBasedOCConsoleCLIDownloads(host, cliDownloadsName string) *v1.Conso
})
}

links = append(links, v1.CLIDownloadLink{
Href: fmt.Sprintf("%s/oc-license", baseURL),
Text: "LICENSE",
})

return &v1.ConsoleCLIDownload{
ObjectMeta: metav1.ObjectMeta{
Name: cliDownloadsName,
Expand All @@ -208,41 +206,6 @@ The oc binary offers the same capabilities as the kubectl binary, but it is furt
}
}

func LicenseDownloads(host, cliDownloadsName string) *v1.ConsoleCLIDownload {
baseURL := fmt.Sprintf("%s", util.HTTPS(host))
platforms := []struct {
label string
key string
archType string
}{
{"Linux for x86_64", "amd64/linux", "LICENSE"},
{"Linux for ARM 64", "arm64/linux", "LICENSE"},
{"Linux for IBM Power, little endian", "ppc64le/linux", "LICENSE"},
{"Linux for IBM Z", "s390x/linux", "LICENSE"},
{"Mac for x86_64", "amd64/mac", "LICENSE"},
{"Windows for x86_64", "amd64/windows", "LICENSE"},
}

links := []v1.CLIDownloadLink{}
for _, platform := range platforms {
links = append(links, v1.CLIDownloadLink{
Href: GetPlatformURL(baseURL, platform.key, platform.archType),
Text: fmt.Sprintf("Download LICENSE for %s", platform.label),
})
}

return &v1.ConsoleCLIDownload{
ObjectMeta: metav1.ObjectMeta{
Name: cliDownloadsName,
},
Spec: v1.ConsoleCLIDownloadSpec{
Description: `Apache License v2.0 for the OpenShift command line interface.`,
DisplayName: "LICENSE - license of OpenShift Command Line Interface",
Links: links,
},
}
}

func ODOConsoleCLIDownloads() *v1.ConsoleCLIDownload {
return &v1.ConsoleCLIDownload{
ObjectMeta: metav1.ObjectMeta{
Expand Down
140 changes: 3 additions & 137 deletions pkg/console/controllers/clidownloads/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,143 +135,9 @@ The oc binary offers the same capabilities as the kubectl binary, but it is furt
Href: "https://www.example.com/s390x/linux/oc.tar",
Text: "Download oc for Linux for IBM Z (unsupported)",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if diff := deep.Equal(PlatformBasedOCConsoleCLIDownloads(tt.args.host, tt.args.cliDownloadsName), tt.want); diff != nil {
t.Error(diff)
}
})
}
}

func TestGetLicenseURL(t *testing.T) {
type args struct {
baseURL string
platform string
archiveType string
}
tests := []struct {
name string
args args
want string
}{
{
name: "Test assembling linux amd64 specific URL for License",
args: args{
baseURL: "https://www.example.com/amd64",
platform: "linux",
archiveType: "LICENSE",
},
want: "https://www.example.com/amd64/linux/LICENSE",
},
{
name: "Test assembling linux arm64 specific URL for License",
args: args{
baseURL: "https://www.example.com/arm64",
platform: "linux",
archiveType: "LICENSE",
},
want: "https://www.example.com/arm64/linux/LICENSE",
},
{
name: "Test assembling linux ppc64le specific URL for License",
args: args{
baseURL: "https://www.example.com/ppc64le",
platform: "linux",
archiveType: "LICENSE",
},
want: "https://www.example.com/ppc64le/linux/LICENSE",
},
{
name: "Test assembling linux s390x specific URL for License",
args: args{
baseURL: "https://www.example.com/s390x",
platform: "linux",
archiveType: "LICENSE",
},
want: "https://www.example.com/s390x/linux/LICENSE",
},
{
name: "Test assembling mac specific URL for License",
args: args{
baseURL: "https://www.example.com/amd64",
platform: "mac",
archiveType: "LICENSE",
},
want: "https://www.example.com/amd64/mac/LICENSE",
},
{
name: "Test assembling windows 64-bit specific URL for License",
args: args{
baseURL: "https://www.example.com/amd64",
platform: "windows",
archiveType: "LICENSE",
},
want: "https://www.example.com/amd64/windows/LICENSE",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if diff := deep.Equal(GetPlatformURL(tt.args.baseURL, tt.args.platform, tt.args.archiveType), tt.want); diff != nil {
t.Error(diff)
}
})
}
}

func TestLicenseDownloads(t *testing.T) {
type args struct {
host string
arch string
cliDownloadsName string
}
tests := []struct {
name string
args args
want *v1.ConsoleCLIDownload
}{
{
name: "Test assembling platform specific URL for LICENSE",
args: args{
host: "www.example.com",
cliDownloadsName: "amd64/oc-cli-downloads",
},
want: &v1.ConsoleCLIDownload{
ObjectMeta: metav1.ObjectMeta{
Name: "amd64/oc-cli-downloads",
},
Spec: v1.ConsoleCLIDownloadSpec{
Description: `Apache License v2.0 for the OpenShift command line interface.`,
DisplayName: "LICENSE - license of OpenShift Command Line Interface",
Links: []v1.CLIDownloadLink{
{
Href: "https://www.example.com/amd64/linux/LICENSE",
Text: "Download LICENSE at Linux for x86_64",
},
{
Href: "https://www.example.com/arm64/linux/LICENSE",
Text: "Download LICENSE at Linux for ARM 64",
},
{
Href: "https://www.example.com/ppc64le/linux/LICENSE",
Text: "Download LICENSE at Linux for IBM Power, little endian",
},
{
Href: "https://www.example.com/s390x/linux/LICENSE",
Text: "Download LICENSE at Linux for IBM Z",
},
{
Href: "https://www.example.com/amd64/mac/LICENSE",
Text: "Download LICENSE at Mac for x86_64",
},
{
Href: "https://www.example.com/amd64/windows/LICENSE",
Text: "Download LICENSE at Windows for x86_64",
Href: "https://www.example.com/oc-license",
Text: "LICENSE",
},
},
},
Expand All @@ -280,7 +146,7 @@ func TestLicenseDownloads(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if diff := deep.Equal(LicenseDownloads(tt.args.host, tt.args.cliDownloadsName), tt.want); diff != nil {
if diff := deep.Equal(PlatformBasedOCConsoleCLIDownloads(tt.args.host, tt.args.cliDownloadsName), tt.want); diff != nil {
t.Error(diff)
}
})
Expand Down
28 changes: 0 additions & 28 deletions test/e2e/downloads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,3 @@ func TestDownloadsEndpoint(t *testing.T) {
t.Logf("%s %s\n", link.Text, resp.Status)
}
}

func TestDonwloadsLicense(t *testing.T) {
client, _ := setupDownloadsTestCase(t)
defer cleanupDownloadsTestCase(t, client)

route, err := client.Routes.Routes(api.OpenShiftConsoleNamespace).Get(api.OpenShiftConsoleName, v1.GetOptions{})
if err != nil {
t.Fatalf("could not get route: %s", err)
}
host := routesub.GetCanonicalHost(route)

licenseDownloads := clidownloads.LicenseDownloads(host, api.OCCLIDownloadsCustomResourceName)

for _, link := range licenseDownloads.Spec.Links {
req := getRequest(t, link.Href)
client := getInsecureClient()
resp, err := client.Do(req)

if err != nil {
t.Fatalf("http error getting %s at %s: %s", link.Text, link.Href, err)
}
if !httpOK(resp) {
t.Fatalf("http error for %s at %s: %d %s", link.Text, link.Href, resp.StatusCode, http.StatusText(resp.StatusCode))
}
resp.Body.Close()
t.Logf("%s %s\n", link.Text, resp.Status)
}
}

0 comments on commit 4a95909

Please sign in to comment.