forked from kubernetes/release
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We now introduce a new `kubecross` package which provides a new API for retrieving the kubecross version for the default as well as a specific branch. This API will be re-used to set the `KUBE_CROSS_VERSION_LATEST` substitution, which is being used to build the `krel` binary before building the actual release. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
- Loading branch information
1 parent
d41c865
commit b38a891
Showing
11 changed files
with
327 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package kubecross | ||
|
||
import "sigs.k8s.io/release-utils/http" | ||
|
||
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate | ||
//counterfeiter:generate . impl | ||
type impl interface { | ||
GetURLResponse(url string, trim bool) (string, error) | ||
} | ||
|
||
type defaultImpl struct{} | ||
|
||
func (*defaultImpl) GetURLResponse(url string, trim bool) (string, error) { | ||
return http.GetURLResponse(url, trim) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package kubecross | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
|
||
"k8s.io/release/pkg/git" | ||
) | ||
|
||
// KubeCross is the main structure of this package. | ||
type KubeCross struct { | ||
impl impl | ||
} | ||
|
||
// New creates a new KubeCross instance. | ||
func New() *KubeCross { | ||
return &KubeCross{&defaultImpl{}} | ||
} | ||
|
||
// Latest returns the latest available kubecross version. | ||
func (k *KubeCross) Latest() (string, error) { | ||
return k.ForBranch(git.DefaultBranch) | ||
} | ||
|
||
// ForBranch returns the kubecross version for the provided branch. | ||
func (k *KubeCross) ForBranch(branch string) (string, error) { | ||
logrus.Infof("Trying to retrieve kube-cross version for branch %s", branch) | ||
|
||
const ( | ||
baseURL = "https://raw.githubusercontent.com/kubernetes/kubernetes" | ||
versionPath = "build/build-image/cross/VERSION" | ||
) | ||
|
||
url := fmt.Sprintf("%s/%s/%s", baseURL, branch, versionPath) | ||
version, err := k.impl.GetURLResponse(url, true) | ||
if err != nil { | ||
return "", errors.Wrap(err, "get URL response") | ||
} | ||
|
||
logrus.Infof("Retrieved kube-cross version: %s", version) | ||
return version, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package kubecross | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
|
||
"k8s.io/release/pkg/kubecross/kubecrossfakes" | ||
) | ||
|
||
func TestLatest(t *testing.T) { | ||
for _, tc := range []struct { | ||
prepare func(*kubecrossfakes.FakeImpl) | ||
expect func(res string, err error) | ||
}{ | ||
{ // success | ||
prepare: func(mock *kubecrossfakes.FakeImpl) { | ||
mock.GetURLResponseReturns("test", nil) | ||
}, | ||
expect: func(res string, err error) { | ||
require.Nil(t, err) | ||
require.Equal(t, "test", res) | ||
}, | ||
}, | ||
{ // failure GetURLResponse | ||
prepare: func(mock *kubecrossfakes.FakeImpl) { | ||
mock.GetURLResponseReturns("", errors.New("")) | ||
}, | ||
expect: func(res string, err error) { | ||
require.NotNil(t, err) | ||
require.Empty(t, res) | ||
}, | ||
}, | ||
} { | ||
mock := &kubecrossfakes.FakeImpl{} | ||
tc.prepare(mock) | ||
|
||
kc := New() | ||
kc.impl = mock | ||
|
||
res, err := kc.Latest() | ||
tc.expect(res, err) | ||
} | ||
} | ||
|
||
func TestForBranch(t *testing.T) { | ||
for _, tc := range []struct { | ||
prepare func(*kubecrossfakes.FakeImpl) | ||
expect func(res string, err error) | ||
}{ | ||
{ // success | ||
prepare: func(mock *kubecrossfakes.FakeImpl) { | ||
mock.GetURLResponseReturns("test", nil) | ||
}, | ||
expect: func(res string, err error) { | ||
require.Nil(t, err) | ||
require.Equal(t, "test", res) | ||
}, | ||
}, | ||
{ // failure GetURLResponse | ||
prepare: func(mock *kubecrossfakes.FakeImpl) { | ||
mock.GetURLResponseReturns("", errors.New("")) | ||
}, | ||
expect: func(res string, err error) { | ||
require.NotNil(t, err) | ||
require.Empty(t, res) | ||
}, | ||
}, | ||
} { | ||
mock := &kubecrossfakes.FakeImpl{} | ||
tc.prepare(mock) | ||
|
||
kc := New() | ||
kc.impl = mock | ||
|
||
res, err := kc.ForBranch("") | ||
tc.expect(res, err) | ||
} | ||
} |
Oops, something went wrong.