Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Feb 7, 2024
1 parent be0e1b0 commit abf281f
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 6 deletions.
31 changes: 31 additions & 0 deletions binding/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,43 @@ func (r *Client) send(rb func() (*http.Request, error)) (response *http.Response
response.StatusCode,
request.Method,
request.URL.Path))
if response.StatusCode == http.StatusUnauthorized {
refreshed, nErr := r.refreshToken(request)
if nErr != nil {
r.Error = liberr.Wrap(nErr)
err = r.Error
return
}
if refreshed {
continue
}
}
break
}
}
return
}

// refreshToken refreshes the token.
func (r *Client) refreshToken(request *http.Request) (refreshed bool, err error) {
if r.token == "" ||
strings.HasSuffix(request.URL.Path, api.AuthRefreshRoot) ||
r.token == "" {
return
}
login := &api.Login{Refresh: r.token}
err = r.Post(api.AuthRefreshRoot, login)
if err == nil {
r.token = login.Token
refreshed = true
return
}
if errors.Is(err, &RestError{}) {
err = nil
}
return
}

// buildTransport builds transport.
func (r *Client) buildTransport() (err error) {
if r.transport != nil {
Expand Down
2 changes: 1 addition & 1 deletion controller/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/go-logr/logr"
logr2 "github.com/jortel/go-utils/logr"
api "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
api "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
"github.com/konveyor/tackle2-hub/settings"
"gorm.io/gorm"
k8serr "k8s.io/apimachinery/pkg/api/errors"
Expand Down
65 changes: 65 additions & 0 deletions k8s/api/tackle/v1alpha2/addon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2019 Red Hat Inc.
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 v1alpha2

import (
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// AddonSpec defines the desired state of Addon
type AddonSpec struct {
// Main container.
Main core.Container `json:"main"`
// Init containers.
Init []core.Container `json:"init,omitempty"`
// Support containers.
Support []core.Container `json:"support,omitempty"`
}

// AddonStatus defines the observed state of Addon
type AddonStatus struct {
// The most recent generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// Addon CR
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="READY",type=string,JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
type Addon struct {
meta.TypeMeta `json:",inline"`
meta.ObjectMeta `json:"metadata,omitempty"`
Spec AddonSpec `json:"spec,omitempty"`
Status AddonStatus `json:"status,omitempty"`
}

// AddonList CR
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type AddonList struct {
meta.TypeMeta `json:",inline"`
meta.ListMeta `json:"metadata,omitempty"`
Items []Addon `json:"items"`
}

func init() {
SchemeBuilder.Register(&Addon{}, &AddonList{})

Check failure on line 64 in k8s/api/tackle/v1alpha2/addon.go

View workflow job for this annotation

GitHub Actions / test-api

cannot use &Addon{} (value of type *Addon) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 64 in k8s/api/tackle/v1alpha2/addon.go

View workflow job for this annotation

GitHub Actions / test-api

cannot use &AddonList{} (value of type *AddonList) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 64 in k8s/api/tackle/v1alpha2/addon.go

View workflow job for this annotation

GitHub Actions / test-unit

cannot use &Addon{} (value of type *Addon) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 64 in k8s/api/tackle/v1alpha2/addon.go

View workflow job for this annotation

GitHub Actions / test-unit

cannot use &AddonList{} (value of type *AddonList) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 64 in k8s/api/tackle/v1alpha2/addon.go

View workflow job for this annotation

GitHub Actions / vet

cannot use &Addon{} (value of type *Addon) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 64 in k8s/api/tackle/v1alpha2/addon.go

View workflow job for this annotation

GitHub Actions / vet

cannot use &AddonList{} (value of type *AddonList) as type runtime.Object in argument to SchemeBuilder.Register:
}
35 changes: 35 additions & 0 deletions k8s/api/tackle/v1alpha2/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2019 Red Hat Inc.
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 v1alpha1 contains API Schema definitions for the migration v1alpha1 API group.
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=github.com/konveyor/tackle2-controller/pkg/apis/migration
// +k8s:defaulter-gen=TypeMeta
// +groupName=tackle.konveyor.io
package v1alpha2

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var SchemeGroupVersion = schema.GroupVersion{
Group: "tackle.konveyor.io",
Version: "v1alpha2",
}

var SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
46 changes: 46 additions & 0 deletions k8s/api/tackle/v1alpha2/tackle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2019 Red Hat Inc.
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 v1alpha2

import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Tackle CR
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="READY",type=string,JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="CONNECTED",type=string,JSONPath=".status.conditions[?(@.type=='ConnectionTestSucceeded')].status"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
type Tackle struct {
meta.TypeMeta `json:",inline"`
meta.ObjectMeta `json:"metadata,omitempty"`
}

// TackleList CR
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type TackleList struct {
meta.TypeMeta `json:",inline"`
meta.ListMeta `json:"metadata,omitempty"`
Items []Tackle `json:"items"`
}

func init() {
SchemeBuilder.Register(&TackleList{}, &Tackle{})

Check failure on line 45 in k8s/api/tackle/v1alpha2/tackle.go

View workflow job for this annotation

GitHub Actions / test-api

cannot use &TackleList{} (value of type *TackleList) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 45 in k8s/api/tackle/v1alpha2/tackle.go

View workflow job for this annotation

GitHub Actions / test-api

cannot use &Tackle{} (value of type *Tackle) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 45 in k8s/api/tackle/v1alpha2/tackle.go

View workflow job for this annotation

GitHub Actions / test-unit

cannot use &TackleList{} (value of type *TackleList) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 45 in k8s/api/tackle/v1alpha2/tackle.go

View workflow job for this annotation

GitHub Actions / test-unit

cannot use &Tackle{} (value of type *Tackle) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 45 in k8s/api/tackle/v1alpha2/tackle.go

View workflow job for this annotation

GitHub Actions / vet

cannot use &TackleList{} (value of type *TackleList) as type runtime.Object in argument to SchemeBuilder.Register:

Check failure on line 45 in k8s/api/tackle/v1alpha2/tackle.go

View workflow job for this annotation

GitHub Actions / vet

cannot use &Tackle{} (value of type *Tackle) as type runtime.Object in argument to SchemeBuilder.Register:
}
10 changes: 5 additions & 5 deletions task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
liberr "github.com/jortel/go-utils/error"
"github.com/jortel/go-utils/logr"
"github.com/konveyor/tackle2-hub/auth"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha2"
"github.com/konveyor/tackle2-hub/metrics"
"github.com/konveyor/tackle2-hub/model"
"github.com/konveyor/tackle2-hub/settings"
Expand Down Expand Up @@ -273,7 +273,7 @@ func (r *Task) Run(client k8s.Client) (err error) {
if err != nil {
return
}
r.Image = addon.Spec.Image
r.Image = addon.Spec.Main.Image
secret := r.secret(addon)
err = client.Create(context.TODO(), &secret)
if err != nil {
Expand Down Expand Up @@ -510,14 +510,14 @@ func (r *Task) specification(addon *crd.Addon, secret *core.Secret) (specificati
func (r *Task) container(addon *crd.Addon, secret *core.Secret) (container core.Container) {
userid := int64(0)
policy := core.PullIfNotPresent
if addon.Spec.ImagePullPolicy != "" {
policy = addon.Spec.ImagePullPolicy
if addon.Spec.Main.ImagePullPolicy != "" {
policy = addon.Spec.Main.ImagePullPolicy
}
container = core.Container{
Name: "main",
Image: r.Image,
ImagePullPolicy: policy,
Resources: addon.Spec.Resources,
Resources: addon.Spec.Main.Resources,
Env: []core.EnvVar{
{
Name: settings.EnvHubBaseURL,
Expand Down

0 comments on commit abf281f

Please sign in to comment.