1
0
mirror of https://github.com/rancher/os.git synced 2025-08-02 07:24:28 +00:00

Add operator

This commit is contained in:
Darren Shepherd 2021-10-20 10:58:54 -07:00
parent 0e46d19194
commit 5675644d9f
60 changed files with 5387 additions and 60 deletions

View File

@ -1,35 +1,49 @@
FROM opensuse/leap:15.3 AS build
RUN zypper ref
RUN zypper in -y squashfs xorriso go1.16 upx busybox-static curl
RUN zypper in -y squashfs xorriso go1.16 upx busybox-static curl tar git gzip
RUN curl -Lo /usr/bin/luet https://github.com/mudler/luet/releases/download/0.18.1/luet-0.18.1-linux-$(go env GOARCH) && \
chmod +x /usr/bin/luet
RUN curl -Lo /usr/bin/rancherd https://github.com/rancher/rancherd/releases/download/v0.0.1-alpha9/rancherd-$(go env GOARCH) && \
chmod +x /usr/bin/rancherd
RUN curl -L https://get.helm.sh/helm-v3.7.1-linux-$(go env GOARCH).tar.gz | tar xzf - -C /usr/bin --strip-components=1
COPY go.mod go.sum /usr/src/
COPY cmd /usr/src/cmd
COPY pkg /usr/src/pkg
COPY scripts /usr/src/scripts
COPY chart /usr/src/chart
ARG IMAGE_TAG=latest
RUN TAG=${IMAGE_TAG} /usr/src/scripts/package-helm && \
cp /usr/src/dist/artifacts/rancheros-operator-*.tgz /usr/src/dist/rancheros-operator-chart.tgz
RUN cd /usr/src && \
CGO_ENABLED=0 go build -ldflags "-extldflags -static -s" -o /usr/sbin/ros-operator ./cmd/ros-operator && \
upx /usr/sbin/ros-operator
RUN cd /usr/src && \
CGO_ENABLED=0 go build -ldflags "-extldflags -static -s" -o /usr/sbin/ros-installer ./cmd/ros-installer && \
upx /usr/sbin/ros-installer
FROM scratch AS framework
COPY --from=build /usr/bin/busybox-static /usr/bin/busybox
COPY --from=build /usr/bin/rancherd /usr/bin/rancherd
COPY --from=build /usr/bin/luet /usr/bin/luet
COPY --from=build /usr/bin/helm /usr/bin/helm
COPY --from=build /usr/src/dist/rancheros-operator-chart.tgz /usr/share/rancher/os/
COPY framework/files/etc/luet/luet.yaml /etc/luet/luet.yaml
COPY --from=build /etc/ssl/certs /etc/ssl/certs
ARG CACHEBUST
ENV LUET_NOLOCK=true
RUN ["/usr/bin/busybox", "sh", "-c", "if [ -e /etc/luet/luet.yaml.$(busybox uname -m) ]; then busybox mv -f /etc/luet/luet.yaml.$(busybox uname -m) /etc/luet/luet.yaml; fi && busybox rm -f /etc/luet/luet.yaml.*"]
RUN ["luet", \
"install", "--no-spinner", "-d", "-y", \
"selinux/k3s", \
"selinux/rancher", \
"meta/cos-minimal", \
"utils/k9s", \
"utils/rancherd", \
"utils/nerdctl"]
COPY --from=build /usr/sbin/ros-installer /usr/sbin/ros-installer
COPY --from=build /usr/sbin/ros-operator /usr/sbin/ros-operator
COPY framework/files/ /
RUN ["/usr/bin/busybox", "sh", "-c", "if [ -e /etc/luet/luet.yaml.$(busybox uname -m) ]; then busybox mv -f /etc/luet/luet.yaml.$(busybox uname -m) /etc/luet/luet.yaml; fi && busybox rm -f /etc/luet/luet.yaml.*"]
RUN ["/usr/bin/busybox", "rm", "-rf", "/var", "/etc/ssl", "/usr/bin/busybox"]
# Make OS image

View File

@ -1,4 +1,4 @@
FROM opensuse/leap
FROM opensuse/leap:15.3
RUN zypper ref
ARG DAPPER_HOST_ARCH

13
chart/Chart.yaml Normal file
View File

@ -0,0 +1,13 @@
apiVersion: v2
name: rancheros-operator
description: RancherOS Operator
version: 0.0.0
appVersion: 0.0.0
icon: https://charts.rancher.io/assets/logos/rancheros-operator.svg
annotations:
catalog.cattle.io/certified: rancher
catalog.cattle.io/experimental: "true"
catalog.cattle.io/namespace: cattle-rancheros-operator-system
catalog.cattle.io/release-name: rancheros-operator
catalog.cattle.io/provides-gvr: managedoses.rancheros.cattle.io/v1
catalog.cattle.io/os: linux

View File

@ -0,0 +1,7 @@
{{- define "system_default_registry" -}}
{{- if .Values.global.cattle.systemDefaultRegistry -}}
{{- printf "%s/" .Values.global.cattle.systemDefaultRegistry -}}
{{- else -}}
{{- "" -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,9 @@
kind: APIService
apiVersion: management.cattle.io/v3
metadata:
name: rancheros-operator
spec:
secretName: rancheros-operator
secretNamespace: {{ .Release.Namespace }}
pathPrefixes:
- /v1-rancheros/

View File

@ -0,0 +1,37 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: rancheros-operator
spec:
selector:
matchLabels:
app: rancheros-operator
template:
metadata:
labels:
app: rancheros-operator
spec:
containers:
- env:
{{- if .Values.proxy }}
- name: HTTP_PROXY
value: {{ .Values.proxy }}
- name: HTTPS_PROXY
value: {{ .Values.proxy }}
- name: NO_PROXY
value: {{ .Values.noProxy }}
{{- end }}
image: '{{ template "system_default_registry" . }}{{ .Values.image.repository }}:{{ .Values.image.tag }}'
name: rancheros-operator
imagePullPolicy: "{{ .Values.image.imagePullPolicy }}"
command:
- /usr/sbin/ros-operator
serviceAccountName: rancheros-operator
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}

54
chart/templates/rbac.yaml Normal file
View File

@ -0,0 +1,54 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: rancheros-operator
rules:
- apiGroups:
- rancheros.cattle.io
resources:
- '*'
verbs:
- '*'
- apiGroups:
- fleet.cattle.io
resources:
- 'bundles'
verbs:
- '*'
- apiGroups:
- management.cattle.io
resources:
- 'settings'
verbs:
- 'get'
- 'watch'
- 'list'
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
#resourceNames:
#- managedosimages.rancheros.cattle.io
verbs:
- '*'
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- 'list'
- 'get'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: rancheros-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: rancheros-operator
subjects:
- kind: ServiceAccount
name: rancheros-operator
namespace: {{.Release.Namespace}}

View File

@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: rancheros-operator

23
chart/values.yaml Normal file
View File

@ -0,0 +1,23 @@
image:
repository: rancher/os
tag: dev
imagePullPolicy: IfNotPresent
# http[s] proxy server
# proxy: http://<username>@<password>:<url>:<port>
# comma separated list of domains or ip addresses that will not use the proxy
noProxy: 127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local
global:
cattle:
systemDefaultRegistry: ""
nodeSelector:
kubernetes.io/os: linux
tolerations:
- key: cattle.io/os
operator: "Equal"
value: "linux"
effect: NoSchedule

30
cmd/ros-operator/main.go Normal file
View File

@ -0,0 +1,30 @@
package main
import (
"context"
"flag"
"os"
"github.com/rancher/os/pkg/operator"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
)
var (
namespace = flag.String("namespace", "cattle-rancheros-operator-system", "Namespace of the pod")
)
func main() {
flag.Parse()
logrus.Info("Starting controller")
ctx := signals.SetupSignalHandler(context.Background())
if os.Getenv("NAMESPACE") != "" {
*namespace = os.Getenv("NAMESPACE")
}
if err := operator.Run(ctx, *namespace); err != nil {
logrus.Fatalf("Error starting: %s", err.Error())
}
<-ctx.Done()
}

View File

@ -0,0 +1 @@
/usr/lib/systemd/system/ros-populate-node-labels.service

View File

@ -0,0 +1,13 @@
[Unit]
Description=RancherOS Populated Node Labels
Documentation=https://github.com/rancher/os
Before=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Type=oneshot
EnvironmentFile=-/etc/default/%N
EnvironmentFile=-/etc/sysconfig/%N
ExecStart=ros-populate-node-labels

View File

@ -0,0 +1,36 @@
#!/bin/bash
set -x -e
source /usr/lib/rancheros-release
manifest() {
cat << EOF
kind: ManagedOSImage
apiVersion: rancheros.cattle.io/v1
metadata:
name: default-os-image
namespace: fleet-local
spec:
osImage: "${IMAGE}"
clusterTargets:
- clusterName: local
EOF
}
PULL_POLICY=IfNotPresent
if [ "$IMAGE_TAG" = dev ]; then
PULL_POLICY=Always
fi
helm upgrade \
--install \
--create-namespace \
-n cattle-rancheros-operator-system \
--set image.repository=${IMAGE_REPO} \
--set image.tag=${IMAGE_TAG} \
--set image.imagePullPolicy=${PULL_POLICY} \
rancheros-operator /usr/share/rancher/os/rancheros-operator-chart.tgz
while ! manifest | kubectl apply -f -; do
sleep 15
done

View File

@ -0,0 +1,15 @@
#!/bin/bash
set -e
. /usr/lib/rancheros-release
IMAGE=$(echo "$IMAGE" | sed 's![/:]!-!g')
for i in rke2 k3s; do
mkdir -p /etc/rancher/$i/config.yaml.d
cat > /etc/rancher/$i/config.yaml.d/99-rancheros-labels.yaml << EOF
node-label+:
- rancheros.cattle.io/image=${IMAGE}
- rancheros.cattle.io/tag=${IMAGE_TAG}
- plan.upgrade.cattle.io/os-upgrader=${IMAGE}
EOF
done

View File

@ -1,12 +1,12 @@
#!/bin/bash
set -x -e
HOST_DIR="${HOST_DIR:-/host}"
RELEASE_FILE="${RELEASE_FILE:-/etc/os-release}"
RELEASE_FILE="${RELEASE_FILE:-/usr/lib/rancheros-release}"
if [ "$FORCE" != "true" ]; then
if diff $RELEASE_FILE ${HOST_DIR}${RELEASE_FILE} >/dev/null; then
echo Update to date with
cat /etc/os-release
cat ${RELEASE_FILE}
exit 0
fi
fi

View File

@ -0,0 +1,6 @@
rancherValues:
rancherImage: ibuildthecloud/rancher
rancherImageTag: dev
postInstructions:
- command: /usr/sbin/ros-operator-install
saveOutput: true

5
generate.go Normal file
View File

@ -0,0 +1,5 @@
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate /bin/rm -rf pkg/generated
//go:generate go run pkg/codegen/main.go
package os

29
go.mod
View File

@ -3,25 +3,24 @@ module github.com/rancher/os
go 1.16
require (
github.com/mattn/go-isatty v0.0.10
github.com/mattn/go-isatty v0.0.12
github.com/pin/tftp v2.1.0+incompatible // indirect
github.com/pkg/errors v0.9.1
github.com/rancher/wrangler v0.8.3
github.com/sirupsen/logrus v1.4.2
github.com/rancher/fleet/pkg/apis v0.0.0-20210927195558-4aaa778d23dd
github.com/rancher/lasso v0.0.0-20210709145333-6c6cd7fd6607
github.com/rancher/rancher/pkg/apis v0.0.0-20211013185633-a636bda2a00e
github.com/rancher/steve v0.0.0-20210922195510-7224dc21013d
github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20210929162341-5e6e996d9486
github.com/rancher/wrangler v0.8.7
github.com/sirupsen/logrus v1.7.0
github.com/tredoe/osutil v1.0.5
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
gopkg.in/pin/tftp.v2 v2.1.0
k8s.io/api v0.22.2
k8s.io/apimachinery v0.22.2
k8s.io/client-go v12.0.0+incompatible
sigs.k8s.io/controller-runtime v0.9.0-beta.0
sigs.k8s.io/yaml v1.2.0
)
replace (
k8s.io/api => github.com/rancher/kubernetes/staging/src/k8s.io/api v1.16.3-k3s.2
k8s.io/apiextensions-apiserver => github.com/rancher/kubernetes/staging/src/k8s.io/apiextensions-apiserver v1.16.3-k3s.2
k8s.io/apimachinery => github.com/rancher/kubernetes/staging/src/k8s.io/apimachinery v1.16.3-k3s.2
k8s.io/apiserver => github.com/rancher/kubernetes/staging/src/k8s.io/apiserver v1.16.3-k3s.2
k8s.io/client-go => github.com/rancher/kubernetes/staging/src/k8s.io/client-go v1.16.3-k3s.2
k8s.io/code-generator => github.com/rancher/kubernetes/staging/src/k8s.io/code-generator v1.16.3-k3s.2
k8s.io/component-base => github.com/rancher/kubernetes/staging/src/k8s.io/component-base v1.16.3-k3s.2
k8s.io/kube-aggregator => github.com/rancher/kubernetes/staging/src/k8s.io/kube-aggregator v1.16.3-k3s.2
k8s.io/metrics => github.com/rancher/kubernetes/staging/src/k8s.io/metrics v1.16.3-k3s.2
)
replace k8s.io/client-go => k8s.io/client-go v0.22.2

1058
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
// +k8s:deepcopy-gen=package
// +groupName=rancheros.cattle.io
package v1

View File

@ -0,0 +1,38 @@
package v1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type MachineInventory struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec MachineInventorySpec `json:"spec"`
Status MachineInventoryStatus `json:"status"`
}
type MachineInventorySpec struct {
ClusterName string `json:"clusterName,omitempty"`
MachineTokenSecretName string `json:"machineTokenSecretName,omitempty"`
Config MachineRuntimeConfig `json:"config,omitempty"`
}
type MachineRuntimeConfig struct {
Role string `json:"role,omitempty"`
NodeName string `json:"nodeName,omitempty"`
Address string `json:"address,omitempty"`
InternalAddress string `json:"internalAddress,omitempty"`
Taints []corev1.Taint `json:"taints,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ConfigValues map[string]string `json:"extraConfig,omitempty"`
}
type MachineInventoryStatus struct {
ClusterRegistrationTokenNamespace string `json:"clusterRegistrationTokenNamespace,omitempty"`
ClusterRegistrationTokenName string `json:"clusterRegistrationTokenName,omitempty"`
}

View File

@ -0,0 +1,36 @@
package v1
import (
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
upgradev1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ManagedOSImage struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ManagedOSImageSpec `json:"spec"`
Status ManagedOSImageStatus `json:"status"`
}
type ManagedOSImageSpec struct {
Paused bool `json:"paused,omitempty"`
OSImage string `json:"osImage,omitempty"`
NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"`
Concurrency *int64 `json:"concurrency,omitempty"`
Prepare *upgradev1.ContainerSpec `json:"prepare,omitempty"`
Cordon *bool `json:"cordon,omitempty"`
Drain *upgradev1.DrainSpec `json:"drain,omitempty"`
ClusterRolloutStrategy *fleet.RolloutStrategy `json:"clusterRolloutStrategy,omitempty"`
Targets []fleet.BundleTarget `json:"clusterTargets,omitempty"`
}
type ManagedOSImageStatus struct {
fleet.BundleStatus
}

View File

@ -0,0 +1,291 @@
// +build !ignore_autogenerated
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
upgradecattleiov1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MachineInventory) DeepCopyInto(out *MachineInventory) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
out.Status = in.Status
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineInventory.
func (in *MachineInventory) DeepCopy() *MachineInventory {
if in == nil {
return nil
}
out := new(MachineInventory)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *MachineInventory) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MachineInventoryList) DeepCopyInto(out *MachineInventoryList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]MachineInventory, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineInventoryList.
func (in *MachineInventoryList) DeepCopy() *MachineInventoryList {
if in == nil {
return nil
}
out := new(MachineInventoryList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *MachineInventoryList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MachineInventorySpec) DeepCopyInto(out *MachineInventorySpec) {
*out = *in
in.Config.DeepCopyInto(&out.Config)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineInventorySpec.
func (in *MachineInventorySpec) DeepCopy() *MachineInventorySpec {
if in == nil {
return nil
}
out := new(MachineInventorySpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MachineInventoryStatus) DeepCopyInto(out *MachineInventoryStatus) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineInventoryStatus.
func (in *MachineInventoryStatus) DeepCopy() *MachineInventoryStatus {
if in == nil {
return nil
}
out := new(MachineInventoryStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MachineRuntimeConfig) DeepCopyInto(out *MachineRuntimeConfig) {
*out = *in
if in.Taints != nil {
in, out := &in.Taints, &out.Taints
*out = make([]corev1.Taint, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Labels != nil {
in, out := &in.Labels, &out.Labels
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.ConfigValues != nil {
in, out := &in.ConfigValues, &out.ConfigValues
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineRuntimeConfig.
func (in *MachineRuntimeConfig) DeepCopy() *MachineRuntimeConfig {
if in == nil {
return nil
}
out := new(MachineRuntimeConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ManagedOSImage) DeepCopyInto(out *ManagedOSImage) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
in.Status.DeepCopyInto(&out.Status)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagedOSImage.
func (in *ManagedOSImage) DeepCopy() *ManagedOSImage {
if in == nil {
return nil
}
out := new(ManagedOSImage)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ManagedOSImage) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ManagedOSImageList) DeepCopyInto(out *ManagedOSImageList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]ManagedOSImage, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagedOSImageList.
func (in *ManagedOSImageList) DeepCopy() *ManagedOSImageList {
if in == nil {
return nil
}
out := new(ManagedOSImageList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ManagedOSImageList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ManagedOSImageSpec) DeepCopyInto(out *ManagedOSImageSpec) {
*out = *in
if in.NodeSelector != nil {
in, out := &in.NodeSelector, &out.NodeSelector
*out = new(metav1.LabelSelector)
(*in).DeepCopyInto(*out)
}
if in.Concurrency != nil {
in, out := &in.Concurrency, &out.Concurrency
*out = new(int64)
**out = **in
}
if in.Prepare != nil {
in, out := &in.Prepare, &out.Prepare
*out = new(upgradecattleiov1.ContainerSpec)
(*in).DeepCopyInto(*out)
}
if in.Cordon != nil {
in, out := &in.Cordon, &out.Cordon
*out = new(bool)
**out = **in
}
if in.Drain != nil {
in, out := &in.Drain, &out.Drain
*out = new(upgradecattleiov1.DrainSpec)
(*in).DeepCopyInto(*out)
}
if in.ClusterRolloutStrategy != nil {
in, out := &in.ClusterRolloutStrategy, &out.ClusterRolloutStrategy
*out = new(v1alpha1.RolloutStrategy)
(*in).DeepCopyInto(*out)
}
if in.Targets != nil {
in, out := &in.Targets, &out.Targets
*out = make([]v1alpha1.BundleTarget, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagedOSImageSpec.
func (in *ManagedOSImageSpec) DeepCopy() *ManagedOSImageSpec {
if in == nil {
return nil
}
out := new(ManagedOSImageSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ManagedOSImageStatus) DeepCopyInto(out *ManagedOSImageStatus) {
*out = *in
in.BundleStatus.DeepCopyInto(&out.BundleStatus)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagedOSImageStatus.
func (in *ManagedOSImageStatus) DeepCopy() *ManagedOSImageStatus {
if in == nil {
return nil
}
out := new(ManagedOSImageStatus)
in.DeepCopyInto(out)
return out
}

View File

@ -0,0 +1,59 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
// +k8s:deepcopy-gen=package
// +groupName=rancheros.cattle.io
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// MachineInventoryList is a list of MachineInventory resources
type MachineInventoryList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []MachineInventory `json:"items"`
}
func NewMachineInventory(namespace, name string, obj MachineInventory) *MachineInventory {
obj.APIVersion, obj.Kind = SchemeGroupVersion.WithKind("MachineInventory").ToAPIVersionAndKind()
obj.Name = name
obj.Namespace = namespace
return &obj
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ManagedOSImageList is a list of ManagedOSImage resources
type ManagedOSImageList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []ManagedOSImage `json:"items"`
}
func NewManagedOSImage(namespace, name string, obj ManagedOSImage) *ManagedOSImage {
obj.APIVersion, obj.Kind = SchemeGroupVersion.WithKind("ManagedOSImage").ToAPIVersionAndKind()
obj.Name = name
obj.Namespace = namespace
return &obj
}

View File

@ -0,0 +1,63 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
// +k8s:deepcopy-gen=package
// +groupName=rancheros.cattle.io
package v1
import (
rancheros "github.com/rancher/os/pkg/apis/rancheros.cattle.io"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var (
MachineInventoryResourceName = "machineinventories"
ManagedOSImageResourceName = "managedosimages"
)
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: rancheros.GroupName, Version: "v1"}
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
)
// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&MachineInventory{},
&MachineInventoryList{},
&ManagedOSImage{},
&ManagedOSImageList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

View File

@ -0,0 +1,24 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package rancheros
const (
// Package-wide consts from generator "zz_generated_register".
GroupName = "rancheros.cattle.io"
)

51
pkg/clients/clients.go Normal file
View File

@ -0,0 +1,51 @@
package clients
import (
"context"
"github.com/rancher/os/pkg/generated/controllers/fleet.cattle.io"
fleetcontrollers "github.com/rancher/os/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
"github.com/rancher/os/pkg/generated/controllers/management.cattle.io"
ranchercontrollers "github.com/rancher/os/pkg/generated/controllers/management.cattle.io/v3"
"github.com/rancher/os/pkg/generated/controllers/provisioning.cattle.io"
provcontrollers "github.com/rancher/os/pkg/generated/controllers/provisioning.cattle.io/v1"
"github.com/rancher/os/pkg/generated/controllers/rancheros.cattle.io"
oscontrollers "github.com/rancher/os/pkg/generated/controllers/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/clients"
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
const (
SystemNamespace = "cattle-system"
)
type Clients struct {
*clients.Clients
Fleet fleetcontrollers.Interface
OS oscontrollers.Interface
Rancher ranchercontrollers.Interface
Provisioning provcontrollers.Interface
}
func NewFromConfig(restConfig *rest.Config) (*Clients, error) {
c, err := clients.NewFromConfig(restConfig, nil)
if err != nil {
return nil, err
}
opts := &generic.FactoryOptions{
SharedControllerFactory: c.SharedControllerFactory,
}
return &Clients{
Clients: c,
Fleet: fleet.NewFactoryFromConfigWithOptionsOrDie(restConfig, opts).Fleet().V1alpha1(),
OS: rancheros.NewFactoryFromConfigWithOptionsOrDie(restConfig, opts).Rancheros().V1(),
Rancher: management.NewFactoryFromConfigWithOptionsOrDie(restConfig, opts).Management().V3(),
Provisioning: provisioning.NewFactoryFromConfigWithOptionsOrDie(restConfig, opts).Provisioning().V1(),
}, nil
}
func (c *Clients) Start(ctx context.Context) error {
return c.SharedControllerFactory.Start(ctx, 5)
}

View File

@ -0,0 +1,17 @@
package main
import (
"os"
"github.com/rancher/wrangler/pkg/cleanup"
"github.com/sirupsen/logrus"
)
func main() {
if err := cleanup.Cleanup("./pkg/apis"); err != nil {
logrus.Fatal(err)
}
if err := os.RemoveAll("./pkg/generated"); err != nil {
logrus.Fatal(err)
}
}

43
pkg/codegen/main.go Normal file
View File

@ -0,0 +1,43 @@
package main
import (
"os"
"github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
provv1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1"
controllergen "github.com/rancher/wrangler/pkg/controller-gen"
"github.com/rancher/wrangler/pkg/controller-gen/args"
)
func main() {
os.Unsetenv("GOPATH")
controllergen.Run(args.Options{
OutputPackage: "github.com/rancher/os/pkg/generated",
Boilerplate: "scripts/boilerplate.go.txt",
Groups: map[string]args.Group{
"provisioning.cattle.io": {
Types: []interface{}{
provv1.Cluster{},
},
},
"management.cattle.io": {
Types: []interface{}{
v3.Setting{},
v3.ClusterRegistrationToken{},
},
},
"fleet.cattle.io": {
Types: []interface{}{
v1alpha1.Bundle{},
},
},
"rancheros.cattle.io": {
Types: []interface{}{
"./pkg/apis/rancheros.cattle.io/v1",
},
GenerateTypes: true,
},
},
})
}

View File

@ -15,7 +15,7 @@ type Install struct {
NoFormat bool `json:"noFormat,omitempty"`
Debug bool `json:"debug,omitempty"`
TTY string `json:"tty,omitempty"`
Password string `json:"password,omitempty"`
Password string `json:"password,omitempy"`
}
type Config struct {

View File

@ -0,0 +1,80 @@
package inventory
import (
"context"
"fmt"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/os/pkg/clients"
ranchercontrollers "github.com/rancher/os/pkg/generated/controllers/management.cattle.io/v3"
provcontrollers "github.com/rancher/os/pkg/generated/controllers/provisioning.cattle.io/v1"
v12 "github.com/rancher/os/pkg/generated/controllers/rancheros.cattle.io/v1"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/rancher/wrangler/pkg/name"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type handler struct {
clusterCache provcontrollers.ClusterCache
clusterRegistrationTokenCache ranchercontrollers.ClusterRegistrationTokenCache
clusterRegistrationTokenClient ranchercontrollers.ClusterRegistrationTokenClient
}
func Register(ctx context.Context, clients *clients.Clients) {
h := &handler{
clusterCache: clients.Provisioning.Cluster().Cache(),
clusterRegistrationTokenCache: clients.Rancher.ClusterRegistrationToken().Cache(),
clusterRegistrationTokenClient: clients.Rancher.ClusterRegistrationToken(),
}
clients.OS.MachineInventory().OnRemove(ctx, "machine-inventory-remove", h.OnMachineInventoryRemove)
v12.RegisterMachineInventoryStatusHandler(ctx, clients.OS.MachineInventory(), "", "machine-inventory", h.OnMachineInventory)
}
func (h *handler) OnMachineInventoryRemove(key string, machine *v1.MachineInventory) (*v1.MachineInventory, error) {
if machine.Status.ClusterRegistrationTokenName != "" && machine.Status.ClusterRegistrationTokenNamespace != "" {
err := h.clusterRegistrationTokenClient.Delete(machine.Status.ClusterRegistrationTokenNamespace, machine.Status.ClusterRegistrationTokenName, nil)
if !apierrors.IsNotFound(err) && err != nil {
return nil, err
}
}
return machine, nil
}
func (h *handler) OnMachineInventory(machine *v1.MachineInventory, status v1.MachineInventoryStatus) (v1.MachineInventoryStatus, error) {
if machine == nil {
return status, nil
}
cluster, err := h.clusterCache.Get(machine.Namespace, machine.Spec.ClusterName)
if err != nil {
return status, err
}
if cluster.Status.ClusterName == "" {
return status, fmt.Errorf("waiting for mgmt cluster to be created for prov cluster %s/%s", machine.Namespace, machine.Spec.ClusterName)
}
crtName := name.SafeConcatName(cluster.Status.ClusterName, machine.Name, "-token")
_, err = h.clusterRegistrationTokenCache.Get(cluster.Status.ClusterName, crtName)
if apierrors.IsNotFound(err) {
_, err = h.clusterRegistrationTokenClient.Create(&v3.ClusterRegistrationToken{
ObjectMeta: metav1.ObjectMeta{
Name: crtName,
Namespace: cluster.Status.ClusterName,
},
Spec: v3.ClusterRegistrationTokenSpec{
ClusterName: cluster.Status.ClusterName,
},
})
}
if err != nil {
return status, err
}
status.ClusterRegistrationTokenName = crtName
status.ClusterRegistrationTokenNamespace = cluster.Status.ClusterName
return status, nil
}

View File

@ -0,0 +1,104 @@
package managedos
import (
"context"
"github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
provv1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/os/pkg/clients"
fleetcontrollers "github.com/rancher/os/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
ranchercontrollers "github.com/rancher/os/pkg/generated/controllers/management.cattle.io/v3"
oscontrollers "github.com/rancher/os/pkg/generated/controllers/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/name"
"github.com/rancher/wrangler/pkg/relatedresource"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
func Register(ctx context.Context, clients *clients.Clients) {
h := &handler{
bundleCache: clients.Fleet.Bundle().Cache(),
settingsCache: clients.Rancher.Setting().Cache(),
}
relatedresource.Watch(ctx,
"mcc-from-bundle-trigger",
relatedresource.OwnerResolver(true, provv1.SchemeGroupVersion.String(), "ManagedOSImage"),
clients.OS.ManagedOSImage(),
clients.Fleet.Bundle())
oscontrollers.RegisterManagedOSImageGeneratingHandler(ctx,
clients.OS.ManagedOSImage(),
clients.Apply.
WithSetOwnerReference(true, true).
WithCacheTypes(
clients.OS.ManagedOSImage(),
clients.Fleet.Bundle()),
"Defined",
"mos-bundle",
h.OnChange,
nil)
}
type handler struct {
bundleCache fleetcontrollers.BundleCache
settingsCache ranchercontrollers.SettingCache
}
func (h *handler) defaultRegistry() (string, error) {
setting, err := h.settingsCache.Get("system-default-registry")
if err != nil {
return "", err
}
if setting.Value == "" {
return setting.Default, nil
}
return setting.Value, nil
}
func (h *handler) OnChange(mos *provv1.ManagedOSImage, status provv1.ManagedOSImageStatus) ([]runtime.Object, provv1.ManagedOSImageStatus, error) {
if mos.Spec.OSImage == "" {
return nil, status, nil
}
prefix, err := h.defaultRegistry()
if err != nil {
return nil, status, err
}
resources, err := ToResources(objects(mos, prefix))
if err != nil {
return nil, status, err
}
bundle := &v1alpha1.Bundle{
ObjectMeta: metav1.ObjectMeta{
Name: name.SafeConcatName("mos", mos.Name),
Namespace: mos.Namespace,
},
Spec: v1alpha1.BundleSpec{
Resources: resources,
BundleDeploymentOptions: v1alpha1.BundleDeploymentOptions{},
Paused: mos.Spec.Paused,
RolloutStrategy: mos.Spec.ClusterRolloutStrategy,
Targets: mos.Spec.Targets,
},
}
status, err = h.updateStatus(status, bundle)
return []runtime.Object{
bundle,
}, status, err
}
func (h *handler) updateStatus(status provv1.ManagedOSImageStatus, bundle *v1alpha1.Bundle) (provv1.ManagedOSImageStatus, error) {
bundle, err := h.bundleCache.Get(bundle.Namespace, bundle.Name)
if apierrors.IsNotFound(err) {
return status, nil
} else if err != nil {
return status, err
}
status.BundleStatus = bundle.Status
return status, nil
}

View File

@ -0,0 +1,46 @@
package managedos
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/wrangler/pkg/gvk"
"github.com/rancher/wrangler/pkg/name"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
)
func ToResources(objs []runtime.Object) (result []v1alpha1.BundleResource, err error) {
for _, obj := range objs {
obj = obj.DeepCopyObject()
if err := gvk.Set(obj); err != nil {
return nil, fmt.Errorf("failed to set gvk: %w", err)
}
typeMeta, err := meta.TypeAccessor(obj)
if err != nil {
return nil, err
}
meta, err := meta.Accessor(obj)
if err != nil {
return nil, err
}
data, err := json.Marshal(obj)
if err != nil {
return nil, err
}
digest := sha256.Sum256(data)
filename := name.SafeConcatName(typeMeta.GetKind(), meta.GetNamespace(), meta.GetName(), hex.EncodeToString(digest[:])[:12]) + ".yaml"
result = append(result, v1alpha1.BundleResource{
Name: filename,
Content: string(data),
})
}
return
}

View File

@ -0,0 +1,105 @@
package managedos
import (
"strings"
osv1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/os/pkg/clients"
upgradev1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
func objects(mos *osv1.ManagedOSImage, prefix string) []runtime.Object {
concurrency := int64(1)
if mos.Spec.Concurrency != nil {
concurrency = *mos.Spec.Concurrency
}
cordon := true
if mos.Spec.Cordon != nil {
cordon = *mos.Spec.Cordon
}
image := strings.SplitN(mos.Spec.OSImage, ":", 2)
version := "latest"
if len(image) == 2 {
version = image[1]
}
selector := mos.Spec.NodeSelector
if selector == nil {
selector = &metav1.LabelSelector{}
}
return []runtime.Object{
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: "os-upgrader",
},
Rules: []rbacv1.PolicyRule{{
Verbs: []string{"update", "get", "list", "watch", "patch"},
APIGroups: []string{""},
Resources: []string{"nodes"},
}},
},
&rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "os-upgrader",
},
Subjects: []rbacv1.Subject{{
Kind: "ServiceAccount",
Name: "os-upgrader",
Namespace: clients.SystemNamespace,
}},
RoleRef: rbacv1.RoleRef{
APIGroup: rbacv1.GroupName,
Kind: "ClusterRole",
Name: "os-upgrader",
},
},
&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "os-upgrader",
Namespace: clients.SystemNamespace,
},
},
&upgradev1.Plan{
TypeMeta: metav1.TypeMeta{
Kind: "Plan",
APIVersion: "upgrade.cattle.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "os-upgrader",
Namespace: clients.SystemNamespace,
},
Spec: upgradev1.PlanSpec{
Concurrency: concurrency,
Version: version,
Tolerations: []corev1.Toleration{{
Operator: corev1.TolerationOpExists,
}},
ServiceAccountName: "os-upgrader",
NodeSelector: selector,
Cordon: cordon,
Drain: mos.Spec.Drain,
Prepare: mos.Spec.Prepare,
Upgrade: &upgradev1.ContainerSpec{
Image: PrefixPrivateRegistry(image[0], prefix),
Command: []string{
"/usr/sbin/suc-upgrade",
},
},
},
},
}
}
func PrefixPrivateRegistry(image, prefix string) string {
if prefix == "" {
return image
}
return prefix + "/" + image
}

View File

@ -0,0 +1,67 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package fleet
import (
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) Fleet() Interface {
return New(c.ControllerFactory())
}

View File

@ -0,0 +1,43 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package fleet
import (
"github.com/rancher/lasso/pkg/controller"
v1alpha1 "github.com/rancher/os/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
)
type Interface interface {
V1alpha1() v1alpha1.Interface
}
type group struct {
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerFactory: controllerFactory,
}
}
func (g *group) V1alpha1() v1alpha1.Interface {
return v1alpha1.New(g.controllerFactory)
}

View File

@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v1alpha1
import (
"context"
"time"
v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type BundleHandler func(string, *v1alpha1.Bundle) (*v1alpha1.Bundle, error)
type BundleController interface {
generic.ControllerMeta
BundleClient
OnChange(ctx context.Context, name string, sync BundleHandler)
OnRemove(ctx context.Context, name string, sync BundleHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() BundleCache
}
type BundleClient interface {
Create(*v1alpha1.Bundle) (*v1alpha1.Bundle, error)
Update(*v1alpha1.Bundle) (*v1alpha1.Bundle, error)
UpdateStatus(*v1alpha1.Bundle) (*v1alpha1.Bundle, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1alpha1.Bundle, error)
List(namespace string, opts metav1.ListOptions) (*v1alpha1.BundleList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Bundle, err error)
}
type BundleCache interface {
Get(namespace, name string) (*v1alpha1.Bundle, error)
List(namespace string, selector labels.Selector) ([]*v1alpha1.Bundle, error)
AddIndexer(indexName string, indexer BundleIndexer)
GetByIndex(indexName, key string) ([]*v1alpha1.Bundle, error)
}
type BundleIndexer func(obj *v1alpha1.Bundle) ([]string, error)
type bundleController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewBundleController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) BundleController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &bundleController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromBundleHandlerToHandler(sync BundleHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1alpha1.Bundle
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1alpha1.Bundle))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *bundleController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1alpha1.Bundle))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateBundleDeepCopyOnChange(client BundleClient, obj *v1alpha1.Bundle, handler func(obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error)) (*v1alpha1.Bundle, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *bundleController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *bundleController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *bundleController) OnChange(ctx context.Context, name string, sync BundleHandler) {
c.AddGenericHandler(ctx, name, FromBundleHandlerToHandler(sync))
}
func (c *bundleController) OnRemove(ctx context.Context, name string, sync BundleHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromBundleHandlerToHandler(sync)))
}
func (c *bundleController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *bundleController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *bundleController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *bundleController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *bundleController) Cache() BundleCache {
return &bundleCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *bundleController) Create(obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *bundleController) Update(obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *bundleController) UpdateStatus(obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *bundleController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *bundleController) Get(namespace, name string, options metav1.GetOptions) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *bundleController) List(namespace string, opts metav1.ListOptions) (*v1alpha1.BundleList, error) {
result := &v1alpha1.BundleList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *bundleController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *bundleController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1alpha1.Bundle, error) {
result := &v1alpha1.Bundle{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type bundleCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *bundleCache) Get(namespace, name string) (*v1alpha1.Bundle, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v1alpha1.Bundle), nil
}
func (c *bundleCache) List(namespace string, selector labels.Selector) (ret []*v1alpha1.Bundle, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Bundle))
})
return ret, err
}
func (c *bundleCache) AddIndexer(indexName string, indexer BundleIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1alpha1.Bundle))
},
}))
}
func (c *bundleCache) GetByIndex(indexName, key string) (result []*v1alpha1.Bundle, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1alpha1.Bundle, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1alpha1.Bundle))
}
return result, nil
}
type BundleStatusHandler func(obj *v1alpha1.Bundle, status v1alpha1.BundleStatus) (v1alpha1.BundleStatus, error)
type BundleGeneratingHandler func(obj *v1alpha1.Bundle, status v1alpha1.BundleStatus) ([]runtime.Object, v1alpha1.BundleStatus, error)
func RegisterBundleStatusHandler(ctx context.Context, controller BundleController, condition condition.Cond, name string, handler BundleStatusHandler) {
statusHandler := &bundleStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromBundleHandlerToHandler(statusHandler.sync))
}
func RegisterBundleGeneratingHandler(ctx context.Context, controller BundleController, apply apply.Apply,
condition condition.Cond, name string, handler BundleGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &bundleGeneratingHandler{
BundleGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterBundleStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type bundleStatusHandler struct {
client BundleClient
condition condition.Cond
handler BundleStatusHandler
}
func (a *bundleStatusHandler) sync(key string, obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type bundleGeneratingHandler struct {
BundleGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *bundleGeneratingHandler) Remove(key string, obj *v1alpha1.Bundle) (*v1alpha1.Bundle, error) {
if obj != nil {
return obj, nil
}
obj = &v1alpha1.Bundle{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *bundleGeneratingHandler) Handle(obj *v1alpha1.Bundle, status v1alpha1.BundleStatus) (v1alpha1.BundleStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.BundleGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

View File

@ -0,0 +1,48 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v1alpha1
import (
v1alpha1 "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1alpha1.AddToScheme)
}
type Interface interface {
Bundle() BundleController
}
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerFactory: controllerFactory,
}
}
type version struct {
controllerFactory controller.SharedControllerFactory
}
func (c *version) Bundle() BundleController {
return NewBundleController(schema.GroupVersionKind{Group: "fleet.cattle.io", Version: "v1alpha1", Kind: "Bundle"}, "bundles", true, c.controllerFactory)
}

View File

@ -0,0 +1,67 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package management
import (
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) Management() Interface {
return New(c.ControllerFactory())
}

View File

@ -0,0 +1,43 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package management
import (
"github.com/rancher/lasso/pkg/controller"
v3 "github.com/rancher/os/pkg/generated/controllers/management.cattle.io/v3"
)
type Interface interface {
V3() v3.Interface
}
type group struct {
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerFactory: controllerFactory,
}
}
func (g *group) V3() v3.Interface {
return v3.New(g.controllerFactory)
}

View File

@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v3
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type ClusterRegistrationTokenHandler func(string, *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)
type ClusterRegistrationTokenController interface {
generic.ControllerMeta
ClusterRegistrationTokenClient
OnChange(ctx context.Context, name string, sync ClusterRegistrationTokenHandler)
OnRemove(ctx context.Context, name string, sync ClusterRegistrationTokenHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() ClusterRegistrationTokenCache
}
type ClusterRegistrationTokenClient interface {
Create(*v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)
Update(*v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)
UpdateStatus(*v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v3.ClusterRegistrationToken, error)
List(namespace string, opts metav1.ListOptions) (*v3.ClusterRegistrationTokenList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v3.ClusterRegistrationToken, err error)
}
type ClusterRegistrationTokenCache interface {
Get(namespace, name string) (*v3.ClusterRegistrationToken, error)
List(namespace string, selector labels.Selector) ([]*v3.ClusterRegistrationToken, error)
AddIndexer(indexName string, indexer ClusterRegistrationTokenIndexer)
GetByIndex(indexName, key string) ([]*v3.ClusterRegistrationToken, error)
}
type ClusterRegistrationTokenIndexer func(obj *v3.ClusterRegistrationToken) ([]string, error)
type clusterRegistrationTokenController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewClusterRegistrationTokenController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ClusterRegistrationTokenController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &clusterRegistrationTokenController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromClusterRegistrationTokenHandlerToHandler(sync ClusterRegistrationTokenHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v3.ClusterRegistrationToken
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v3.ClusterRegistrationToken))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *clusterRegistrationTokenController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v3.ClusterRegistrationToken))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateClusterRegistrationTokenDeepCopyOnChange(client ClusterRegistrationTokenClient, obj *v3.ClusterRegistrationToken, handler func(obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error)) (*v3.ClusterRegistrationToken, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *clusterRegistrationTokenController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *clusterRegistrationTokenController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *clusterRegistrationTokenController) OnChange(ctx context.Context, name string, sync ClusterRegistrationTokenHandler) {
c.AddGenericHandler(ctx, name, FromClusterRegistrationTokenHandlerToHandler(sync))
}
func (c *clusterRegistrationTokenController) OnRemove(ctx context.Context, name string, sync ClusterRegistrationTokenHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromClusterRegistrationTokenHandlerToHandler(sync)))
}
func (c *clusterRegistrationTokenController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *clusterRegistrationTokenController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *clusterRegistrationTokenController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *clusterRegistrationTokenController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *clusterRegistrationTokenController) Cache() ClusterRegistrationTokenCache {
return &clusterRegistrationTokenCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *clusterRegistrationTokenController) Create(obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *clusterRegistrationTokenController) Update(obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *clusterRegistrationTokenController) UpdateStatus(obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *clusterRegistrationTokenController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *clusterRegistrationTokenController) Get(namespace, name string, options metav1.GetOptions) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *clusterRegistrationTokenController) List(namespace string, opts metav1.ListOptions) (*v3.ClusterRegistrationTokenList, error) {
result := &v3.ClusterRegistrationTokenList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *clusterRegistrationTokenController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *clusterRegistrationTokenController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v3.ClusterRegistrationToken, error) {
result := &v3.ClusterRegistrationToken{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type clusterRegistrationTokenCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *clusterRegistrationTokenCache) Get(namespace, name string) (*v3.ClusterRegistrationToken, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v3.ClusterRegistrationToken), nil
}
func (c *clusterRegistrationTokenCache) List(namespace string, selector labels.Selector) (ret []*v3.ClusterRegistrationToken, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v3.ClusterRegistrationToken))
})
return ret, err
}
func (c *clusterRegistrationTokenCache) AddIndexer(indexName string, indexer ClusterRegistrationTokenIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v3.ClusterRegistrationToken))
},
}))
}
func (c *clusterRegistrationTokenCache) GetByIndex(indexName, key string) (result []*v3.ClusterRegistrationToken, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v3.ClusterRegistrationToken, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v3.ClusterRegistrationToken))
}
return result, nil
}
type ClusterRegistrationTokenStatusHandler func(obj *v3.ClusterRegistrationToken, status v3.ClusterRegistrationTokenStatus) (v3.ClusterRegistrationTokenStatus, error)
type ClusterRegistrationTokenGeneratingHandler func(obj *v3.ClusterRegistrationToken, status v3.ClusterRegistrationTokenStatus) ([]runtime.Object, v3.ClusterRegistrationTokenStatus, error)
func RegisterClusterRegistrationTokenStatusHandler(ctx context.Context, controller ClusterRegistrationTokenController, condition condition.Cond, name string, handler ClusterRegistrationTokenStatusHandler) {
statusHandler := &clusterRegistrationTokenStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromClusterRegistrationTokenHandlerToHandler(statusHandler.sync))
}
func RegisterClusterRegistrationTokenGeneratingHandler(ctx context.Context, controller ClusterRegistrationTokenController, apply apply.Apply,
condition condition.Cond, name string, handler ClusterRegistrationTokenGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &clusterRegistrationTokenGeneratingHandler{
ClusterRegistrationTokenGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterClusterRegistrationTokenStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type clusterRegistrationTokenStatusHandler struct {
client ClusterRegistrationTokenClient
condition condition.Cond
handler ClusterRegistrationTokenStatusHandler
}
func (a *clusterRegistrationTokenStatusHandler) sync(key string, obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type clusterRegistrationTokenGeneratingHandler struct {
ClusterRegistrationTokenGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *clusterRegistrationTokenGeneratingHandler) Remove(key string, obj *v3.ClusterRegistrationToken) (*v3.ClusterRegistrationToken, error) {
if obj != nil {
return obj, nil
}
obj = &v3.ClusterRegistrationToken{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *clusterRegistrationTokenGeneratingHandler) Handle(obj *v3.ClusterRegistrationToken, status v3.ClusterRegistrationTokenStatus) (v3.ClusterRegistrationTokenStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.ClusterRegistrationTokenGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

View File

@ -0,0 +1,52 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v3
import (
"github.com/rancher/lasso/pkg/controller"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v3.AddToScheme)
}
type Interface interface {
ClusterRegistrationToken() ClusterRegistrationTokenController
Setting() SettingController
}
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerFactory: controllerFactory,
}
}
type version struct {
controllerFactory controller.SharedControllerFactory
}
func (c *version) ClusterRegistrationToken() ClusterRegistrationTokenController {
return NewClusterRegistrationTokenController(schema.GroupVersionKind{Group: "management.cattle.io", Version: "v3", Kind: "ClusterRegistrationToken"}, "clusterregistrationtokens", true, c.controllerFactory)
}
func (c *version) Setting() SettingController {
return NewSettingController(schema.GroupVersionKind{Group: "management.cattle.io", Version: "v3", Kind: "Setting"}, "settings", false, c.controllerFactory)
}

View File

@ -0,0 +1,256 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v3
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type SettingHandler func(string, *v3.Setting) (*v3.Setting, error)
type SettingController interface {
generic.ControllerMeta
SettingClient
OnChange(ctx context.Context, name string, sync SettingHandler)
OnRemove(ctx context.Context, name string, sync SettingHandler)
Enqueue(name string)
EnqueueAfter(name string, duration time.Duration)
Cache() SettingCache
}
type SettingClient interface {
Create(*v3.Setting) (*v3.Setting, error)
Update(*v3.Setting) (*v3.Setting, error)
Delete(name string, options *metav1.DeleteOptions) error
Get(name string, options metav1.GetOptions) (*v3.Setting, error)
List(opts metav1.ListOptions) (*v3.SettingList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v3.Setting, err error)
}
type SettingCache interface {
Get(name string) (*v3.Setting, error)
List(selector labels.Selector) ([]*v3.Setting, error)
AddIndexer(indexName string, indexer SettingIndexer)
GetByIndex(indexName, key string) ([]*v3.Setting, error)
}
type SettingIndexer func(obj *v3.Setting) ([]string, error)
type settingController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewSettingController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) SettingController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &settingController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromSettingHandlerToHandler(sync SettingHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v3.Setting
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v3.Setting))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *settingController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v3.Setting))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateSettingDeepCopyOnChange(client SettingClient, obj *v3.Setting, handler func(obj *v3.Setting) (*v3.Setting, error)) (*v3.Setting, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *settingController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *settingController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *settingController) OnChange(ctx context.Context, name string, sync SettingHandler) {
c.AddGenericHandler(ctx, name, FromSettingHandlerToHandler(sync))
}
func (c *settingController) OnRemove(ctx context.Context, name string, sync SettingHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromSettingHandlerToHandler(sync)))
}
func (c *settingController) Enqueue(name string) {
c.controller.Enqueue("", name)
}
func (c *settingController) EnqueueAfter(name string, duration time.Duration) {
c.controller.EnqueueAfter("", name, duration)
}
func (c *settingController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *settingController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *settingController) Cache() SettingCache {
return &settingCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *settingController) Create(obj *v3.Setting) (*v3.Setting, error) {
result := &v3.Setting{}
return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{})
}
func (c *settingController) Update(obj *v3.Setting) (*v3.Setting, error) {
result := &v3.Setting{}
return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{})
}
func (c *settingController) Delete(name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), "", name, *options)
}
func (c *settingController) Get(name string, options metav1.GetOptions) (*v3.Setting, error) {
result := &v3.Setting{}
return result, c.client.Get(context.TODO(), "", name, result, options)
}
func (c *settingController) List(opts metav1.ListOptions) (*v3.SettingList, error) {
result := &v3.SettingList{}
return result, c.client.List(context.TODO(), "", result, opts)
}
func (c *settingController) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), "", opts)
}
func (c *settingController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v3.Setting, error) {
result := &v3.Setting{}
return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type settingCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *settingCache) Get(name string) (*v3.Setting, error) {
obj, exists, err := c.indexer.GetByKey(name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v3.Setting), nil
}
func (c *settingCache) List(selector labels.Selector) (ret []*v3.Setting, err error) {
err = cache.ListAll(c.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v3.Setting))
})
return ret, err
}
func (c *settingCache) AddIndexer(indexName string, indexer SettingIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v3.Setting))
},
}))
}
func (c *settingCache) GetByIndex(indexName, key string) (result []*v3.Setting, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v3.Setting, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v3.Setting))
}
return result, nil
}

View File

@ -0,0 +1,67 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package provisioning
import (
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) Provisioning() Interface {
return New(c.ControllerFactory())
}

View File

@ -0,0 +1,43 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package provisioning
import (
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/generated/controllers/provisioning.cattle.io/v1"
)
type Interface interface {
V1() v1.Interface
}
type group struct {
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerFactory: controllerFactory,
}
}
func (g *group) V1() v1.Interface {
return v1.New(g.controllerFactory)
}

View File

@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type ClusterHandler func(string, *v1.Cluster) (*v1.Cluster, error)
type ClusterController interface {
generic.ControllerMeta
ClusterClient
OnChange(ctx context.Context, name string, sync ClusterHandler)
OnRemove(ctx context.Context, name string, sync ClusterHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() ClusterCache
}
type ClusterClient interface {
Create(*v1.Cluster) (*v1.Cluster, error)
Update(*v1.Cluster) (*v1.Cluster, error)
UpdateStatus(*v1.Cluster) (*v1.Cluster, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1.Cluster, error)
List(namespace string, opts metav1.ListOptions) (*v1.ClusterList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Cluster, err error)
}
type ClusterCache interface {
Get(namespace, name string) (*v1.Cluster, error)
List(namespace string, selector labels.Selector) ([]*v1.Cluster, error)
AddIndexer(indexName string, indexer ClusterIndexer)
GetByIndex(indexName, key string) ([]*v1.Cluster, error)
}
type ClusterIndexer func(obj *v1.Cluster) ([]string, error)
type clusterController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewClusterController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ClusterController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &clusterController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromClusterHandlerToHandler(sync ClusterHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1.Cluster
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1.Cluster))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *clusterController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1.Cluster))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateClusterDeepCopyOnChange(client ClusterClient, obj *v1.Cluster, handler func(obj *v1.Cluster) (*v1.Cluster, error)) (*v1.Cluster, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *clusterController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *clusterController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *clusterController) OnChange(ctx context.Context, name string, sync ClusterHandler) {
c.AddGenericHandler(ctx, name, FromClusterHandlerToHandler(sync))
}
func (c *clusterController) OnRemove(ctx context.Context, name string, sync ClusterHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromClusterHandlerToHandler(sync)))
}
func (c *clusterController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *clusterController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *clusterController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *clusterController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *clusterController) Cache() ClusterCache {
return &clusterCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *clusterController) Create(obj *v1.Cluster) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *clusterController) Update(obj *v1.Cluster) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *clusterController) UpdateStatus(obj *v1.Cluster) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *clusterController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *clusterController) Get(namespace, name string, options metav1.GetOptions) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *clusterController) List(namespace string, opts metav1.ListOptions) (*v1.ClusterList, error) {
result := &v1.ClusterList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *clusterController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *clusterController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Cluster, error) {
result := &v1.Cluster{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type clusterCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *clusterCache) Get(namespace, name string) (*v1.Cluster, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v1.Cluster), nil
}
func (c *clusterCache) List(namespace string, selector labels.Selector) (ret []*v1.Cluster, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.Cluster))
})
return ret, err
}
func (c *clusterCache) AddIndexer(indexName string, indexer ClusterIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1.Cluster))
},
}))
}
func (c *clusterCache) GetByIndex(indexName, key string) (result []*v1.Cluster, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1.Cluster, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Cluster))
}
return result, nil
}
type ClusterStatusHandler func(obj *v1.Cluster, status v1.ClusterStatus) (v1.ClusterStatus, error)
type ClusterGeneratingHandler func(obj *v1.Cluster, status v1.ClusterStatus) ([]runtime.Object, v1.ClusterStatus, error)
func RegisterClusterStatusHandler(ctx context.Context, controller ClusterController, condition condition.Cond, name string, handler ClusterStatusHandler) {
statusHandler := &clusterStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromClusterHandlerToHandler(statusHandler.sync))
}
func RegisterClusterGeneratingHandler(ctx context.Context, controller ClusterController, apply apply.Apply,
condition condition.Cond, name string, handler ClusterGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &clusterGeneratingHandler{
ClusterGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterClusterStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type clusterStatusHandler struct {
client ClusterClient
condition condition.Cond
handler ClusterStatusHandler
}
func (a *clusterStatusHandler) sync(key string, obj *v1.Cluster) (*v1.Cluster, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type clusterGeneratingHandler struct {
ClusterGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *clusterGeneratingHandler) Remove(key string, obj *v1.Cluster) (*v1.Cluster, error) {
if obj != nil {
return obj, nil
}
obj = &v1.Cluster{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *clusterGeneratingHandler) Handle(obj *v1.Cluster, status v1.ClusterStatus) (v1.ClusterStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.ClusterGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

View File

@ -0,0 +1,48 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1.AddToScheme)
}
type Interface interface {
Cluster() ClusterController
}
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerFactory: controllerFactory,
}
}
type version struct {
controllerFactory controller.SharedControllerFactory
}
func (c *version) Cluster() ClusterController {
return NewClusterController(schema.GroupVersionKind{Group: "provisioning.cattle.io", Version: "v1", Kind: "Cluster"}, "clusters", true, c.controllerFactory)
}

View File

@ -0,0 +1,67 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package rancheros
import (
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
type Factory struct {
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
f, err := NewFactoryFromConfig(config)
if err != nil {
panic(err)
}
return f
}
func NewFactoryFromConfig(config *rest.Config) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, nil)
}
func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) {
return NewFactoryFromConfigWithOptions(config, &FactoryOptions{
Namespace: namespace,
})
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
Factory: f,
}, err
}
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return f
}
func (c *Factory) Rancheros() Interface {
return New(c.ControllerFactory())
}

View File

@ -0,0 +1,43 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package rancheros
import (
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/generated/controllers/rancheros.cattle.io/v1"
)
type Interface interface {
V1() v1.Interface
}
type group struct {
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerFactory: controllerFactory,
}
}
func (g *group) V1() v1.Interface {
return v1.New(g.controllerFactory)
}

View File

@ -0,0 +1,52 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1.AddToScheme)
}
type Interface interface {
MachineInventory() MachineInventoryController
ManagedOSImage() ManagedOSImageController
}
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerFactory: controllerFactory,
}
}
type version struct {
controllerFactory controller.SharedControllerFactory
}
func (c *version) MachineInventory() MachineInventoryController {
return NewMachineInventoryController(schema.GroupVersionKind{Group: "rancheros.cattle.io", Version: "v1", Kind: "MachineInventory"}, "machineinventories", true, c.controllerFactory)
}
func (c *version) ManagedOSImage() ManagedOSImageController {
return NewManagedOSImageController(schema.GroupVersionKind{Group: "rancheros.cattle.io", Version: "v1", Kind: "ManagedOSImage"}, "managedosimages", true, c.controllerFactory)
}

View File

@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type MachineInventoryHandler func(string, *v1.MachineInventory) (*v1.MachineInventory, error)
type MachineInventoryController interface {
generic.ControllerMeta
MachineInventoryClient
OnChange(ctx context.Context, name string, sync MachineInventoryHandler)
OnRemove(ctx context.Context, name string, sync MachineInventoryHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() MachineInventoryCache
}
type MachineInventoryClient interface {
Create(*v1.MachineInventory) (*v1.MachineInventory, error)
Update(*v1.MachineInventory) (*v1.MachineInventory, error)
UpdateStatus(*v1.MachineInventory) (*v1.MachineInventory, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1.MachineInventory, error)
List(namespace string, opts metav1.ListOptions) (*v1.MachineInventoryList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.MachineInventory, err error)
}
type MachineInventoryCache interface {
Get(namespace, name string) (*v1.MachineInventory, error)
List(namespace string, selector labels.Selector) ([]*v1.MachineInventory, error)
AddIndexer(indexName string, indexer MachineInventoryIndexer)
GetByIndex(indexName, key string) ([]*v1.MachineInventory, error)
}
type MachineInventoryIndexer func(obj *v1.MachineInventory) ([]string, error)
type machineInventoryController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewMachineInventoryController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) MachineInventoryController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &machineInventoryController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromMachineInventoryHandlerToHandler(sync MachineInventoryHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1.MachineInventory
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1.MachineInventory))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *machineInventoryController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1.MachineInventory))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateMachineInventoryDeepCopyOnChange(client MachineInventoryClient, obj *v1.MachineInventory, handler func(obj *v1.MachineInventory) (*v1.MachineInventory, error)) (*v1.MachineInventory, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *machineInventoryController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *machineInventoryController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *machineInventoryController) OnChange(ctx context.Context, name string, sync MachineInventoryHandler) {
c.AddGenericHandler(ctx, name, FromMachineInventoryHandlerToHandler(sync))
}
func (c *machineInventoryController) OnRemove(ctx context.Context, name string, sync MachineInventoryHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromMachineInventoryHandlerToHandler(sync)))
}
func (c *machineInventoryController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *machineInventoryController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *machineInventoryController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *machineInventoryController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *machineInventoryController) Cache() MachineInventoryCache {
return &machineInventoryCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *machineInventoryController) Create(obj *v1.MachineInventory) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *machineInventoryController) Update(obj *v1.MachineInventory) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *machineInventoryController) UpdateStatus(obj *v1.MachineInventory) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *machineInventoryController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *machineInventoryController) Get(namespace, name string, options metav1.GetOptions) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *machineInventoryController) List(namespace string, opts metav1.ListOptions) (*v1.MachineInventoryList, error) {
result := &v1.MachineInventoryList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *machineInventoryController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *machineInventoryController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.MachineInventory, error) {
result := &v1.MachineInventory{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type machineInventoryCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *machineInventoryCache) Get(namespace, name string) (*v1.MachineInventory, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v1.MachineInventory), nil
}
func (c *machineInventoryCache) List(namespace string, selector labels.Selector) (ret []*v1.MachineInventory, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.MachineInventory))
})
return ret, err
}
func (c *machineInventoryCache) AddIndexer(indexName string, indexer MachineInventoryIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1.MachineInventory))
},
}))
}
func (c *machineInventoryCache) GetByIndex(indexName, key string) (result []*v1.MachineInventory, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1.MachineInventory, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.MachineInventory))
}
return result, nil
}
type MachineInventoryStatusHandler func(obj *v1.MachineInventory, status v1.MachineInventoryStatus) (v1.MachineInventoryStatus, error)
type MachineInventoryGeneratingHandler func(obj *v1.MachineInventory, status v1.MachineInventoryStatus) ([]runtime.Object, v1.MachineInventoryStatus, error)
func RegisterMachineInventoryStatusHandler(ctx context.Context, controller MachineInventoryController, condition condition.Cond, name string, handler MachineInventoryStatusHandler) {
statusHandler := &machineInventoryStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromMachineInventoryHandlerToHandler(statusHandler.sync))
}
func RegisterMachineInventoryGeneratingHandler(ctx context.Context, controller MachineInventoryController, apply apply.Apply,
condition condition.Cond, name string, handler MachineInventoryGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &machineInventoryGeneratingHandler{
MachineInventoryGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterMachineInventoryStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type machineInventoryStatusHandler struct {
client MachineInventoryClient
condition condition.Cond
handler MachineInventoryStatusHandler
}
func (a *machineInventoryStatusHandler) sync(key string, obj *v1.MachineInventory) (*v1.MachineInventory, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type machineInventoryGeneratingHandler struct {
MachineInventoryGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *machineInventoryGeneratingHandler) Remove(key string, obj *v1.MachineInventory) (*v1.MachineInventory, error) {
if obj != nil {
return obj, nil
}
obj = &v1.MachineInventory{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *machineInventoryGeneratingHandler) Handle(obj *v1.MachineInventory, status v1.MachineInventoryStatus) (v1.MachineInventoryStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.MachineInventoryGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

View File

@ -0,0 +1,376 @@
/*
Copyright 2021 Rancher Labs, 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.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"context"
"time"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type ManagedOSImageHandler func(string, *v1.ManagedOSImage) (*v1.ManagedOSImage, error)
type ManagedOSImageController interface {
generic.ControllerMeta
ManagedOSImageClient
OnChange(ctx context.Context, name string, sync ManagedOSImageHandler)
OnRemove(ctx context.Context, name string, sync ManagedOSImageHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() ManagedOSImageCache
}
type ManagedOSImageClient interface {
Create(*v1.ManagedOSImage) (*v1.ManagedOSImage, error)
Update(*v1.ManagedOSImage) (*v1.ManagedOSImage, error)
UpdateStatus(*v1.ManagedOSImage) (*v1.ManagedOSImage, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1.ManagedOSImage, error)
List(namespace string, opts metav1.ListOptions) (*v1.ManagedOSImageList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ManagedOSImage, err error)
}
type ManagedOSImageCache interface {
Get(namespace, name string) (*v1.ManagedOSImage, error)
List(namespace string, selector labels.Selector) ([]*v1.ManagedOSImage, error)
AddIndexer(indexName string, indexer ManagedOSImageIndexer)
GetByIndex(indexName, key string) ([]*v1.ManagedOSImage, error)
}
type ManagedOSImageIndexer func(obj *v1.ManagedOSImage) ([]string, error)
type managedOSImageController struct {
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewManagedOSImageController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ManagedOSImageController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &managedOSImageController{
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
func FromManagedOSImageHandlerToHandler(sync ManagedOSImageHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1.ManagedOSImage
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1.ManagedOSImage))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *managedOSImageController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1.ManagedOSImage))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateManagedOSImageDeepCopyOnChange(client ManagedOSImageClient, obj *v1.ManagedOSImage, handler func(obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error)) (*v1.ManagedOSImage, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *managedOSImageController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *managedOSImageController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *managedOSImageController) OnChange(ctx context.Context, name string, sync ManagedOSImageHandler) {
c.AddGenericHandler(ctx, name, FromManagedOSImageHandlerToHandler(sync))
}
func (c *managedOSImageController) OnRemove(ctx context.Context, name string, sync ManagedOSImageHandler) {
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromManagedOSImageHandlerToHandler(sync)))
}
func (c *managedOSImageController) Enqueue(namespace, name string) {
c.controller.Enqueue(namespace, name)
}
func (c *managedOSImageController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *managedOSImageController) Informer() cache.SharedIndexInformer {
return c.controller.Informer()
}
func (c *managedOSImageController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *managedOSImageController) Cache() ManagedOSImageCache {
return &managedOSImageCache{
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *managedOSImageController) Create(obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *managedOSImageController) Update(obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *managedOSImageController) UpdateStatus(obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *managedOSImageController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *managedOSImageController) Get(namespace, name string, options metav1.GetOptions) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *managedOSImageController) List(namespace string, opts metav1.ListOptions) (*v1.ManagedOSImageList, error) {
result := &v1.ManagedOSImageList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *managedOSImageController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *managedOSImageController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.ManagedOSImage, error) {
result := &v1.ManagedOSImage{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type managedOSImageCache struct {
indexer cache.Indexer
resource schema.GroupResource
}
func (c *managedOSImageCache) Get(namespace, name string) (*v1.ManagedOSImage, error) {
obj, exists, err := c.indexer.GetByKey(namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(c.resource, name)
}
return obj.(*v1.ManagedOSImage), nil
}
func (c *managedOSImageCache) List(namespace string, selector labels.Selector) (ret []*v1.ManagedOSImage, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.ManagedOSImage))
})
return ret, err
}
func (c *managedOSImageCache) AddIndexer(indexName string, indexer ManagedOSImageIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1.ManagedOSImage))
},
}))
}
func (c *managedOSImageCache) GetByIndex(indexName, key string) (result []*v1.ManagedOSImage, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1.ManagedOSImage, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.ManagedOSImage))
}
return result, nil
}
type ManagedOSImageStatusHandler func(obj *v1.ManagedOSImage, status v1.ManagedOSImageStatus) (v1.ManagedOSImageStatus, error)
type ManagedOSImageGeneratingHandler func(obj *v1.ManagedOSImage, status v1.ManagedOSImageStatus) ([]runtime.Object, v1.ManagedOSImageStatus, error)
func RegisterManagedOSImageStatusHandler(ctx context.Context, controller ManagedOSImageController, condition condition.Cond, name string, handler ManagedOSImageStatusHandler) {
statusHandler := &managedOSImageStatusHandler{
client: controller,
condition: condition,
handler: handler,
}
controller.AddGenericHandler(ctx, name, FromManagedOSImageHandlerToHandler(statusHandler.sync))
}
func RegisterManagedOSImageGeneratingHandler(ctx context.Context, controller ManagedOSImageController, apply apply.Apply,
condition condition.Cond, name string, handler ManagedOSImageGeneratingHandler, opts *generic.GeneratingHandlerOptions) {
statusHandler := &managedOSImageGeneratingHandler{
ManagedOSImageGeneratingHandler: handler,
apply: apply,
name: name,
gvk: controller.GroupVersionKind(),
}
if opts != nil {
statusHandler.opts = *opts
}
controller.OnChange(ctx, name, statusHandler.Remove)
RegisterManagedOSImageStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
}
type managedOSImageStatusHandler struct {
client ManagedOSImageClient
condition condition.Cond
handler ManagedOSImageStatusHandler
}
func (a *managedOSImageStatusHandler) sync(key string, obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
if obj == nil {
return obj, nil
}
origStatus := obj.Status.DeepCopy()
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *origStatus.DeepCopy()
}
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(&newStatus, "", nil)
} else {
a.condition.SetError(&newStatus, "", err)
}
}
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
if a.condition != "" {
// Since status has changed, update the lastUpdatedTime
a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339))
}
var newErr error
obj.Status = newStatus
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
type managedOSImageGeneratingHandler struct {
ManagedOSImageGeneratingHandler
apply apply.Apply
opts generic.GeneratingHandlerOptions
gvk schema.GroupVersionKind
name string
}
func (a *managedOSImageGeneratingHandler) Remove(key string, obj *v1.ManagedOSImage) (*v1.ManagedOSImage, error) {
if obj != nil {
return obj, nil
}
obj = &v1.ManagedOSImage{}
obj.Namespace, obj.Name = kv.RSplit(key, "/")
obj.SetGroupVersionKind(a.gvk)
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects()
}
func (a *managedOSImageGeneratingHandler) Handle(obj *v1.ManagedOSImage, status v1.ManagedOSImageStatus) (v1.ManagedOSImageStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.ManagedOSImageGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
}
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
WithOwner(obj).
WithSetID(a.name).
ApplyObjects(objs...)
}

52
pkg/operator/operator.go Normal file
View File

@ -0,0 +1,52 @@
package operator
import (
"context"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/os/pkg/clients"
"github.com/rancher/os/pkg/controllers/inventory"
"github.com/rancher/os/pkg/controllers/managedos"
"github.com/rancher/os/pkg/server"
"github.com/rancher/steve/pkg/aggregation"
"github.com/rancher/wrangler/pkg/crd"
"github.com/sirupsen/logrus"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
func Run(ctx context.Context, namespace string) error {
restConfig, err := config.GetConfig()
if err != nil {
logrus.Fatalf("failed to find kubeconfig: %v", err)
}
clients, err := clients.NewFromConfig(restConfig)
if err != nil {
logrus.Fatalf("Error building controller: %s", err.Error())
}
factory, err := crd.NewFactoryFromClient(restConfig)
if err != nil {
logrus.Fatalf("Failed to create CRD factory: %v", err)
}
err = factory.BatchCreateCRDs(ctx,
crd.CRD{
SchemaObject: v1.ManagedOSImage{},
Status: true,
},
crd.CRD{
SchemaObject: v1.MachineInventory{},
Status: true,
},
).BatchWait()
if err != nil {
logrus.Fatalf("Failed to create CRDs: %v", err)
}
managedos.Register(ctx, clients)
inventory.Register(ctx, clients)
aggregation.Watch(ctx, clients.Core.Secret(), namespace, "rancheros-operator", server.New(clients))
return clients.Start(ctx)
}

54
pkg/server/cacert.go Normal file
View File

@ -0,0 +1,54 @@
package server
import (
"crypto/hmac"
"crypto/sha512"
"encoding/base64"
"net/http"
"strings"
)
var (
tokenHash = "tokenByHash"
)
func (i *InventoryServer) cacerts(rw http.ResponseWriter, req *http.Request) {
ca := i.cacert()
rw.Header().Set("Content-Type", "text/plain")
var bytes []byte
if strings.TrimSpace(ca) != "" {
if !strings.HasSuffix(ca, "\n") {
ca += "\n"
}
bytes = []byte(ca)
}
nonce := req.Header.Get("X-Cattle-Nonce")
authorization := strings.TrimPrefix(req.Header.Get("Authorization"), "Bearer ")
if authorization != "" && nonce != "" {
crt, err := i.secretCache.GetByIndex(tokenHash, authorization)
if err == nil && len(crt) >= 0 {
digest := hmac.New(sha512.New, crt[0].Data[tokenKey])
digest.Write([]byte(nonce))
digest.Write([]byte{0})
digest.Write(bytes)
digest.Write([]byte{0})
hash := digest.Sum(nil)
rw.Header().Set("X-Cattle-Hash", base64.StdEncoding.EncodeToString(hash))
}
}
if len(bytes) > 0 {
_, _ = rw.Write([]byte(ca))
}
}
func (i *InventoryServer) cacert() string {
setting, err := i.settingCache.Get("cacerts")
if err != nil {
return ""
}
return setting.Value
}

153
pkg/server/server.go Normal file
View File

@ -0,0 +1,153 @@
package server
import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"strings"
v1 "github.com/rancher/os/pkg/apis/rancheros.cattle.io/v1"
"github.com/rancher/os/pkg/clients"
ranchercontrollers "github.com/rancher/os/pkg/generated/controllers/management.cattle.io/v3"
roscontrollers "github.com/rancher/os/pkg/generated/controllers/rancheros.cattle.io/v1"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
corecontrollers "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)
var (
tokenType = "rancheros.cattle.io/token"
tokenKey = "token"
tokenIndex = "tokenIndex"
machineBySecretNameIndex = "machineBySecretNameIndex"
)
type InventoryServer struct {
secretCache corecontrollers.SecretCache
settingCache ranchercontrollers.SettingCache
machineCache roscontrollers.MachineInventoryCache
clusterRegistrationToken ranchercontrollers.ClusterRegistrationTokenCache
}
func New(clients *clients.Clients) *InventoryServer {
server := &InventoryServer{
secretCache: clients.Core.Secret().Cache(),
settingCache: clients.Rancher.Setting().Cache(),
machineCache: clients.OS.MachineInventory().Cache(),
clusterRegistrationToken: clients.Rancher.ClusterRegistrationToken().Cache(),
}
server.secretCache.AddIndexer(tokenIndex, func(obj *corev1.Secret) ([]string, error) {
if string(obj.Type) != tokenType {
return nil, nil
}
t := obj.Data[tokenKey]
if len(t) == 0 {
return nil, nil
}
return []string{base64.StdEncoding.EncodeToString(t)}, nil
})
server.machineCache.AddIndexer(machineBySecretNameIndex, func(obj *v1.MachineInventory) ([]string, error) {
if obj.Spec.MachineTokenSecretName == "" {
return nil, nil
}
return []string{obj.Namespace + "/" + obj.Spec.MachineTokenSecretName}, nil
})
server.secretCache.AddIndexer(tokenHash, func(obj *corev1.Secret) ([]string, error) {
if string(obj.Type) == tokenType {
return nil, nil
}
if token := obj.Data[tokenKey]; len(token) > 0 {
hash := sha256.Sum256(token)
return []string{base64.StdEncoding.EncodeToString(hash[:])}, nil
}
return nil, nil
})
return server
}
func (i *InventoryServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
if strings.HasSuffix(req.URL.Path, "/cacerts") {
i.cacerts(resp, req)
} else {
err := i.handle(resp, req)
if err != nil {
http.Error(resp, err.Error(), http.StatusInternalServerError)
}
}
}
func (i *InventoryServer) handle(resp http.ResponseWriter, req *http.Request) error {
token := strings.TrimPrefix(req.Header.Get("Authorization"), "Bearer ")
secrets, err := i.secretCache.GetByIndex(tokenIndex, token)
if apierrors.IsNotFound(err) {
http.Error(resp, "Token not found", http.StatusNotFound)
return nil
} else if err != nil {
return err
} else if len(secrets) > 1 {
logrus.Errorf("Multiple machine secrets with the same value [%s/%s, %s/%s, ...]",
secrets[0].Namespace, secrets[0].Name, secrets[1].Namespace, secrets[1].Name)
http.Error(resp, "Token not found", http.StatusNotFound)
return nil
}
machines, err := i.machineCache.GetByIndex(machineBySecretNameIndex, secrets[0].Namespace+"/"+secrets[0].Name)
if len(machines) > 1 {
logrus.Errorf("Multiple machine inventories with the token: %v", machines)
}
if apierrors.IsNotFound(err) || len(machines) != 1 {
http.Error(resp, "Machine not found", http.StatusNotFound)
return nil
} else if err != nil {
return err
}
crt, err := i.clusterRegistrationToken.Get(machines[0].Status.ClusterRegistrationTokenNamespace,
machines[0].Status.ClusterRegistrationTokenName)
if apierrors.IsNotFound(err) || crt.Status.Token == "" {
http.Error(resp, "Cluster token not found", http.StatusNotFound)
return nil
}
return writeResponse(resp, machines[0], crt)
}
type config struct {
Role string `json:"role,omitempty"`
NodeName string `json:"nodeName,omitempty"`
Address string `json:"address,omitempty"`
InternalAddress string `json:"internalAddress,omitempty"`
Taints []string `json:"taints,omitempty"`
Labels []string `json:"labels,omitempty"`
ConfigValues map[string]string `json:"extraConfig,omitempty"`
Token string `json:"token,omitempty"`
}
func writeResponse(resp http.ResponseWriter, inventory *v1.MachineInventory, crt *v3.ClusterRegistrationToken) error {
config := config{
Role: inventory.Spec.Config.Role,
NodeName: inventory.Spec.Config.NodeName,
Address: inventory.Spec.Config.Address,
InternalAddress: inventory.Spec.Config.InternalAddress,
Taints: nil,
Labels: nil,
ConfigValues: inventory.Spec.Config.ConfigValues,
Token: crt.Status.Token,
}
for k, v := range inventory.Spec.Config.Labels {
config.Labels = append(config.Labels, fmt.Sprintf("%s=%s", k, v))
}
for _, taint := range inventory.Spec.Config.Taints {
config.Labels = append(config.Labels, taint.ToString())
}
resp.Header().Set("Content-Type", "application/json")
return json.NewEncoder(resp).Encode(config)
}

16
scripts/boilerplate.go.txt Executable file
View File

@ -0,0 +1,16 @@
/*
Copyright YEAR Rancher Labs, 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.
*/

View File

@ -43,6 +43,8 @@ if [ "${TAG}" = "dev" ]; then
PXE_ASSET_VERSION=${TAG}
fi
./scripts/package-helm
cat > build/output.ipxe << EOF
#!ipxe
set arch ${ARCH}

24
scripts/package-helm Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
set -e -x
if ! hash helm 2>/dev/null; then
exit 0
fi
cd $(dirname $0)/..
. ./scripts/version
rm -rf build/chart
mkdir -p build dist/artifacts
cp -rf chart build/
sed -i \
-e 's/version:.*/version: '${HELM_VERSION}'/' \
-e 's/appVersion:.*/appVersion: '${HELM_VERSION}'/' \
build/chart/Chart.yaml
sed -i \
-e 's/tag:.*/tag: '${HELM_TAG}'/' \
build/chart/values.yaml
helm package -d ./dist/artifacts ./build/chart

View File

@ -47,7 +47,7 @@ qemu-system-x86_64 \
-serial mon:stdio \
-rtc base=utc,clock=rt \
-chardev socket,path=qga.sock,server,nowait,id=qga0 \
-nic user,tftp=./,bootfile=/ipxe.cfg \
-nic user,tftp=./,bootfile=/ipxe.cfg,hostfwd=tcp:127.0.0.1:2222-:22 \
-device virtio-serial \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
-drive if=virtio,media=disk,file=disk.img \

View File

@ -1,12 +1,18 @@
#!/bin/bash
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
if [ -e .git ] || [ -e ../.git ]; then
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
DIRTY="-dirty"
fi
COMMIT=$(git rev-parse --short HEAD)
GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)}
else
COMMIT=HEAD
GIT_TAG=HEAD
DIRTY="-dirty"
fi
COMMIT=$(git rev-parse --short HEAD)
GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)}
if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then
VERSION=$GIT_TAG
else
@ -19,9 +25,17 @@ fi
SUFFIX="-${ARCH}"
HELM_TAG=${TAG:-${VERSION}}
HELM_VERSION=${HELM_TAG/v/}
TAG=${TAG:-${VERSION}${SUFFIX}}
REPO=${REPO:-rancher}
if echo $TAG | grep -q dirty; then
TAG=dev
HELM_TAG=dev
HELM_VERSION=0.0.0-dev
fi
if echo "$HELM_VERSION" | grep -q '^[^0-9]'; then
HELM_VERSION=0.0.0-dev
fi