Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"os"
"time"

"github.com/openshift/cluster-version-operator/pkg/cincinnati"
"github.com/openshift/cluster-version-operator/pkg/cvo"
"github.com/openshift/cluster-version-operator/pkg/version"

"github.com/golang/glog"
"github.com/google/uuid"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -40,7 +38,6 @@ var (

func init() {
flag.StringVar(&flags.kubeconfig, "kubeconfig", "", "Kubeconfig file to access a remote cluster. Warning: For testing only, do not use in production.")
flag.StringVar(&flags.clusterID, "cluster-id", "", "UUID of the cluster that the channel operator is managing, MUST be set")
flag.BoolVar(&flags.version, "version", false, "Print the version")
flag.Parse()
}
Expand All @@ -54,14 +51,7 @@ func main() {
return
}

id, err := uuid.Parse(flags.clusterID)
if err != nil {
glog.Fatalf("Invalid clusterID %q, must be a UUID: %s", flags.clusterID, err)
} else if id.Variant() != uuid.RFC4122 {
glog.Fatalf("Invalid clusterID %q, must be an RFC4122-variant UUID: found %s", flags.clusterID, id.Variant())
} else if id.Version() != 4 {
glog.Fatalf("Invalid clusterID %q, must be a version-4 UUID: found %s", flags.clusterID, id.Version())
}
glog.Infof(version.String)

config, err := loadClientConfig(flags.kubeconfig)
if err != nil {
Expand All @@ -74,15 +64,15 @@ func main() {
RenewDeadline: renewDeadline,
RetryPeriod: retryPeriod,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: startedLeading(config, cincinnati.NewClient(id)),
OnStartedLeading: startedLeading(config),
OnStoppedLeading: stoppedLeading,
},
})
}

func startedLeading(config *rest.Config, client cincinnati.Client) func(<-chan struct{}) {
func startedLeading(config *rest.Config) func(<-chan struct{}) {
return func(stopCh <-chan struct{}) {
cvo.StartWorkers(stopCh, config, client)
cvo.StartWorkers(stopCh, config)
}
}

Expand Down
1 change: 1 addition & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ ${PROJECT_ROOT}/vendor/k8s.io/code-generator/generate-groups.sh \
github.com/openshift/cluster-version-operator/pkg/generated \
github.com/openshift/cluster-version-operator/pkg/apis \
"clusterversion.openshift.io:v1" \
$@ \
28 changes: 28 additions & 0 deletions pkg/apis/clusterversion.openshift.io/v1/cvoconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v1

import (
"fmt"

"k8s.io/apimachinery/pkg/runtime"
)

// DeepCopyObject copies the CVOConfig into an Object. This doesn't actually
// require a deep copy, but the code generator (and Go itself) isn't advanced
// enough to determine that.
func (c *CVOConfig) DeepCopyObject() runtime.Object {
out := *c
c.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
return &out
}

// DeepCopyInto copies the CVOConfig into another CVOConfig. This doesn't
// actually require a deep copy, but the code generator (and Go itself) isn't
// advanced enough to determine that.
func (c *CVOConfig) DeepCopyInto(out *CVOConfig) {
*out = *c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does explictly call deepcopy on objectmeta.

c.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
}

func (c CVOConfig) String() string {
return fmt.Sprintf("{ Upstream: %s Channel: %s ClusterID: %s }", c.Upstream, c.Channel, c.ClusterID)
}
6 changes: 0 additions & 6 deletions pkg/apis/clusterversion.openshift.io/v1/doc.go

This file was deleted.

1 change: 1 addition & 0 deletions pkg/apis/clusterversion.openshift.io/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&OperatorStatus{},
&OperatorStatusList{},
&CVOConfig{},
&CVOStatus{},
)

Expand Down
36 changes: 31 additions & 5 deletions pkg/apis/clusterversion.openshift.io/v1/types.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package v1

import (
"github.com/google/uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// OperatorStatusList is a list of OperatorStatus resources.
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type OperatorStatusList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []OperatorStatus `json:"items"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// OperatorStatus is the Custom Resource object which holds the current state
// of an operator. This object is used by operators to convey their state to
// the rest of the cluster.
// +genclient
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type OperatorStatus struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Expand Down Expand Up @@ -75,11 +76,36 @@ const (
OperatorStatusConditionTypeDegraded OperatorStatusConditionType = "Degraded"
)

// CVOConfigList is a list of CVOConfig resources.
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type CVOConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []CVOConfig `json:"items"`
}

// CVOConfig is the configuration for the ClusterVersionOperator. This is where
// parameters related to automatic updates can be set.
// +genclient
type CVOConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Upstream URL `json:"upstream"`
Channel string `json:"channel"`
ClusterID uuid.UUID `json:"clusterId"`
}

// URL is a thin wrapper around string that ensures the string is a valid URL.
type URL string

// CVOStatus contains information specific to the ClusterVersionOperator. This
// object is inserted into the Extension attribute of the generic
// OperatorStatus object.
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type CVOStatus struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/clusterversion.openshift.io/v1/url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v1

import (
"net/url"
)

// UnmarshalJSON unmarshals a URL, ensuring that it is valid.
func (u *URL) UnmarshalJSON(data []byte) error {
_, err := url.Parse(string(data))
if err != nil {
return err
}

*u = URL(string(data))

return nil
}
49 changes: 33 additions & 16 deletions pkg/apis/clusterversion.openshift.io/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/cincinnati/cincinnati.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewClient(id uuid.UUID) Client {
// then finding all of the children. These children are the available updates
// for the current version and their payloads indicate from where the actual
// update image can be downloaded.
func (c *Client) GetUpdatePayloads(upstream string, version semver.Version, channel string) ([]string, error) {
func (c Client) GetUpdatePayloads(upstream string, channel string, version semver.Version) ([]string, error) {
// Download the update graph.
req, err := http.NewRequest("GET", upstream, nil)
if err != nil {
Expand Down
Loading