Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage pull with Omaha Protocol #525

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 1 addition & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,8 @@ docker-push: ## Push Docker image
docker push $(IMG):$(TAG)

controller-gen: ## Find or download controller-gen
ifeq (, $(shell which controller-gen))
@{ \
set -e; \
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d); \
cd $$CONTROLLER_GEN_TMP_DIR; \
go mod init tmp; \
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION); \
rm -rf $$CONTROLLER_GEN_TMP_DIR; \
}
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

gen-crd-api-reference-docs: ## Find or download gen-crd-api-reference-docs
ifeq (, $(shell which gen-crd-api-reference-docs))
Expand Down
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ resources:
- group: source
kind: Bucket
version: v1beta1
- group: source
kind: Omaha
version: v1beta1
version: "2"
161 changes: 161 additions & 0 deletions api/v1beta1/omaha_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
Copyright 2020 The Flux 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 v1beta1

import (
"github.com/fluxcd/pkg/apis/meta"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// OmahaSpec defines the desired state of Omaha
type OmahaSpec struct {
// The Omaha server URL, a valid URL contains at least a protocol and host.
// +required
URL string `json:"url"`

// +required
AppID string `json:"appid"`

// +required
Track string `json:"track"`

// +optional
Arch string `json:"arch"`

// The interval at which to check for omaha updates.
// +required
Interval metav1.Duration `json:"interval"`

// This flag tells the controller to suspend the reconciliation of this source.
// +optional
Suspend bool `json:"suspend,omitempty"`
}

// OmahaStatus defines the observed state of Omaha
type OmahaStatus struct {
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Conditions holds the conditions for Ohama.
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`

// URL is the download link for the artifact output of the last Ohama sync.
// +optional
URL string `json:"url,omitempty"`

// TODO
AppVersion string `json:"appVersion,omitempty"`

// Artifact represents the output of the last successful Omaha sync.
// +optional
Artifact *Artifact `json:"artifact,omitempty"`

meta.ReconcileRequestStatus `json:",inline"`
}

const (
// OmahaOperationSucceedReason represents the fact that the omaha listing and
// download operations succeeded.
OmahaOperationSucceedReason string = "OmahaOperationSucceed"

// OmahaOperationFailedReason represents the fact that the omaha listing or
// download operations failed.
OmahaOperationFailedReason string = "OmahaOperationFailed"
)

// OmahaProgressing resets the conditions of the Omaha to metav1.Condition of
// type meta.ReadyCondition with status 'Unknown' and meta.ProgressingReason
// reason and message. It returns the modified Omaha.
func OmahaProgressing(omaha Omaha) Omaha {
omaha.Status.ObservedGeneration = omaha.Generation
omaha.Status.URL = ""
omaha.Status.Conditions = []metav1.Condition{}
meta.SetResourceCondition(&omaha, meta.ReadyCondition, metav1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
return omaha
}

// OmahaReady sets the given Artifact and URL on the Omaha and sets the
// meta.ReadyCondition to 'True', with the given reason and message. It returns
// the modified Omaha.
func OmahaReady(omaha Omaha, artifact *Artifact, url, reason, message string) Omaha {
omaha.Status.Artifact = artifact
omaha.Status.URL = url
meta.SetResourceCondition(&omaha, meta.ReadyCondition, metav1.ConditionTrue, reason, message)
return omaha
}

// OmahaNotReady sets the meta.ReadyCondition on the Omaha to 'False', with
// the given reason and message. It returns the modified Omaha.
func OmahaNotReady(omaha Omaha, reason, message string) Omaha {
meta.SetResourceCondition(&omaha, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
return omaha
}

// OmahaReadyMessage returns the message of the metav1.Condition of type
// meta.ReadyCondition with status 'True' if present, or an empty string.
func OmahaReadyMessage(omaha Omaha) string {
if c := apimeta.FindStatusCondition(omaha.Status.Conditions, meta.ReadyCondition); c != nil {
if c.Status == metav1.ConditionTrue {
return c.Message
}
}
return ""
}

// GetArtifact returns the latest artifact from the source if present in the
// status sub-resource.
func (in *Omaha) GetArtifact() *Artifact {
return in.Status.Artifact
}

// GetStatusConditions returns a pointer to the Status.Conditions slice
func (in *Omaha) GetStatusConditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// GetInterval returns the interval at which the source is updated.
func (in *Omaha) GetInterval() metav1.Duration {
return in.Spec.Interval
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Omaha is the Schema for the omahas API
type Omaha struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec OmahaSpec `json:"spec,omitempty"`
Status OmahaStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// OmahaList contains a list of Omaha
type OmahaList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Omaha `json:"items"`
}

func init() {
SchemeBuilder.Register(&Omaha{}, &OmahaList{})
}
104 changes: 104 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

Loading